// 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_DatabaseIdentity_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 DatabaseIdentity via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDatabaseIdentity, DatabaseIdentityGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDatabaseIdentity(generators)
	databaseIdentityGenerator = gen.Struct(reflect.TypeOf(DatabaseIdentity{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDatabaseIdentity(generators)
	AddRelatedPropertyGeneratorsForDatabaseIdentity(generators)
	databaseIdentityGenerator = gen.Struct(reflect.TypeOf(DatabaseIdentity{}), generators)

	return databaseIdentityGenerator
}

// AddIndependentPropertyGeneratorsForDatabaseIdentity is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForDatabaseIdentity(gens map[string]gopter.Gen) {
	gens["Type"] = gen.PtrOf(gen.OneConstOf(DatabaseIdentity_Type_None, DatabaseIdentity_Type_UserAssigned))
}

// AddRelatedPropertyGeneratorsForDatabaseIdentity is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForDatabaseIdentity(gens map[string]gopter.Gen) {
	gens["UserAssignedIdentities"] = gen.MapOf(
		gen.AlphaString(),
		UserAssignedIdentityDetailsGenerator())
}

func Test_DatabaseProperties_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 DatabaseProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDatabaseProperties, DatabasePropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// DatabasePropertiesGenerator returns a generator of DatabaseProperties instances for property testing.
func DatabasePropertiesGenerator() gopter.Gen {
	if databasePropertiesGenerator != nil {
		return databasePropertiesGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDatabaseProperties(generators)
	databasePropertiesGenerator = gen.Struct(reflect.TypeOf(DatabaseProperties{}), generators)

	return databasePropertiesGenerator
}

// AddIndependentPropertyGeneratorsForDatabaseProperties is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForDatabaseProperties(gens map[string]gopter.Gen) {
	gens["AutoPauseDelay"] = gen.PtrOf(gen.Int())
	gens["CatalogCollation"] = gen.PtrOf(gen.OneConstOf(DatabaseProperties_CatalogCollation_DATABASE_DEFAULT, DatabaseProperties_CatalogCollation_SQL_Latin1_General_CP1_CI_AS))
	gens["Collation"] = gen.PtrOf(gen.AlphaString())
	gens["CreateMode"] = gen.PtrOf(gen.OneConstOf(
		DatabaseProperties_CreateMode_Copy,
		DatabaseProperties_CreateMode_Default,
		DatabaseProperties_CreateMode_OnlineSecondary,
		DatabaseProperties_CreateMode_PointInTimeRestore,
		DatabaseProperties_CreateMode_Recovery,
		DatabaseProperties_CreateMode_Restore,
		DatabaseProperties_CreateMode_RestoreExternalBackup,
		DatabaseProperties_CreateMode_RestoreExternalBackupSecondary,
		DatabaseProperties_CreateMode_RestoreLongTermRetentionBackup,
		DatabaseProperties_CreateMode_Secondary))
	gens["ElasticPoolId"] = gen.PtrOf(gen.AlphaString())
	gens["FederatedClientId"] = gen.PtrOf(gen.AlphaString())
	gens["HighAvailabilityReplicaCount"] = gen.PtrOf(gen.Int())
	gens["IsLedgerOn"] = gen.PtrOf(gen.Bool())
	gens["LicenseType"] = gen.PtrOf(gen.OneConstOf(DatabaseProperties_LicenseType_BasePrice, DatabaseProperties_LicenseType_LicenseIncluded))
	gens["LongTermRetentionBackupResourceId"] = gen.PtrOf(gen.AlphaString())
	gens["MaintenanceConfigurationId"] = gen.PtrOf(gen.AlphaString())
	gens["MaxSizeBytes"] = gen.PtrOf(gen.Int())
	gens["MinCapacity"] = gen.PtrOf(gen.Float64())
	gens["ReadScale"] = gen.PtrOf(gen.OneConstOf(DatabaseProperties_ReadScale_Disabled, DatabaseProperties_ReadScale_Enabled))
	gens["RecoverableDatabaseId"] = gen.PtrOf(gen.AlphaString())
	gens["RecoveryServicesRecoveryPointId"] = gen.PtrOf(gen.AlphaString())
	gens["RequestedBackupStorageRedundancy"] = gen.PtrOf(gen.OneConstOf(
		DatabaseProperties_RequestedBackupStorageRedundancy_Geo,
		DatabaseProperties_RequestedBackupStorageRedundancy_GeoZone,
		DatabaseProperties_RequestedBackupStorageRedundancy_Local,
		DatabaseProperties_RequestedBackupStorageRedundancy_Zone))
	gens["RestorableDroppedDatabaseId"] = gen.PtrOf(gen.AlphaString())
	gens["RestorePointInTime"] = gen.PtrOf(gen.AlphaString())
	gens["SampleName"] = gen.PtrOf(gen.OneConstOf(DatabaseProperties_SampleName_AdventureWorksLT, DatabaseProperties_SampleName_WideWorldImportersFull, DatabaseProperties_SampleName_WideWorldImportersStd))
	gens["SecondaryType"] = gen.PtrOf(gen.OneConstOf(DatabaseProperties_SecondaryType_Geo, DatabaseProperties_SecondaryType_Named))
	gens["SourceDatabaseDeletionDate"] = gen.PtrOf(gen.AlphaString())
	gens["SourceDatabaseId"] = gen.PtrOf(gen.AlphaString())
	gens["SourceResourceId"] = gen.PtrOf(gen.AlphaString())
	gens["ZoneRedundant"] = gen.PtrOf(gen.Bool())
}

func Test_ServersDatabase_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 ServersDatabase_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForServersDatabase_Spec, ServersDatabase_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual ServersDatabase_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 ServersDatabase_Spec instances for property testing - lazily instantiated by
// ServersDatabase_SpecGenerator()
var serversDatabase_SpecGenerator gopter.Gen

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForServersDatabase_Spec(generators)
	serversDatabase_SpecGenerator = gen.Struct(reflect.TypeOf(ServersDatabase_Spec{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForServersDatabase_Spec(generators)
	AddRelatedPropertyGeneratorsForServersDatabase_Spec(generators)
	serversDatabase_SpecGenerator = gen.Struct(reflect.TypeOf(ServersDatabase_Spec{}), generators)

	return serversDatabase_SpecGenerator
}

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

// AddRelatedPropertyGeneratorsForServersDatabase_Spec is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForServersDatabase_Spec(gens map[string]gopter.Gen) {
	gens["Identity"] = gen.PtrOf(DatabaseIdentityGenerator())
	gens["Properties"] = gen.PtrOf(DatabasePropertiesGenerator())
	gens["Sku"] = gen.PtrOf(SkuGenerator())
}

func Test_Sku_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 Sku via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForSku, SkuGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// SkuGenerator returns a generator of Sku instances for property testing.
func SkuGenerator() gopter.Gen {
	if skuGenerator != nil {
		return skuGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForSku(generators)
	skuGenerator = gen.Struct(reflect.TypeOf(Sku{}), generators)

	return skuGenerator
}

// AddIndependentPropertyGeneratorsForSku is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForSku(gens map[string]gopter.Gen) {
	gens["Capacity"] = gen.PtrOf(gen.Int())
	gens["Family"] = gen.PtrOf(gen.AlphaString())
	gens["Name"] = gen.PtrOf(gen.AlphaString())
	gens["Size"] = gen.PtrOf(gen.AlphaString())
	gens["Tier"] = gen.PtrOf(gen.AlphaString())
}
