// 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_ServersDatabasesTransparentDataEncryption_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 ServersDatabasesTransparentDataEncryption_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForServersDatabasesTransparentDataEncryption_Spec, ServersDatabasesTransparentDataEncryption_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual ServersDatabasesTransparentDataEncryption_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 ServersDatabasesTransparentDataEncryption_Spec instances for property testing - lazily instantiated by
// ServersDatabasesTransparentDataEncryption_SpecGenerator()
var serversDatabasesTransparentDataEncryption_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForServersDatabasesTransparentDataEncryption_Spec(generators)
	AddRelatedPropertyGeneratorsForServersDatabasesTransparentDataEncryption_Spec(generators)
	serversDatabasesTransparentDataEncryption_SpecGenerator = gen.Struct(reflect.TypeOf(ServersDatabasesTransparentDataEncryption_Spec{}), generators)

	return serversDatabasesTransparentDataEncryption_SpecGenerator
}

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

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

func Test_TransparentDataEncryptionProperties_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 TransparentDataEncryptionProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForTransparentDataEncryptionProperties, TransparentDataEncryptionPropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// TransparentDataEncryptionPropertiesGenerator returns a generator of TransparentDataEncryptionProperties instances for property testing.
func TransparentDataEncryptionPropertiesGenerator() gopter.Gen {
	if transparentDataEncryptionPropertiesGenerator != nil {
		return transparentDataEncryptionPropertiesGenerator
	}

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

	return transparentDataEncryptionPropertiesGenerator
}

// AddIndependentPropertyGeneratorsForTransparentDataEncryptionProperties is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForTransparentDataEncryptionProperties(gens map[string]gopter.Gen) {
	gens["State"] = gen.PtrOf(gen.OneConstOf(TransparentDataEncryptionProperties_State_Disabled, TransparentDataEncryptionProperties_State_Enabled))
}
