// Code generated by azure-service-operator-codegen. DO NOT EDIT.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package storage

import (
	"encoding/json"
	"github.com/google/go-cmp/cmp"
	"github.com/google/go-cmp/cmp/cmpopts"
	"github.com/kr/pretty"
	"github.com/kylelemons/godebug/diff"
	"github.com/leanovate/gopter"
	"github.com/leanovate/gopter/gen"
	"github.com/leanovate/gopter/prop"
	"os"
	"reflect"
	"testing"
)

func Test_FlexibleServersBackup_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MinSuccessfulTests = 20
	parameters.MaxSize = 3
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip of FlexibleServersBackup via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForFlexibleServersBackup, FlexibleServersBackupGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

// RunJSONSerializationTestForFlexibleServersBackup runs a test to see if a specific instance of FlexibleServersBackup round trips to JSON and back losslessly
func RunJSONSerializationTestForFlexibleServersBackup(subject FlexibleServersBackup) string {
	// Serialize to JSON
	bin, err := json.Marshal(subject)
	if err != nil {
		return err.Error()
	}

	// Deserialize back into memory
	var actual FlexibleServersBackup
	err = json.Unmarshal(bin, &actual)
	if err != nil {
		return err.Error()
	}

	// Check for outcome
	match := cmp.Equal(subject, actual, cmpopts.EquateEmpty())
	if !match {
		actualFmt := pretty.Sprint(actual)
		subjectFmt := pretty.Sprint(subject)
		result := diff.Diff(subjectFmt, actualFmt)
		return result
	}

	return ""
}

// Generator of FlexibleServersBackup instances for property testing - lazily instantiated by
// FlexibleServersBackupGenerator()
var flexibleServersBackupGenerator gopter.Gen

// FlexibleServersBackupGenerator returns a generator of FlexibleServersBackup instances for property testing.
func FlexibleServersBackupGenerator() gopter.Gen {
	if flexibleServersBackupGenerator != nil {
		return flexibleServersBackupGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddRelatedPropertyGeneratorsForFlexibleServersBackup(generators)
	flexibleServersBackupGenerator = gen.Struct(reflect.TypeOf(FlexibleServersBackup{}), generators)

	return flexibleServersBackupGenerator
}

// AddRelatedPropertyGeneratorsForFlexibleServersBackup is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForFlexibleServersBackup(gens map[string]gopter.Gen) {
	gens["Spec"] = FlexibleServersBackup_SpecGenerator()
	gens["Status"] = FlexibleServersBackup_STATUSGenerator()
}

func Test_FlexibleServersBackupOperatorSpec_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MinSuccessfulTests = 100
	parameters.MaxSize = 3
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip of FlexibleServersBackupOperatorSpec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForFlexibleServersBackupOperatorSpec, FlexibleServersBackupOperatorSpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

// RunJSONSerializationTestForFlexibleServersBackupOperatorSpec runs a test to see if a specific instance of FlexibleServersBackupOperatorSpec round trips to JSON and back losslessly
func RunJSONSerializationTestForFlexibleServersBackupOperatorSpec(subject FlexibleServersBackupOperatorSpec) string {
	// Serialize to JSON
	bin, err := json.Marshal(subject)
	if err != nil {
		return err.Error()
	}

	// Deserialize back into memory
	var actual FlexibleServersBackupOperatorSpec
	err = json.Unmarshal(bin, &actual)
	if err != nil {
		return err.Error()
	}

	// Check for outcome
	match := cmp.Equal(subject, actual, cmpopts.EquateEmpty())
	if !match {
		actualFmt := pretty.Sprint(actual)
		subjectFmt := pretty.Sprint(subject)
		result := diff.Diff(subjectFmt, actualFmt)
		return result
	}

	return ""
}

// Generator of FlexibleServersBackupOperatorSpec instances for property testing - lazily instantiated by
// FlexibleServersBackupOperatorSpecGenerator()
var flexibleServersBackupOperatorSpecGenerator gopter.Gen

// FlexibleServersBackupOperatorSpecGenerator returns a generator of FlexibleServersBackupOperatorSpec instances for property testing.
func FlexibleServersBackupOperatorSpecGenerator() gopter.Gen {
	if flexibleServersBackupOperatorSpecGenerator != nil {
		return flexibleServersBackupOperatorSpecGenerator
	}

	generators := make(map[string]gopter.Gen)
	flexibleServersBackupOperatorSpecGenerator = gen.Struct(reflect.TypeOf(FlexibleServersBackupOperatorSpec{}), generators)

	return flexibleServersBackupOperatorSpecGenerator
}

func Test_FlexibleServersBackup_STATUS_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MinSuccessfulTests = 80
	parameters.MaxSize = 3
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip of FlexibleServersBackup_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForFlexibleServersBackup_STATUS, FlexibleServersBackup_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

// RunJSONSerializationTestForFlexibleServersBackup_STATUS runs a test to see if a specific instance of FlexibleServersBackup_STATUS round trips to JSON and back losslessly
func RunJSONSerializationTestForFlexibleServersBackup_STATUS(subject FlexibleServersBackup_STATUS) string {
	// Serialize to JSON
	bin, err := json.Marshal(subject)
	if err != nil {
		return err.Error()
	}

	// Deserialize back into memory
	var actual FlexibleServersBackup_STATUS
	err = json.Unmarshal(bin, &actual)
	if err != nil {
		return err.Error()
	}

	// Check for outcome
	match := cmp.Equal(subject, actual, cmpopts.EquateEmpty())
	if !match {
		actualFmt := pretty.Sprint(actual)
		subjectFmt := pretty.Sprint(subject)
		result := diff.Diff(subjectFmt, actualFmt)
		return result
	}

	return ""
}

