// 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_SubscriptionCreateParameterProperties_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 SubscriptionCreateParameterProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForSubscriptionCreateParameterProperties, SubscriptionCreateParameterPropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// SubscriptionCreateParameterPropertiesGenerator returns a generator of SubscriptionCreateParameterProperties instances for property testing.
func SubscriptionCreateParameterPropertiesGenerator() gopter.Gen {
	if subscriptionCreateParameterPropertiesGenerator != nil {
		return subscriptionCreateParameterPropertiesGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForSubscriptionCreateParameterProperties(generators)
	subscriptionCreateParameterPropertiesGenerator = gen.Struct(reflect.TypeOf(SubscriptionCreateParameterProperties{}), generators)

	return subscriptionCreateParameterPropertiesGenerator
}

// AddIndependentPropertyGeneratorsForSubscriptionCreateParameterProperties is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForSubscriptionCreateParameterProperties(gens map[string]gopter.Gen) {
	gens["AllowTracing"] = gen.PtrOf(gen.Bool())
	gens["DisplayName"] = gen.PtrOf(gen.AlphaString())
	gens["OwnerId"] = gen.PtrOf(gen.AlphaString())
	gens["PrimaryKey"] = gen.PtrOf(gen.AlphaString())
	gens["Scope"] = gen.PtrOf(gen.AlphaString())
	gens["SecondaryKey"] = gen.PtrOf(gen.AlphaString())
	gens["State"] = gen.PtrOf(gen.OneConstOf(
		SubscriptionCreateParameterProperties_State_Active,
		SubscriptionCreateParameterProperties_State_Cancelled,
		SubscriptionCreateParameterProperties_State_Expired,
		SubscriptionCreateParameterProperties_State_Rejected,
		SubscriptionCreateParameterProperties_State_Submitted,
		SubscriptionCreateParameterProperties_State_Suspended))
}

func Test_Subscription_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 Subscription_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForSubscription_Spec, Subscription_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual Subscription_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 Subscription_Spec instances for property testing - lazily instantiated by Subscription_SpecGenerator()
var subscription_SpecGenerator gopter.Gen

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForSubscription_Spec(generators)
	subscription_SpecGenerator = gen.Struct(reflect.TypeOf(Subscription_Spec{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForSubscription_Spec(generators)
	AddRelatedPropertyGeneratorsForSubscription_Spec(generators)
	subscription_SpecGenerator = gen.Struct(reflect.TypeOf(Subscription_Spec{}), generators)

	return subscription_SpecGenerator
}

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

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