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

import (
	"encoding/json"
	storage "github.com/Azure/azure-service-operator/v2/api/network/v1api20220701/storage"
	"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_DnsForwardingRuleset_WhenConvertedToHub_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	parameters.MinSuccessfulTests = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from DnsForwardingRuleset to hub returns original",
		prop.ForAll(RunResourceConversionTestForDnsForwardingRuleset, DnsForwardingRulesetGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

// RunResourceConversionTestForDnsForwardingRuleset tests if a specific instance of DnsForwardingRuleset round trips to the hub storage version and back losslessly
func RunResourceConversionTestForDnsForwardingRuleset(subject DnsForwardingRuleset) string {
	// Copy subject to make sure conversion doesn't modify it
	copied := subject.DeepCopy()

	// Convert to our hub version
	var hub storage.DnsForwardingRuleset
	err := copied.ConvertTo(&hub)
	if err != nil {
		return err.Error()
	}

	// Convert from our hub version
	var actual DnsForwardingRuleset
	err = actual.ConvertFrom(&hub)
	if err != nil {
		return err.Error()
	}

	// Compare actual with what we started with
	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 ""
}

func Test_DnsForwardingRuleset_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from DnsForwardingRuleset to DnsForwardingRuleset via AssignProperties_To_DnsForwardingRuleset & AssignProperties_From_DnsForwardingRuleset returns original",
		prop.ForAll(RunPropertyAssignmentTestForDnsForwardingRuleset, DnsForwardingRulesetGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

// RunPropertyAssignmentTestForDnsForwardingRuleset tests if a specific instance of DnsForwardingRuleset can be assigned to storage and back losslessly
func RunPropertyAssignmentTestForDnsForwardingRuleset(subject DnsForwardingRuleset) string {
	// Copy subject to make sure assignment doesn't modify it
	copied := subject.DeepCopy()

	// Use AssignPropertiesTo() for the first stage of conversion
	var other storage.DnsForwardingRuleset
	err := copied.AssignProperties_To_DnsForwardingRuleset(&other)
	if err != nil {
		return err.Error()
	}

	// Use AssignPropertiesFrom() to convert back to our original type
	var actual DnsForwardingRuleset
	err = actual.AssignProperties_From_DnsForwardingRuleset(&other)
	if err != nil {
		return err.Error()
	}

	// Check for a match
	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 ""
}

func Test_DnsForwardingRuleset_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 DnsForwardingRuleset via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDnsForwardingRuleset, DnsForwardingRulesetGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// DnsForwardingRulesetGenerator returns a generator of DnsForwardingRuleset instances for property testing.
func DnsForwardingRulesetGenerator() gopter.Gen {
	if dnsForwardingRulesetGenerator != nil {
		return dnsForwardingRulesetGenerator
	}

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

	return dnsForwardingRulesetGenerator
}

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

func Test_DnsForwardingRulesetOperatorSpec_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from DnsForwardingRulesetOperatorSpec to DnsForwardingRulesetOperatorSpec via AssignProperties_To_DnsForwardingRulesetOperatorSpec & AssignProperties_From_DnsForwardingRulesetOperatorSpec returns original",
		prop.ForAll(RunPropertyAssignmentTestForDnsForwardingRulesetOperatorSpec, DnsForwardingRulesetOperatorSpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

// RunPropertyAssignmentTestForDnsForwardingRulesetOperatorSpec tests if a specific instance of DnsForwardingRulesetOperatorSpec can be assigned to storage and back losslessly
func RunPropertyAssignmentTestForDnsForwardingRulesetOperatorSpec(subject DnsForwardingRulesetOperatorSpec) string {
	// Copy subject to make sure assignment doesn't modify it
	copied := subject.DeepCopy()

	// Use AssignPropertiesTo() for the first stage of conversion
	var other storage.DnsForwardingRulesetOperatorSpec
	err := copied.AssignProperties_To_DnsForwardingRulesetOperatorSpec(&other)
	if err != nil {
		return err.Error()
	}

	// Use AssignPropertiesFrom() to convert back to our original type
	var actual DnsForwardingRulesetOperatorSpec
	err = actual.AssignProperties_From_DnsForwardingRulesetOperatorSpec(&other)
	if err != nil {
		return err.Error()
	}

	// Check for a match
	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 ""
}

func Test_DnsForwardingRulesetOperatorSpec_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 DnsForwardingRulesetOperatorSpec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDnsForwardingRulesetOperatorSpec, DnsForwardingRulesetOperatorSpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// DnsForwardingRulesetOperatorSpecGenerator returns a generator of DnsForwardingRulesetOperatorSpec instances for property testing.
func DnsForwardingRulesetOperatorSpecGenerator() gopter.Gen {
	if dnsForwardingRulesetOperatorSpecGenerator != nil {
		return dnsForwardingRulesetOperatorSpecGenerator
	}

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

	return dnsForwardingRulesetOperatorSpecGenerator
}

func Test_DnsForwardingRuleset_STATUS_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from DnsForwardingRuleset_STATUS to DnsForwardingRuleset_STATUS via AssignProperties_To_DnsForwardingRuleset_STATUS & AssignProperties_From_DnsForwardingRuleset_STATUS returns original",
		prop.ForAll(RunPropertyAssignmentTestForDnsForwardingRuleset_STATUS, DnsForwardingRuleset_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

// RunPropertyAssignmentTestForDnsForwardingRuleset_STATUS tests if a specific instance of DnsForwardingRuleset_STATUS can be assigned to storage and back losslessly
func RunPropertyAssignmentTestForDnsForwardingRuleset_STATUS(subject DnsForwardingRuleset_STATUS) string {
	// Copy subject to make sure assignment doesn't modify it
	copied := subject.DeepCopy()

	// Use AssignPropertiesTo() for the first stage of conversion
	var other storage.DnsForwardingRuleset_STATUS
	err := copied.AssignProperties_To_DnsForwardingRuleset_STATUS(&other)
	if err != nil {
		return err.Error()
	}

	// Use AssignPropertiesFrom() to convert back to our original type
	var actual DnsForwardingRuleset_STATUS
	err = actual.AssignProperties_From_DnsForwardingRuleset_STATUS(&other)
	if err != nil {
		return err.Error()
	}

	// Check for a match
	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 ""
}

func Test_DnsForwardingRuleset_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 DnsForwardingRuleset_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDnsForwardingRuleset_STATUS, DnsForwardingRuleset_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual DnsForwardingRuleset_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 DnsForwardingRuleset_STATUS instances for property testing - lazily instantiated by
// DnsForwardingRuleset_STATUSGenerator()
var dnsForwardingRuleset_STATUSGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDnsForwardingRuleset_STATUS(generators)
	AddRelatedPropertyGeneratorsForDnsForwardingRuleset_STATUS(generators)
	dnsForwardingRuleset_STATUSGenerator = gen.Struct(reflect.TypeOf(DnsForwardingRuleset_STATUS{}), generators)

	return dnsForwardingRuleset_STATUSGenerator
}

// AddIndependentPropertyGeneratorsForDnsForwardingRuleset_STATUS is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForDnsForwardingRuleset_STATUS(gens map[string]gopter.Gen) {
	gens["Etag"] = gen.PtrOf(gen.AlphaString())
	gens["Id"] = gen.PtrOf(gen.AlphaString())
	gens["Location"] = gen.PtrOf(gen.AlphaString())
	gens["Name"] = gen.PtrOf(gen.AlphaString())
	gens["ProvisioningState"] = gen.PtrOf(gen.OneConstOf(
		DnsresolverProvisioningState_STATUS_Canceled,
		DnsresolverProvisioningState_STATUS_Creating,
		DnsresolverProvisioningState_STATUS_Deleting,
		DnsresolverProvisioningState_STATUS_Failed,
		DnsresolverProvisioningState_STATUS_Succeeded,
		DnsresolverProvisioningState_STATUS_Updating))
	gens["ResourceGuid"] = gen.PtrOf(gen.AlphaString())
	gens["Tags"] = gen.MapOf(
		gen.AlphaString(),
		gen.AlphaString())
	gens["Type"] = gen.PtrOf(gen.AlphaString())
}

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

func Test_DnsForwardingRuleset_Spec_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from DnsForwardingRuleset_Spec to DnsForwardingRuleset_Spec via AssignProperties_To_DnsForwardingRuleset_Spec & AssignProperties_From_DnsForwardingRuleset_Spec returns original",
		prop.ForAll(RunPropertyAssignmentTestForDnsForwardingRuleset_Spec, DnsForwardingRuleset_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

// RunPropertyAssignmentTestForDnsForwardingRuleset_Spec tests if a specific instance of DnsForwardingRuleset_Spec can be assigned to storage and back losslessly
func RunPropertyAssignmentTestForDnsForwardingRuleset_Spec(subject DnsForwardingRuleset_Spec) string {
	// Copy subject to make sure assignment doesn't modify it
	copied := subject.DeepCopy()

	// Use AssignPropertiesTo() for the first stage of conversion
	var other storage.DnsForwardingRuleset_Spec
	err := copied.AssignProperties_To_DnsForwardingRuleset_Spec(&other)
	if err != nil {
		return err.Error()
	}

	// Use AssignPropertiesFrom() to convert back to our original type
	var actual DnsForwardingRuleset_Spec
	err = actual.AssignProperties_From_DnsForwardingRuleset_Spec(&other)
	if err != nil {
		return err.Error()
	}

	// Check for a match
	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 ""
}

func Test_DnsForwardingRuleset_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 DnsForwardingRuleset_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDnsForwardingRuleset_Spec, DnsForwardingRuleset_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual DnsForwardingRuleset_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 DnsForwardingRuleset_Spec instances for property testing - lazily instantiated by
// DnsForwardingRuleset_SpecGenerator()
var dnsForwardingRuleset_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDnsForwardingRuleset_Spec(generators)
	AddRelatedPropertyGeneratorsForDnsForwardingRuleset_Spec(generators)
	dnsForwardingRuleset_SpecGenerator = gen.Struct(reflect.TypeOf(DnsForwardingRuleset_Spec{}), generators)

	return dnsForwardingRuleset_SpecGenerator
}

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

// AddRelatedPropertyGeneratorsForDnsForwardingRuleset_Spec is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForDnsForwardingRuleset_Spec(gens map[string]gopter.Gen) {
	gens["DnsResolverOutboundEndpoints"] = gen.SliceOf(SubResourceGenerator())
	gens["OperatorSpec"] = gen.PtrOf(DnsForwardingRulesetOperatorSpecGenerator())
}
