// 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_SubscriptionContractProperties_STATUS_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 SubscriptionContractProperties_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForSubscriptionContractProperties_STATUS, SubscriptionContractProperties_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// SubscriptionContractProperties_STATUSGenerator returns a generator of SubscriptionContractProperties_STATUS instances for property testing.
func SubscriptionContractProperties_STATUSGenerator() gopter.Gen {
	if subscriptionContractProperties_STATUSGenerator != nil {
		return subscriptionContractProperties_STATUSGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForSubscriptionContractProperties_STATUS(generators)
	subscriptionContractProperties_STATUSGenerator = gen.Struct(reflect.TypeOf(SubscriptionContractProperties_STATUS{}), generators)

	return subscriptionContractProperties_STATUSGenerator
}

// AddIndependentPropertyGeneratorsForSubscriptionContractProperties_STATUS is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForSubscriptionContractProperties_STATUS(gens map[string]gopter.Gen) {
	gens["AllowTracing"] = gen.PtrOf(gen.Bool())
	gens["CreatedDate"] = gen.PtrOf(gen.AlphaString())
	gens["DisplayName"] = gen.PtrOf(gen.AlphaString())
	gens["EndDate"] = gen.PtrOf(gen.AlphaString())
	gens["ExpirationDate"] = gen.PtrOf(gen.AlphaString())
	gens["NotificationDate"] = gen.PtrOf(gen.AlphaString())
	gens["OwnerId"] = gen.PtrOf(gen.AlphaString())
	gens["Scope"] = gen.PtrOf(gen.AlphaString())
	gens["StartDate"] = gen.PtrOf(gen.AlphaString())
	gens["State"] = gen.PtrOf(gen.OneConstOf(
		SubscriptionContractProperties_State_STATUS_Active,
		SubscriptionContractProperties_State_STATUS_Cancelled,
		SubscriptionContractProperties_State_STATUS_Expired,
		SubscriptionContractProperties_State_STATUS_Rejected,
		SubscriptionContractProperties_State_STATUS_Submitted,
		SubscriptionContractProperties_State_STATUS_Suspended))
	gens["StateComment"] = gen.PtrOf(gen.AlphaString())
}

func Test_Subscription_STATUS_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_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForSubscription_STATUS, Subscription_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual Subscription_STATUS
	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_STATUS instances for property testing - lazily instantiated by
// Subscription_STATUSGenerator()
var subscription_STATUSGenerator gopter.Gen

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForSubscription_STATUS(generators)
	subscription_STATUSGenerator = gen.Struct(reflect.TypeOf(Subscription_STATUS{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForSubscription_STATUS(generators)
	AddRelatedPropertyGeneratorsForSubscription_STATUS(generators)
	subscription_STATUSGenerator = gen.Struct(reflect.TypeOf(Subscription_STATUS{}), generators)

	return subscription_STATUSGenerator
}

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

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