// 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_FlexibleServersAdvancedThreatProtectionSettings_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 FlexibleServersAdvancedThreatProtectionSettings_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForFlexibleServersAdvancedThreatProtectionSettings_Spec, FlexibleServersAdvancedThreatProtectionSettings_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual FlexibleServersAdvancedThreatProtectionSettings_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 FlexibleServersAdvancedThreatProtectionSettings_Spec instances for property testing - lazily
// instantiated by FlexibleServersAdvancedThreatProtectionSettings_SpecGenerator()
var flexibleServersAdvancedThreatProtectionSettings_SpecGenerator gopter.Gen

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForFlexibleServersAdvancedThreatProtectionSettings_Spec(generators)
	flexibleServersAdvancedThreatProtectionSettings_SpecGenerator = gen.Struct(reflect.TypeOf(FlexibleServersAdvancedThreatProtectionSettings_Spec{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForFlexibleServersAdvancedThreatProtectionSettings_Spec(generators)
	AddRelatedPropertyGeneratorsForFlexibleServersAdvancedThreatProtectionSettings_Spec(generators)
	flexibleServersAdvancedThreatProtectionSettings_SpecGenerator = gen.Struct(reflect.TypeOf(FlexibleServersAdvancedThreatProtectionSettings_Spec{}), generators)

	return flexibleServersAdvancedThreatProtectionSettings_SpecGenerator
}

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

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

func Test_ServerThreatProtectionProperties_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 ServerThreatProtectionProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForServerThreatProtectionProperties, ServerThreatProtectionPropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// ServerThreatProtectionPropertiesGenerator returns a generator of ServerThreatProtectionProperties instances for property testing.
func ServerThreatProtectionPropertiesGenerator() gopter.Gen {
	if serverThreatProtectionPropertiesGenerator != nil {
		return serverThreatProtectionPropertiesGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForServerThreatProtectionProperties(generators)
	serverThreatProtectionPropertiesGenerator = gen.Struct(reflect.TypeOf(ServerThreatProtectionProperties{}), generators)

	return serverThreatProtectionPropertiesGenerator
}

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