// 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_DatabaseBlobAuditingPolicyProperties_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 DatabaseBlobAuditingPolicyProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDatabaseBlobAuditingPolicyProperties, DatabaseBlobAuditingPolicyPropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// DatabaseBlobAuditingPolicyPropertiesGenerator returns a generator of DatabaseBlobAuditingPolicyProperties instances for property testing.
func DatabaseBlobAuditingPolicyPropertiesGenerator() gopter.Gen {
	if databaseBlobAuditingPolicyPropertiesGenerator != nil {
		return databaseBlobAuditingPolicyPropertiesGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDatabaseBlobAuditingPolicyProperties(generators)
	databaseBlobAuditingPolicyPropertiesGenerator = gen.Struct(reflect.TypeOf(DatabaseBlobAuditingPolicyProperties{}), generators)

	return databaseBlobAuditingPolicyPropertiesGenerator
}

// AddIndependentPropertyGeneratorsForDatabaseBlobAuditingPolicyProperties is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForDatabaseBlobAuditingPolicyProperties(gens map[string]gopter.Gen) {
	gens["AuditActionsAndGroups"] = gen.SliceOf(gen.AlphaString())
	gens["IsAzureMonitorTargetEnabled"] = gen.PtrOf(gen.Bool())
	gens["IsManagedIdentityInUse"] = gen.PtrOf(gen.Bool())
	gens["IsStorageSecondaryKeyInUse"] = gen.PtrOf(gen.Bool())
	gens["QueueDelayMs"] = gen.PtrOf(gen.Int())
	gens["RetentionDays"] = gen.PtrOf(gen.Int())
	gens["State"] = gen.PtrOf(gen.OneConstOf(DatabaseBlobAuditingPolicyProperties_State_Disabled, DatabaseBlobAuditingPolicyProperties_State_Enabled))
	gens["StorageAccountAccessKey"] = gen.PtrOf(gen.AlphaString())
	gens["StorageAccountSubscriptionId"] = gen.PtrOf(gen.AlphaString())
	gens["StorageEndpoint"] = gen.PtrOf(gen.AlphaString())
}

func Test_ServersDatabasesAuditingSetting_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 ServersDatabasesAuditingSetting_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForServersDatabasesAuditingSetting_Spec, ServersDatabasesAuditingSetting_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual ServersDatabasesAuditingSetting_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 ServersDatabasesAuditingSetting_Spec instances for property testing - lazily instantiated by
// ServersDatabasesAuditingSetting_SpecGenerator()
var serversDatabasesAuditingSetting_SpecGenerator gopter.Gen

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForServersDatabasesAuditingSetting_Spec(generators)
	serversDatabasesAuditingSetting_SpecGenerator = gen.Struct(reflect.TypeOf(ServersDatabasesAuditingSetting_Spec{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForServersDatabasesAuditingSetting_Spec(generators)
	AddRelatedPropertyGeneratorsForServersDatabasesAuditingSetting_Spec(generators)
	serversDatabasesAuditingSetting_SpecGenerator = gen.Struct(reflect.TypeOf(ServersDatabasesAuditingSetting_Spec{}), generators)

	return serversDatabasesAuditingSetting_SpecGenerator
}

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

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