// 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_AFDDomainHttpsParameters_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 AFDDomainHttpsParameters via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForAFDDomainHttpsParameters, AFDDomainHttpsParametersGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForAFDDomainHttpsParameters(generators)
	AddRelatedPropertyGeneratorsForAFDDomainHttpsParameters(generators)
	afdDomainHttpsParametersGenerator = gen.Struct(reflect.TypeOf(AFDDomainHttpsParameters{}), generators)

	return afdDomainHttpsParametersGenerator
}

// AddIndependentPropertyGeneratorsForAFDDomainHttpsParameters is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForAFDDomainHttpsParameters(gens map[string]gopter.Gen) {
	gens["CertificateType"] = gen.PtrOf(gen.OneConstOf(AFDDomainHttpsParameters_CertificateType_AzureFirstPartyManagedCertificate, AFDDomainHttpsParameters_CertificateType_CustomerCertificate, AFDDomainHttpsParameters_CertificateType_ManagedCertificate))
	gens["MinimumTlsVersion"] = gen.PtrOf(gen.OneConstOf(AFDDomainHttpsParameters_MinimumTlsVersion_TLS10, AFDDomainHttpsParameters_MinimumTlsVersion_TLS12))
}

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

func Test_AFDDomainProperties_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 AFDDomainProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForAFDDomainProperties, AFDDomainPropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForAFDDomainProperties(generators)
	AddRelatedPropertyGeneratorsForAFDDomainProperties(generators)
	afdDomainPropertiesGenerator = gen.Struct(reflect.TypeOf(AFDDomainProperties{}), generators)

	return afdDomainPropertiesGenerator
}

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

// AddRelatedPropertyGeneratorsForAFDDomainProperties is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForAFDDomainProperties(gens map[string]gopter.Gen) {
	gens["AzureDnsZone"] = gen.PtrOf(ResourceReferenceGenerator())
	gens["PreValidatedCustomDomainResourceId"] = gen.PtrOf(ResourceReferenceGenerator())
	gens["TlsSettings"] = gen.PtrOf(AFDDomainHttpsParametersGenerator())
}

func Test_AfdCustomDomain_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 AfdCustomDomain_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForAfdCustomDomain_Spec, AfdCustomDomain_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual AfdCustomDomain_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 AfdCustomDomain_Spec instances for property testing - lazily instantiated by
// AfdCustomDomain_SpecGenerator()
var afdCustomDomain_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForAfdCustomDomain_Spec(generators)
	AddRelatedPropertyGeneratorsForAfdCustomDomain_Spec(generators)
	afdCustomDomain_SpecGenerator = gen.Struct(reflect.TypeOf(AfdCustomDomain_Spec{}), generators)

	return afdCustomDomain_SpecGenerator
}

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

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

func Test_ResourceReference_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 ResourceReference via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForResourceReference, ResourceReferenceGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// ResourceReferenceGenerator returns a generator of ResourceReference instances for property testing.
func ResourceReferenceGenerator() gopter.Gen {
	if resourceReferenceGenerator != nil {
		return resourceReferenceGenerator
	}

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

	return resourceReferenceGenerator
}

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