// 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_DomainProperties_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 DomainProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDomainProperties, DomainPropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDomainProperties(generators)
	AddRelatedPropertyGeneratorsForDomainProperties(generators)
	domainPropertiesGenerator = gen.Struct(reflect.TypeOf(DomainProperties{}), generators)

	return domainPropertiesGenerator
}

// AddIndependentPropertyGeneratorsForDomainProperties is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForDomainProperties(gens map[string]gopter.Gen) {
	gens["InputSchema"] = gen.PtrOf(gen.OneConstOf(DomainProperties_InputSchema_CloudEventSchemaV1_0, DomainProperties_InputSchema_CustomEventSchema, DomainProperties_InputSchema_EventGridSchema))
	gens["PublicNetworkAccess"] = gen.PtrOf(gen.OneConstOf(DomainProperties_PublicNetworkAccess_Disabled, DomainProperties_PublicNetworkAccess_Enabled))
}

// AddRelatedPropertyGeneratorsForDomainProperties is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForDomainProperties(gens map[string]gopter.Gen) {
	gens["InboundIpRules"] = gen.SliceOf(InboundIpRuleGenerator())
	gens["InputSchemaMapping"] = gen.PtrOf(InputSchemaMappingGenerator())
}

func Test_Domain_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 Domain_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDomain_Spec, Domain_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual Domain_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 Domain_Spec instances for property testing - lazily instantiated by Domain_SpecGenerator()
var domain_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDomain_Spec(generators)
	AddRelatedPropertyGeneratorsForDomain_Spec(generators)
	domain_SpecGenerator = gen.Struct(reflect.TypeOf(Domain_Spec{}), generators)

	return domain_SpecGenerator
}

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

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

func Test_InboundIpRule_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 InboundIpRule via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForInboundIpRule, InboundIpRuleGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// InboundIpRuleGenerator returns a generator of InboundIpRule instances for property testing.
func InboundIpRuleGenerator() gopter.Gen {
	if inboundIpRuleGenerator != nil {
		return inboundIpRuleGenerator
	}

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

	return inboundIpRuleGenerator
}

// AddIndependentPropertyGeneratorsForInboundIpRule is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForInboundIpRule(gens map[string]gopter.Gen) {
	gens["Action"] = gen.PtrOf(gen.OneConstOf(InboundIpRule_Action_Allow))
	gens["IpMask"] = gen.PtrOf(gen.AlphaString())
}

func Test_InputSchemaMapping_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 InputSchemaMapping via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForInputSchemaMapping, InputSchemaMappingGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// InputSchemaMappingGenerator returns a generator of InputSchemaMapping instances for property testing.
func InputSchemaMappingGenerator() gopter.Gen {
	if inputSchemaMappingGenerator != nil {
		return inputSchemaMappingGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddRelatedPropertyGeneratorsForInputSchemaMapping(generators)

	// handle OneOf by choosing only one field to instantiate
	var gens []gopter.Gen
	for propName, propGen := range generators {
		props := map[string]gopter.Gen{propName: propGen}
		gens = append(gens, gen.Struct(reflect.TypeOf(InputSchemaMapping{}), props))
	}
	inputSchemaMappingGenerator = gen.OneGenOf(gens...)

	return inputSchemaMappingGenerator
}

// AddRelatedPropertyGeneratorsForInputSchemaMapping is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForInputSchemaMapping(gens map[string]gopter.Gen) {
	gens["Json"] = JsonInputSchemaMappingGenerator().Map(func(it JsonInputSchemaMapping) *JsonInputSchemaMapping {
		return &it
	}) // generate one case for OneOf type
}

func Test_JsonField_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 JsonField via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForJsonField, JsonFieldGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// JsonFieldGenerator returns a generator of JsonField instances for property testing.
func JsonFieldGenerator() gopter.Gen {
	if jsonFieldGenerator != nil {
		return jsonFieldGenerator
	}

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

	return jsonFieldGenerator
}

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

func Test_JsonFieldWithDefault_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 JsonFieldWithDefault via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForJsonFieldWithDefault, JsonFieldWithDefaultGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// JsonFieldWithDefaultGenerator returns a generator of JsonFieldWithDefault instances for property testing.
func JsonFieldWithDefaultGenerator() gopter.Gen {
	if jsonFieldWithDefaultGenerator != nil {
		return jsonFieldWithDefaultGenerator
	}

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

	return jsonFieldWithDefaultGenerator
}

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

func Test_JsonInputSchemaMapping_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 JsonInputSchemaMapping via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForJsonInputSchemaMapping, JsonInputSchemaMappingGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForJsonInputSchemaMapping(generators)
	AddRelatedPropertyGeneratorsForJsonInputSchemaMapping(generators)
	jsonInputSchemaMappingGenerator = gen.Struct(reflect.TypeOf(JsonInputSchemaMapping{}), generators)

	return jsonInputSchemaMappingGenerator
}

// AddIndependentPropertyGeneratorsForJsonInputSchemaMapping is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForJsonInputSchemaMapping(gens map[string]gopter.Gen) {
	gens["InputSchemaMappingType"] = gen.OneConstOf(JsonInputSchemaMapping_InputSchemaMappingType_Json)
}

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

func Test_JsonInputSchemaMappingProperties_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 JsonInputSchemaMappingProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForJsonInputSchemaMappingProperties, JsonInputSchemaMappingPropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// JsonInputSchemaMappingPropertiesGenerator returns a generator of JsonInputSchemaMappingProperties instances for property testing.
func JsonInputSchemaMappingPropertiesGenerator() gopter.Gen {
	if jsonInputSchemaMappingPropertiesGenerator != nil {
		return jsonInputSchemaMappingPropertiesGenerator
	}

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

	return jsonInputSchemaMappingPropertiesGenerator
}

// AddRelatedPropertyGeneratorsForJsonInputSchemaMappingProperties is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForJsonInputSchemaMappingProperties(gens map[string]gopter.Gen) {
	gens["DataVersion"] = gen.PtrOf(JsonFieldWithDefaultGenerator())
	gens["EventTime"] = gen.PtrOf(JsonFieldGenerator())
	gens["EventType"] = gen.PtrOf(JsonFieldWithDefaultGenerator())
	gens["Id"] = gen.PtrOf(JsonFieldGenerator())
	gens["Subject"] = gen.PtrOf(JsonFieldWithDefaultGenerator())
	gens["Topic"] = gen.PtrOf(JsonFieldGenerator())
}
