// 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_FailoverGroupProperties_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 FailoverGroupProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForFailoverGroupProperties, FailoverGroupPropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForFailoverGroupProperties(generators)
	AddRelatedPropertyGeneratorsForFailoverGroupProperties(generators)
	failoverGroupPropertiesGenerator = gen.Struct(reflect.TypeOf(FailoverGroupProperties{}), generators)

	return failoverGroupPropertiesGenerator
}

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

// AddRelatedPropertyGeneratorsForFailoverGroupProperties is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForFailoverGroupProperties(gens map[string]gopter.Gen) {
	gens["PartnerServers"] = gen.SliceOf(PartnerInfoGenerator())
	gens["ReadOnlyEndpoint"] = gen.PtrOf(FailoverGroupReadOnlyEndpointGenerator())
	gens["ReadWriteEndpoint"] = gen.PtrOf(FailoverGroupReadWriteEndpointGenerator())
}

func Test_FailoverGroupReadOnlyEndpoint_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 FailoverGroupReadOnlyEndpoint via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForFailoverGroupReadOnlyEndpoint, FailoverGroupReadOnlyEndpointGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// FailoverGroupReadOnlyEndpointGenerator returns a generator of FailoverGroupReadOnlyEndpoint instances for property testing.
func FailoverGroupReadOnlyEndpointGenerator() gopter.Gen {
	if failoverGroupReadOnlyEndpointGenerator != nil {
		return failoverGroupReadOnlyEndpointGenerator
	}

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

	return failoverGroupReadOnlyEndpointGenerator
}

// AddIndependentPropertyGeneratorsForFailoverGroupReadOnlyEndpoint is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForFailoverGroupReadOnlyEndpoint(gens map[string]gopter.Gen) {
	gens["FailoverPolicy"] = gen.PtrOf(gen.OneConstOf(FailoverGroupReadOnlyEndpoint_FailoverPolicy_Disabled, FailoverGroupReadOnlyEndpoint_FailoverPolicy_Enabled))
}

func Test_FailoverGroupReadWriteEndpoint_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 FailoverGroupReadWriteEndpoint via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForFailoverGroupReadWriteEndpoint, FailoverGroupReadWriteEndpointGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// FailoverGroupReadWriteEndpointGenerator returns a generator of FailoverGroupReadWriteEndpoint instances for property testing.
func FailoverGroupReadWriteEndpointGenerator() gopter.Gen {
	if failoverGroupReadWriteEndpointGenerator != nil {
		return failoverGroupReadWriteEndpointGenerator
	}

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

	return failoverGroupReadWriteEndpointGenerator
}

// AddIndependentPropertyGeneratorsForFailoverGroupReadWriteEndpoint is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForFailoverGroupReadWriteEndpoint(gens map[string]gopter.Gen) {
	gens["FailoverPolicy"] = gen.PtrOf(gen.OneConstOf(FailoverGroupReadWriteEndpoint_FailoverPolicy_Automatic, FailoverGroupReadWriteEndpoint_FailoverPolicy_Manual))
	gens["FailoverWithDataLossGracePeriodMinutes"] = gen.PtrOf(gen.Int())
}

func Test_PartnerInfo_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 PartnerInfo via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForPartnerInfo, PartnerInfoGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// PartnerInfoGenerator returns a generator of PartnerInfo instances for property testing.
func PartnerInfoGenerator() gopter.Gen {
	if partnerInfoGenerator != nil {
		return partnerInfoGenerator
	}

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

	return partnerInfoGenerator
}

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

func Test_ServersFailoverGroup_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 ServersFailoverGroup_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForServersFailoverGroup_Spec, ServersFailoverGroup_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual ServersFailoverGroup_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 ServersFailoverGroup_Spec instances for property testing - lazily instantiated by
// ServersFailoverGroup_SpecGenerator()
var serversFailoverGroup_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForServersFailoverGroup_Spec(generators)
	AddRelatedPropertyGeneratorsForServersFailoverGroup_Spec(generators)
	serversFailoverGroup_SpecGenerator = gen.Struct(reflect.TypeOf(ServersFailoverGroup_Spec{}), generators)

	return serversFailoverGroup_SpecGenerator
}

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

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