// 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_SqlDatabaseContainerTrigger_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 SqlDatabaseContainerTrigger_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForSqlDatabaseContainerTrigger_Spec, SqlDatabaseContainerTrigger_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual SqlDatabaseContainerTrigger_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 SqlDatabaseContainerTrigger_Spec instances for property testing - lazily instantiated by
// SqlDatabaseContainerTrigger_SpecGenerator()
var sqlDatabaseContainerTrigger_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForSqlDatabaseContainerTrigger_Spec(generators)
	AddRelatedPropertyGeneratorsForSqlDatabaseContainerTrigger_Spec(generators)
	sqlDatabaseContainerTrigger_SpecGenerator = gen.Struct(reflect.TypeOf(SqlDatabaseContainerTrigger_Spec{}), generators)

	return sqlDatabaseContainerTrigger_SpecGenerator
}

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

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

func Test_SqlTriggerCreateUpdateProperties_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 SqlTriggerCreateUpdateProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForSqlTriggerCreateUpdateProperties, SqlTriggerCreateUpdatePropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// SqlTriggerCreateUpdatePropertiesGenerator returns a generator of SqlTriggerCreateUpdateProperties instances for property testing.
func SqlTriggerCreateUpdatePropertiesGenerator() gopter.Gen {
	if sqlTriggerCreateUpdatePropertiesGenerator != nil {
		return sqlTriggerCreateUpdatePropertiesGenerator
	}

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

	return sqlTriggerCreateUpdatePropertiesGenerator
}

// AddRelatedPropertyGeneratorsForSqlTriggerCreateUpdateProperties is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForSqlTriggerCreateUpdateProperties(gens map[string]gopter.Gen) {
	gens["Options"] = gen.PtrOf(CreateUpdateOptionsGenerator())
	gens["Resource"] = gen.PtrOf(SqlTriggerResourceGenerator())
}

func Test_SqlTriggerResource_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 SqlTriggerResource via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForSqlTriggerResource, SqlTriggerResourceGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// SqlTriggerResourceGenerator returns a generator of SqlTriggerResource instances for property testing.
func SqlTriggerResourceGenerator() gopter.Gen {
	if sqlTriggerResourceGenerator != nil {
		return sqlTriggerResourceGenerator
	}

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

	return sqlTriggerResourceGenerator
}

// AddIndependentPropertyGeneratorsForSqlTriggerResource is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForSqlTriggerResource(gens map[string]gopter.Gen) {
	gens["Body"] = gen.PtrOf(gen.AlphaString())
	gens["Id"] = gen.PtrOf(gen.AlphaString())
	gens["TriggerOperation"] = gen.PtrOf(gen.OneConstOf(
		SqlTriggerResource_TriggerOperation_All,
		SqlTriggerResource_TriggerOperation_Create,
		SqlTriggerResource_TriggerOperation_Delete,
		SqlTriggerResource_TriggerOperation_Replace,
		SqlTriggerResource_TriggerOperation_Update))
	gens["TriggerType"] = gen.PtrOf(gen.OneConstOf(SqlTriggerResource_TriggerType_Post, SqlTriggerResource_TriggerType_Pre))
}
