// 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_NamespacesTopicsSubscription_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 NamespacesTopicsSubscription_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForNamespacesTopicsSubscription_Spec, NamespacesTopicsSubscription_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual NamespacesTopicsSubscription_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 NamespacesTopicsSubscription_Spec instances for property testing - lazily instantiated by
// NamespacesTopicsSubscription_SpecGenerator()
var namespacesTopicsSubscription_SpecGenerator gopter.Gen

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForNamespacesTopicsSubscription_Spec(generators)
	namespacesTopicsSubscription_SpecGenerator = gen.Struct(reflect.TypeOf(NamespacesTopicsSubscription_Spec{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForNamespacesTopicsSubscription_Spec(generators)
	AddRelatedPropertyGeneratorsForNamespacesTopicsSubscription_Spec(generators)
	namespacesTopicsSubscription_SpecGenerator = gen.Struct(reflect.TypeOf(NamespacesTopicsSubscription_Spec{}), generators)

	return namespacesTopicsSubscription_SpecGenerator
}

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

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

func Test_SBClientAffineProperties_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 SBClientAffineProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForSBClientAffineProperties, SBClientAffinePropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// SBClientAffinePropertiesGenerator returns a generator of SBClientAffineProperties instances for property testing.
func SBClientAffinePropertiesGenerator() gopter.Gen {
	if sbClientAffinePropertiesGenerator != nil {
		return sbClientAffinePropertiesGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForSBClientAffineProperties(generators)
	sbClientAffinePropertiesGenerator = gen.Struct(reflect.TypeOf(SBClientAffineProperties{}), generators)

	return sbClientAffinePropertiesGenerator
}

// AddIndependentPropertyGeneratorsForSBClientAffineProperties is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForSBClientAffineProperties(gens map[string]gopter.Gen) {
	gens["ClientId"] = gen.PtrOf(gen.AlphaString())
	gens["IsDurable"] = gen.PtrOf(gen.Bool())
	gens["IsShared"] = gen.PtrOf(gen.Bool())
}

func Test_SBSubscriptionProperties_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 SBSubscriptionProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForSBSubscriptionProperties, SBSubscriptionPropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForSBSubscriptionProperties(generators)
	sbSubscriptionPropertiesGenerator = gen.Struct(reflect.TypeOf(SBSubscriptionProperties{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForSBSubscriptionProperties(generators)
	AddRelatedPropertyGeneratorsForSBSubscriptionProperties(generators)
	sbSubscriptionPropertiesGenerator = gen.Struct(reflect.TypeOf(SBSubscriptionProperties{}), generators)

	return sbSubscriptionPropertiesGenerator
}

// AddIndependentPropertyGeneratorsForSBSubscriptionProperties is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForSBSubscriptionProperties(gens map[string]gopter.Gen) {
	gens["AutoDeleteOnIdle"] = gen.PtrOf(gen.AlphaString())
	gens["DeadLetteringOnFilterEvaluationExceptions"] = gen.PtrOf(gen.Bool())
	gens["DeadLetteringOnMessageExpiration"] = gen.PtrOf(gen.Bool())
	gens["DefaultMessageTimeToLive"] = gen.PtrOf(gen.AlphaString())
	gens["DuplicateDetectionHistoryTimeWindow"] = gen.PtrOf(gen.AlphaString())
	gens["EnableBatchedOperations"] = gen.PtrOf(gen.Bool())
	gens["ForwardDeadLetteredMessagesTo"] = gen.PtrOf(gen.AlphaString())
	gens["ForwardTo"] = gen.PtrOf(gen.AlphaString())
	gens["IsClientAffine"] = gen.PtrOf(gen.Bool())
	gens["LockDuration"] = gen.PtrOf(gen.AlphaString())
	gens["MaxDeliveryCount"] = gen.PtrOf(gen.Int())
	gens["RequiresSession"] = gen.PtrOf(gen.Bool())
}

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