// 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_CopyCompletionError_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 CopyCompletionError via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForCopyCompletionError, CopyCompletionErrorGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// CopyCompletionErrorGenerator returns a generator of CopyCompletionError instances for property testing.
func CopyCompletionErrorGenerator() gopter.Gen {
	if copyCompletionErrorGenerator != nil {
		return copyCompletionErrorGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForCopyCompletionError(generators)
	copyCompletionErrorGenerator = gen.Struct(reflect.TypeOf(CopyCompletionError{}), generators)

	return copyCompletionErrorGenerator
}

// AddIndependentPropertyGeneratorsForCopyCompletionError is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForCopyCompletionError(gens map[string]gopter.Gen) {
	gens["ErrorCode"] = gen.PtrOf(gen.OneConstOf(CopyCompletionErrorReason_CopySourceNotFound))
	gens["ErrorMessage"] = gen.PtrOf(gen.AlphaString())
}

func Test_SnapshotProperties_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 SnapshotProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForSnapshotProperties, SnapshotPropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForSnapshotProperties(generators)
	snapshotPropertiesGenerator = gen.Struct(reflect.TypeOf(SnapshotProperties{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForSnapshotProperties(generators)
	AddRelatedPropertyGeneratorsForSnapshotProperties(generators)
	snapshotPropertiesGenerator = gen.Struct(reflect.TypeOf(SnapshotProperties{}), generators)

	return snapshotPropertiesGenerator
}

// AddIndependentPropertyGeneratorsForSnapshotProperties is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForSnapshotProperties(gens map[string]gopter.Gen) {
	gens["CompletionPercent"] = gen.PtrOf(gen.Float64())
	gens["DataAccessAuthMode"] = gen.PtrOf(gen.OneConstOf(DataAccessAuthMode_AzureActiveDirectory, DataAccessAuthMode_None))
	gens["DiskAccessId"] = gen.PtrOf(gen.AlphaString())
	gens["DiskSizeGB"] = gen.PtrOf(gen.Int())
	gens["HyperVGeneration"] = gen.PtrOf(gen.OneConstOf(HyperVGeneration_V1, HyperVGeneration_V2))
	gens["Incremental"] = gen.PtrOf(gen.Bool())
	gens["NetworkAccessPolicy"] = gen.PtrOf(gen.OneConstOf(NetworkAccessPolicy_AllowAll, NetworkAccessPolicy_AllowPrivate, NetworkAccessPolicy_DenyAll))
	gens["OsType"] = gen.PtrOf(gen.OneConstOf(OperatingSystemTypes_Linux, OperatingSystemTypes_Windows))
	gens["PublicNetworkAccess"] = gen.PtrOf(gen.OneConstOf(PublicNetworkAccess_Disabled, PublicNetworkAccess_Enabled))
	gens["SupportsHibernation"] = gen.PtrOf(gen.Bool())
}

// AddRelatedPropertyGeneratorsForSnapshotProperties is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForSnapshotProperties(gens map[string]gopter.Gen) {
	gens["CopyCompletionError"] = gen.PtrOf(CopyCompletionErrorGenerator())
	gens["CreationData"] = gen.PtrOf(CreationDataGenerator())
	gens["Encryption"] = gen.PtrOf(EncryptionGenerator())
	gens["EncryptionSettingsCollection"] = gen.PtrOf(EncryptionSettingsCollectionGenerator())
	gens["PurchasePlan"] = gen.PtrOf(DiskPurchasePlanGenerator())
	gens["SecurityProfile"] = gen.PtrOf(DiskSecurityProfileGenerator())
	gens["SupportedCapabilities"] = gen.PtrOf(SupportedCapabilitiesGenerator())
}

func Test_SnapshotSku_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 SnapshotSku via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForSnapshotSku, SnapshotSkuGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// SnapshotSkuGenerator returns a generator of SnapshotSku instances for property testing.
func SnapshotSkuGenerator() gopter.Gen {
	if snapshotSkuGenerator != nil {
		return snapshotSkuGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForSnapshotSku(generators)
	snapshotSkuGenerator = gen.Struct(reflect.TypeOf(SnapshotSku{}), generators)

	return snapshotSkuGenerator
}

// AddIndependentPropertyGeneratorsForSnapshotSku is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForSnapshotSku(gens map[string]gopter.Gen) {
	gens["Name"] = gen.PtrOf(gen.OneConstOf(SnapshotStorageAccountTypes_Premium_LRS, SnapshotStorageAccountTypes_Standard_LRS, SnapshotStorageAccountTypes_Standard_ZRS))
}

func Test_Snapshot_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 Snapshot_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForSnapshot_Spec, Snapshot_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual Snapshot_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 Snapshot_Spec instances for property testing - lazily instantiated by Snapshot_SpecGenerator()
var snapshot_SpecGenerator gopter.Gen

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForSnapshot_Spec(generators)
	snapshot_SpecGenerator = gen.Struct(reflect.TypeOf(Snapshot_Spec{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForSnapshot_Spec(generators)
	AddRelatedPropertyGeneratorsForSnapshot_Spec(generators)
	snapshot_SpecGenerator = gen.Struct(reflect.TypeOf(Snapshot_Spec{}), generators)

	return snapshot_SpecGenerator
}

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

// AddRelatedPropertyGeneratorsForSnapshot_Spec is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForSnapshot_Spec(gens map[string]gopter.Gen) {
	gens["ExtendedLocation"] = gen.PtrOf(ExtendedLocationGenerator())
	gens["Properties"] = gen.PtrOf(SnapshotPropertiesGenerator())
	gens["Sku"] = gen.PtrOf(SnapshotSkuGenerator())
}
