// 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_AutoUpgradeNodeImageSelection_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 AutoUpgradeNodeImageSelection via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForAutoUpgradeNodeImageSelection, AutoUpgradeNodeImageSelectionGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// AutoUpgradeNodeImageSelectionGenerator returns a generator of AutoUpgradeNodeImageSelection instances for property testing.
func AutoUpgradeNodeImageSelectionGenerator() gopter.Gen {
	if autoUpgradeNodeImageSelectionGenerator != nil {
		return autoUpgradeNodeImageSelectionGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForAutoUpgradeNodeImageSelection(generators)
	autoUpgradeNodeImageSelectionGenerator = gen.Struct(reflect.TypeOf(AutoUpgradeNodeImageSelection{}), generators)

	return autoUpgradeNodeImageSelectionGenerator
}

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

func Test_AutoUpgradeProfileProperties_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 AutoUpgradeProfileProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForAutoUpgradeProfileProperties, AutoUpgradeProfilePropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForAutoUpgradeProfileProperties(generators)
	autoUpgradeProfilePropertiesGenerator = gen.Struct(reflect.TypeOf(AutoUpgradeProfileProperties{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForAutoUpgradeProfileProperties(generators)
	AddRelatedPropertyGeneratorsForAutoUpgradeProfileProperties(generators)
	autoUpgradeProfilePropertiesGenerator = gen.Struct(reflect.TypeOf(AutoUpgradeProfileProperties{}), generators)

	return autoUpgradeProfilePropertiesGenerator
}

// AddIndependentPropertyGeneratorsForAutoUpgradeProfileProperties is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForAutoUpgradeProfileProperties(gens map[string]gopter.Gen) {
	gens["Channel"] = gen.PtrOf(gen.OneConstOf(UpgradeChannel_NodeImage, UpgradeChannel_Rapid, UpgradeChannel_Stable))
	gens["Disabled"] = gen.PtrOf(gen.Bool())
	gens["UpdateStrategyId"] = gen.PtrOf(gen.AlphaString())
}

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

func Test_FleetsAutoUpgradeProfile_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 FleetsAutoUpgradeProfile_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForFleetsAutoUpgradeProfile_Spec, FleetsAutoUpgradeProfile_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual FleetsAutoUpgradeProfile_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 FleetsAutoUpgradeProfile_Spec instances for property testing - lazily instantiated by
// FleetsAutoUpgradeProfile_SpecGenerator()
var fleetsAutoUpgradeProfile_SpecGenerator gopter.Gen

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForFleetsAutoUpgradeProfile_Spec(generators)
	fleetsAutoUpgradeProfile_SpecGenerator = gen.Struct(reflect.TypeOf(FleetsAutoUpgradeProfile_Spec{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForFleetsAutoUpgradeProfile_Spec(generators)
	AddRelatedPropertyGeneratorsForFleetsAutoUpgradeProfile_Spec(generators)
	fleetsAutoUpgradeProfile_SpecGenerator = gen.Struct(reflect.TypeOf(FleetsAutoUpgradeProfile_Spec{}), generators)

	return fleetsAutoUpgradeProfile_SpecGenerator
}

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

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