// 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_DeploymentCapacitySettings_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 DeploymentCapacitySettings via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDeploymentCapacitySettings, DeploymentCapacitySettingsGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// DeploymentCapacitySettingsGenerator returns a generator of DeploymentCapacitySettings instances for property testing.
func DeploymentCapacitySettingsGenerator() gopter.Gen {
	if deploymentCapacitySettingsGenerator != nil {
		return deploymentCapacitySettingsGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDeploymentCapacitySettings(generators)
	deploymentCapacitySettingsGenerator = gen.Struct(reflect.TypeOf(DeploymentCapacitySettings{}), generators)

	return deploymentCapacitySettingsGenerator
}

// AddIndependentPropertyGeneratorsForDeploymentCapacitySettings is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForDeploymentCapacitySettings(gens map[string]gopter.Gen) {
	gens["DesignatedCapacity"] = gen.PtrOf(gen.Int())
	gens["Priority"] = gen.PtrOf(gen.Int())
}

func Test_DeploymentModel_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 DeploymentModel via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDeploymentModel, DeploymentModelGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// DeploymentModelGenerator returns a generator of DeploymentModel instances for property testing.
func DeploymentModelGenerator() gopter.Gen {
	if deploymentModelGenerator != nil {
		return deploymentModelGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDeploymentModel(generators)
	deploymentModelGenerator = gen.Struct(reflect.TypeOf(DeploymentModel{}), generators)

	return deploymentModelGenerator
}

// AddIndependentPropertyGeneratorsForDeploymentModel is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForDeploymentModel(gens map[string]gopter.Gen) {
	gens["Format"] = gen.PtrOf(gen.AlphaString())
	gens["Name"] = gen.PtrOf(gen.AlphaString())
	gens["Publisher"] = gen.PtrOf(gen.AlphaString())
	gens["Source"] = gen.PtrOf(gen.AlphaString())
	gens["SourceAccount"] = gen.PtrOf(gen.AlphaString())
	gens["Version"] = gen.PtrOf(gen.AlphaString())
}

func Test_DeploymentProperties_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 DeploymentProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDeploymentProperties, DeploymentPropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDeploymentProperties(generators)
	deploymentPropertiesGenerator = gen.Struct(reflect.TypeOf(DeploymentProperties{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDeploymentProperties(generators)
	AddRelatedPropertyGeneratorsForDeploymentProperties(generators)
	deploymentPropertiesGenerator = gen.Struct(reflect.TypeOf(DeploymentProperties{}), generators)

	return deploymentPropertiesGenerator
}

// AddIndependentPropertyGeneratorsForDeploymentProperties is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForDeploymentProperties(gens map[string]gopter.Gen) {
	gens["ParentDeploymentName"] = gen.PtrOf(gen.AlphaString())
	gens["RaiPolicyName"] = gen.PtrOf(gen.AlphaString())
	gens["SpilloverDeploymentName"] = gen.PtrOf(gen.AlphaString())
	gens["VersionUpgradeOption"] = gen.PtrOf(gen.OneConstOf(DeploymentProperties_VersionUpgradeOption_NoAutoUpgrade, DeploymentProperties_VersionUpgradeOption_OnceCurrentVersionExpired, DeploymentProperties_VersionUpgradeOption_OnceNewDefaultVersionAvailable))
}

// AddRelatedPropertyGeneratorsForDeploymentProperties is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForDeploymentProperties(gens map[string]gopter.Gen) {
	gens["CapacitySettings"] = gen.PtrOf(DeploymentCapacitySettingsGenerator())
	gens["Model"] = gen.PtrOf(DeploymentModelGenerator())
	gens["ScaleSettings"] = gen.PtrOf(DeploymentScaleSettingsGenerator())
}

func Test_DeploymentScaleSettings_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 DeploymentScaleSettings via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDeploymentScaleSettings, DeploymentScaleSettingsGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// DeploymentScaleSettingsGenerator returns a generator of DeploymentScaleSettings instances for property testing.
func DeploymentScaleSettingsGenerator() gopter.Gen {
	if deploymentScaleSettingsGenerator != nil {
		return deploymentScaleSettingsGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDeploymentScaleSettings(generators)
	deploymentScaleSettingsGenerator = gen.Struct(reflect.TypeOf(DeploymentScaleSettings{}), generators)

	return deploymentScaleSettingsGenerator
}

// AddIndependentPropertyGeneratorsForDeploymentScaleSettings is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForDeploymentScaleSettings(gens map[string]gopter.Gen) {
	gens["Capacity"] = gen.PtrOf(gen.Int())
	gens["ScaleType"] = gen.PtrOf(gen.OneConstOf(DeploymentScaleSettings_ScaleType_Manual, DeploymentScaleSettings_ScaleType_Standard))
}

func Test_Deployment_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 Deployment_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDeployment_Spec, Deployment_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual Deployment_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 Deployment_Spec instances for property testing - lazily instantiated by Deployment_SpecGenerator()
var deployment_SpecGenerator gopter.Gen

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDeployment_Spec(generators)
	deployment_SpecGenerator = gen.Struct(reflect.TypeOf(Deployment_Spec{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDeployment_Spec(generators)
	AddRelatedPropertyGeneratorsForDeployment_Spec(generators)
	deployment_SpecGenerator = gen.Struct(reflect.TypeOf(Deployment_Spec{}), generators)

	return deployment_SpecGenerator
}

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

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