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

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_AFDEndpointProperties_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 AFDEndpointProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForAFDEndpointProperties, AFDEndpointPropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual AFDEndpointProperties
	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 AFDEndpointProperties instances for property testing - lazily instantiated by
// AFDEndpointPropertiesGenerator()
var afdEndpointPropertiesGenerator gopter.Gen

// AFDEndpointPropertiesGenerator returns a generator of AFDEndpointProperties instances for property testing.
func AFDEndpointPropertiesGenerator() gopter.Gen {
	if afdEndpointPropertiesGenerator != nil {
		return afdEndpointPropertiesGenerator
	}

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

	return afdEndpointPropertiesGenerator
}

// AddIndependentPropertyGeneratorsForAFDEndpointProperties is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForAFDEndpointProperties(gens map[string]gopter.Gen) {
	gens["AutoGeneratedDomainNameLabelScope"] = gen.PtrOf(gen.OneConstOf(
		AutoGeneratedDomainNameLabelScope_NoReuse,
		AutoGeneratedDomainNameLabelScope_ResourceGroupReuse,
		AutoGeneratedDomainNameLabelScope_SubscriptionReuse,
		AutoGeneratedDomainNameLabelScope_TenantReuse))
	gens["EnabledState"] = gen.PtrOf(gen.OneConstOf(AFDEndpointProperties_EnabledState_Disabled, AFDEndpointProperties_EnabledState_Enabled))
}

func Test_AfdEndpoint_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 AfdEndpoint_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForAfdEndpoint_Spec, AfdEndpoint_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual AfdEndpoint_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 AfdEndpoint_Spec instances for property testing - lazily instantiated by AfdEndpoint_SpecGenerator()
var afdEndpoint_SpecGenerator gopter.Gen

// AfdEndpoint_SpecGenerator returns a generator of AfdEndpoint_Spec instances for property testing.
// We first initialize afdEndpoint_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 AfdEndpoint_SpecGenerator() gopter.Gen {
	if afdEndpoint_SpecGenerator != nil {
		return afdEndpoint_SpecGenerator
	}

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForAfdEndpoint_Spec(generators)
	AddRelatedPropertyGeneratorsForAfdEndpoint_Spec(generators)
	afdEndpoint_SpecGenerator = gen.Struct(reflect.TypeOf(AfdEndpoint_Spec{}), generators)

	return afdEndpoint_SpecGenerator
}

// AddIndependentPropertyGeneratorsForAfdEndpoint_Spec is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForAfdEndpoint_Spec(gens map[string]gopter.Gen) {
	gens["Location"] = gen.PtrOf(gen.AlphaString())
	gens["Name"] = gen.AlphaString()
	gens["Tags"] = gen.MapOf(
		gen.AlphaString(),
		gen.AlphaString())
}

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