// 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_ServerSecurityAlertPoliciesSecurityAlertsPolicyProperties_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 ServerSecurityAlertPoliciesSecurityAlertsPolicyProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForServerSecurityAlertPoliciesSecurityAlertsPolicyProperties, ServerSecurityAlertPoliciesSecurityAlertsPolicyPropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// ServerSecurityAlertPoliciesSecurityAlertsPolicyPropertiesGenerator returns a generator of ServerSecurityAlertPoliciesSecurityAlertsPolicyProperties instances for property testing.
func ServerSecurityAlertPoliciesSecurityAlertsPolicyPropertiesGenerator() gopter.Gen {
	if serverSecurityAlertPoliciesSecurityAlertsPolicyPropertiesGenerator != nil {
		return serverSecurityAlertPoliciesSecurityAlertsPolicyPropertiesGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForServerSecurityAlertPoliciesSecurityAlertsPolicyProperties(generators)
	serverSecurityAlertPoliciesSecurityAlertsPolicyPropertiesGenerator = gen.Struct(reflect.TypeOf(ServerSecurityAlertPoliciesSecurityAlertsPolicyProperties{}), generators)

	return serverSecurityAlertPoliciesSecurityAlertsPolicyPropertiesGenerator
}

// AddIndependentPropertyGeneratorsForServerSecurityAlertPoliciesSecurityAlertsPolicyProperties is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForServerSecurityAlertPoliciesSecurityAlertsPolicyProperties(gens map[string]gopter.Gen) {
	gens["DisabledAlerts"] = gen.SliceOf(gen.AlphaString())
	gens["EmailAccountAdmins"] = gen.PtrOf(gen.Bool())
	gens["EmailAddresses"] = gen.SliceOf(gen.AlphaString())
	gens["RetentionDays"] = gen.PtrOf(gen.Int())
	gens["State"] = gen.PtrOf(gen.OneConstOf(ServerSecurityAlertPoliciesSecurityAlertsPolicyProperties_State_Disabled, ServerSecurityAlertPoliciesSecurityAlertsPolicyProperties_State_Enabled))
	gens["StorageAccountAccessKey"] = gen.PtrOf(gen.AlphaString())
	gens["StorageEndpoint"] = gen.PtrOf(gen.AlphaString())
}

func Test_ServersSecurityAlertPolicy_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 ServersSecurityAlertPolicy_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForServersSecurityAlertPolicy_Spec, ServersSecurityAlertPolicy_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual ServersSecurityAlertPolicy_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 ServersSecurityAlertPolicy_Spec instances for property testing - lazily instantiated by
// ServersSecurityAlertPolicy_SpecGenerator()
var serversSecurityAlertPolicy_SpecGenerator gopter.Gen

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForServersSecurityAlertPolicy_Spec(generators)
	serversSecurityAlertPolicy_SpecGenerator = gen.Struct(reflect.TypeOf(ServersSecurityAlertPolicy_Spec{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForServersSecurityAlertPolicy_Spec(generators)
	AddRelatedPropertyGeneratorsForServersSecurityAlertPolicy_Spec(generators)
	serversSecurityAlertPolicy_SpecGenerator = gen.Struct(reflect.TypeOf(ServersSecurityAlertPolicy_Spec{}), generators)

	return serversSecurityAlertPolicy_SpecGenerator
}

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

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