// 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_DnsForwardingRuleSetsForwardingRule_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 DnsForwardingRuleSetsForwardingRule_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDnsForwardingRuleSetsForwardingRule_Spec, DnsForwardingRuleSetsForwardingRule_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual DnsForwardingRuleSetsForwardingRule_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 DnsForwardingRuleSetsForwardingRule_Spec instances for property testing - lazily instantiated by
// DnsForwardingRuleSetsForwardingRule_SpecGenerator()
var dnsForwardingRuleSetsForwardingRule_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDnsForwardingRuleSetsForwardingRule_Spec(generators)
	AddRelatedPropertyGeneratorsForDnsForwardingRuleSetsForwardingRule_Spec(generators)
	dnsForwardingRuleSetsForwardingRule_SpecGenerator = gen.Struct(reflect.TypeOf(DnsForwardingRuleSetsForwardingRule_Spec{}), generators)

	return dnsForwardingRuleSetsForwardingRule_SpecGenerator
}

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

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

func Test_ForwardingRuleProperties_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 ForwardingRuleProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForForwardingRuleProperties, ForwardingRulePropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForForwardingRuleProperties(generators)
	AddRelatedPropertyGeneratorsForForwardingRuleProperties(generators)
	forwardingRulePropertiesGenerator = gen.Struct(reflect.TypeOf(ForwardingRuleProperties{}), generators)

	return forwardingRulePropertiesGenerator
}

// AddIndependentPropertyGeneratorsForForwardingRuleProperties is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForForwardingRuleProperties(gens map[string]gopter.Gen) {
	gens["DomainName"] = gen.PtrOf(gen.AlphaString())
	gens["ForwardingRuleState"] = gen.PtrOf(gen.OneConstOf(ForwardingRuleProperties_ForwardingRuleState_Disabled, ForwardingRuleProperties_ForwardingRuleState_Enabled))
	gens["Metadata"] = gen.MapOf(
		gen.AlphaString(),
		gen.AlphaString())
}

// AddRelatedPropertyGeneratorsForForwardingRuleProperties is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForForwardingRuleProperties(gens map[string]gopter.Gen) {
	gens["TargetDnsServers"] = gen.SliceOf(TargetDnsServerGenerator())
}

func Test_TargetDnsServer_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 TargetDnsServer via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForTargetDnsServer, TargetDnsServerGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// TargetDnsServerGenerator returns a generator of TargetDnsServer instances for property testing.
func TargetDnsServerGenerator() gopter.Gen {
	if targetDnsServerGenerator != nil {
		return targetDnsServerGenerator
	}

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

	return targetDnsServerGenerator
}

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