// 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_PricingPlanProperties_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 PricingPlanProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForPricingPlanProperties, PricingPlanPropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// PricingPlanPropertiesGenerator returns a generator of PricingPlanProperties instances for property testing.
func PricingPlanPropertiesGenerator() gopter.Gen {
	if pricingPlanPropertiesGenerator != nil {
		return pricingPlanPropertiesGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForPricingPlanProperties(generators)
	pricingPlanPropertiesGenerator = gen.Struct(reflect.TypeOf(PricingPlanProperties{}), generators)

	return pricingPlanPropertiesGenerator
}

// AddIndependentPropertyGeneratorsForPricingPlanProperties is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForPricingPlanProperties(gens map[string]gopter.Gen) {
	gens["Cap"] = gen.PtrOf(gen.Float64())
	gens["PlanType"] = gen.PtrOf(gen.AlphaString())
	gens["StopSendNotificationWhenHitCap"] = gen.PtrOf(gen.Bool())
	gens["StopSendNotificationWhenHitThreshold"] = gen.PtrOf(gen.Bool())
	gens["WarningThreshold"] = gen.PtrOf(gen.Int())
}

func Test_PricingPlan_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 PricingPlan_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForPricingPlan_Spec, PricingPlan_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual PricingPlan_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 PricingPlan_Spec instances for property testing - lazily instantiated by PricingPlan_SpecGenerator()
var pricingPlan_SpecGenerator gopter.Gen

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForPricingPlan_Spec(generators)
	pricingPlan_SpecGenerator = gen.Struct(reflect.TypeOf(PricingPlan_Spec{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForPricingPlan_Spec(generators)
	AddRelatedPropertyGeneratorsForPricingPlan_Spec(generators)
	pricingPlan_SpecGenerator = gen.Struct(reflect.TypeOf(PricingPlan_Spec{}), generators)

	return pricingPlan_SpecGenerator
}

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

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