// 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_DnsResolverProperties_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 DnsResolverProperties_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDnsResolverProperties_STATUS, DnsResolverProperties_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual DnsResolverProperties_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 DnsResolverProperties_STATUS instances for property testing - lazily instantiated by
// DnsResolverProperties_STATUSGenerator()
var dnsResolverProperties_STATUSGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDnsResolverProperties_STATUS(generators)
	AddRelatedPropertyGeneratorsForDnsResolverProperties_STATUS(generators)
	dnsResolverProperties_STATUSGenerator = gen.Struct(reflect.TypeOf(DnsResolverProperties_STATUS{}), generators)

	return dnsResolverProperties_STATUSGenerator
}

// AddIndependentPropertyGeneratorsForDnsResolverProperties_STATUS is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForDnsResolverProperties_STATUS(gens map[string]gopter.Gen) {
	gens["DnsResolverState"] = gen.PtrOf(gen.OneConstOf(DnsResolverProperties_DnsResolverState_STATUS_Connected, DnsResolverProperties_DnsResolverState_STATUS_Disconnected))
	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())
}

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

func Test_DnsResolver_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 DnsResolver_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDnsResolver_STATUS, DnsResolver_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual DnsResolver_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 DnsResolver_STATUS instances for property testing - lazily instantiated by DnsResolver_STATUSGenerator()
var dnsResolver_STATUSGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDnsResolver_STATUS(generators)
	AddRelatedPropertyGeneratorsForDnsResolver_STATUS(generators)
	dnsResolver_STATUSGenerator = gen.Struct(reflect.TypeOf(DnsResolver_STATUS{}), generators)

	return dnsResolver_STATUSGenerator
}

// AddIndependentPropertyGeneratorsForDnsResolver_STATUS is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForDnsResolver_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["Tags"] = gen.MapOf(
		gen.AlphaString(),
		gen.AlphaString())
	gens["Type"] = gen.PtrOf(gen.AlphaString())
}

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