// 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_FleetUpdateStrategyProperties_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 FleetUpdateStrategyProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForFleetUpdateStrategyProperties, FleetUpdateStrategyPropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// FleetUpdateStrategyPropertiesGenerator returns a generator of FleetUpdateStrategyProperties instances for property testing.
func FleetUpdateStrategyPropertiesGenerator() gopter.Gen {
	if fleetUpdateStrategyPropertiesGenerator != nil {
		return fleetUpdateStrategyPropertiesGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddRelatedPropertyGeneratorsForFleetUpdateStrategyProperties(generators)
	fleetUpdateStrategyPropertiesGenerator = gen.Struct(reflect.TypeOf(FleetUpdateStrategyProperties{}), generators)

	return fleetUpdateStrategyPropertiesGenerator
}

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

func Test_FleetsUpdateStrategy_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 FleetsUpdateStrategy_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForFleetsUpdateStrategy_Spec, FleetsUpdateStrategy_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual FleetsUpdateStrategy_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 FleetsUpdateStrategy_Spec instances for property testing - lazily instantiated by
// FleetsUpdateStrategy_SpecGenerator()
var fleetsUpdateStrategy_SpecGenerator gopter.Gen

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForFleetsUpdateStrategy_Spec(generators)
	fleetsUpdateStrategy_SpecGenerator = gen.Struct(reflect.TypeOf(FleetsUpdateStrategy_Spec{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForFleetsUpdateStrategy_Spec(generators)
	AddRelatedPropertyGeneratorsForFleetsUpdateStrategy_Spec(generators)
	fleetsUpdateStrategy_SpecGenerator = gen.Struct(reflect.TypeOf(FleetsUpdateStrategy_Spec{}), generators)

	return fleetsUpdateStrategy_SpecGenerator
}

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

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