// Generator of FlexibleServersBackup_STATUS instances for property testing - lazily instantiated by
// FlexibleServersBackup_STATUSGenerator()
var flexibleServersBackup_STATUSGenerator gopter.Gen

// FlexibleServersBackup_STATUSGenerator returns a generator of FlexibleServersBackup_STATUS instances for property testing.
// We first initialize flexibleServersBackup_STATUSGenerator with a simplified generator based on the
// fields with primitive types then replacing it with a more complex one that also handles complex fields
// to ensure any cycles in the object graph properly terminate.
func FlexibleServersBackup_STATUSGenerator() gopter.Gen {
	if flexibleServersBackup_STATUSGenerator != nil {
		return flexibleServersBackup_STATUSGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForFlexibleServersBackup_STATUS(generators)
	flexibleServersBackup_STATUSGenerator = gen.Struct(reflect.TypeOf(FlexibleServersBackup_STATUS{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForFlexibleServersBackup_STATUS(generators)
	AddRelatedPropertyGeneratorsForFlexibleServersBackup_STATUS(generators)
	flexibleServersBackup_STATUSGenerator = gen.Struct(reflect.TypeOf(FlexibleServersBackup_STATUS{}), generators)

	return flexibleServersBackup_STATUSGenerator
}

// AddIndependentPropertyGeneratorsForFlexibleServersBackup_STATUS is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForFlexibleServersBackup_STATUS(gens map[string]gopter.Gen) {
	gens["BackupType"] = gen.PtrOf(gen.AlphaString())
	gens["CompletedTime"] = gen.PtrOf(gen.AlphaString())
	gens["Id"] = gen.PtrOf(gen.AlphaString())
	gens["Name"] = gen.PtrOf(gen.AlphaString())
	gens["Source"] = gen.PtrOf(gen.AlphaString())
	gens["Type"] = gen.PtrOf(gen.AlphaString())
}

// AddRelatedPropertyGeneratorsForFlexibleServersBackup_STATUS is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForFlexibleServersBackup_STATUS(gens map[string]gopter.Gen) {
	gens["SystemData"] = gen.PtrOf(SystemData_STATUSGenerator())
}

func Test_FlexibleServersBackup_Spec_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MinSuccessfulTests = 80
	parameters.MaxSize = 3
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip of FlexibleServersBackup_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForFlexibleServersBackup_Spec, FlexibleServersBackup_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

// RunJSONSerializationTestForFlexibleServersBackup_Spec runs a test to see if a specific instance of FlexibleServersBackup_Spec round trips to JSON and back losslessly
func RunJSONSerializationTestForFlexibleServersBackup_Spec(subject FlexibleServersBackup_Spec) string {
	// Serialize to JSON
	bin, err := json.Marshal(subject)
	if err != nil {
		return err.Error()
	}

	// Deserialize back into memory
	var actual FlexibleServersBackup_Spec
	err = json.Unmarshal(bin, &actual)
	if err != nil {
		return err.Error()
	}

	// Check for outcome
	match := cmp.Equal(subject, actual, cmpopts.EquateEmpty())
	if !match {
		actualFmt := pretty.Sprint(actual)
		subjectFmt := pretty.Sprint(subject)
		result := diff.Diff(subjectFmt, actualFmt)
		return result
	}

	return ""
}

// Generator of FlexibleServersBackup_Spec instances for property testing - lazily instantiated by
// FlexibleServersBackup_SpecGenerator()
var flexibleServersBackup_SpecGenerator gopter.Gen

// FlexibleServersBackup_SpecGenerator returns a generator of FlexibleServersBackup_Spec instances for property testing.
// We first initialize flexibleServersBackup_SpecGenerator with a simplified generator based on the
// fields with primitive types then replacing it with a more complex one that also handles complex fields
// to ensure any cycles in the object graph properly terminate.
func FlexibleServersBackup_SpecGenerator() gopter.Gen {
	if flexibleServersBackup_SpecGenerator != nil {
		return flexibleServersBackup_SpecGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForFlexibleServersBackup_Spec(generators)
	flexibleServersBackup_SpecGenerator = gen.Struct(reflect.TypeOf(FlexibleServersBackup_Spec{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForFlexibleServersBackup_Spec(generators)
	AddRelatedPropertyGeneratorsForFlexibleServersBackup_Spec(generators)
	flexibleServersBackup_SpecGenerator = gen.Struct(reflect.TypeOf(FlexibleServersBackup_Spec{}), generators)

	return flexibleServersBackup_SpecGenerator
}

// AddIndependentPropertyGeneratorsForFlexibleServersBackup_Spec is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForFlexibleServersBackup_Spec(gens map[string]gopter.Gen) {
	gens["AzureName"] = gen.AlphaString()
	gens["OriginalVersion"] = gen.AlphaString()
}

// AddRelatedPropertyGeneratorsForFlexibleServersBackup_Spec is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForFlexibleServersBackup_Spec(gens map[string]gopter.Gen) {
	gens["OperatorSpec"] = gen.PtrOf(FlexibleServersBackupOperatorSpecGenerator())
}
