// 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_NamespacesTopic_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 NamespacesTopic_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForNamespacesTopic_Spec, NamespacesTopic_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual NamespacesTopic_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 NamespacesTopic_Spec instances for property testing - lazily instantiated by
// NamespacesTopic_SpecGenerator()
var namespacesTopic_SpecGenerator gopter.Gen

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForNamespacesTopic_Spec(generators)
	namespacesTopic_SpecGenerator = gen.Struct(reflect.TypeOf(NamespacesTopic_Spec{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForNamespacesTopic_Spec(generators)
	AddRelatedPropertyGeneratorsForNamespacesTopic_Spec(generators)
	namespacesTopic_SpecGenerator = gen.Struct(reflect.TypeOf(NamespacesTopic_Spec{}), generators)

	return namespacesTopic_SpecGenerator
}

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

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

func Test_SBTopicProperties_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 SBTopicProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForSBTopicProperties, SBTopicPropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// SBTopicPropertiesGenerator returns a generator of SBTopicProperties instances for property testing.
func SBTopicPropertiesGenerator() gopter.Gen {
	if sbTopicPropertiesGenerator != nil {
		return sbTopicPropertiesGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForSBTopicProperties(generators)
	sbTopicPropertiesGenerator = gen.Struct(reflect.TypeOf(SBTopicProperties{}), generators)

	return sbTopicPropertiesGenerator
}

// AddIndependentPropertyGeneratorsForSBTopicProperties is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForSBTopicProperties(gens map[string]gopter.Gen) {
	gens["AutoDeleteOnIdle"] = gen.PtrOf(gen.AlphaString())
	gens["DefaultMessageTimeToLive"] = gen.PtrOf(gen.AlphaString())
	gens["DuplicateDetectionHistoryTimeWindow"] = gen.PtrOf(gen.AlphaString())
	gens["EnableBatchedOperations"] = gen.PtrOf(gen.Bool())
	gens["EnableExpress"] = gen.PtrOf(gen.Bool())
	gens["EnablePartitioning"] = gen.PtrOf(gen.Bool())
	gens["MaxMessageSizeInKilobytes"] = gen.PtrOf(gen.Int())
	gens["MaxSizeInMegabytes"] = gen.PtrOf(gen.Int())
	gens["RequiresDuplicateDetection"] = gen.PtrOf(gen.Bool())
	gens["SupportOrdering"] = gen.PtrOf(gen.Bool())
}
