// 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_DomainTopicProperties_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 DomainTopicProperties_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDomainTopicProperties_STATUS, DomainTopicProperties_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual DomainTopicProperties_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 DomainTopicProperties_STATUS instances for property testing - lazily instantiated by
// DomainTopicProperties_STATUSGenerator()
var domainTopicProperties_STATUSGenerator gopter.Gen

// DomainTopicProperties_STATUSGenerator returns a generator of DomainTopicProperties_STATUS instances for property testing.
func DomainTopicProperties_STATUSGenerator() gopter.Gen {
	if domainTopicProperties_STATUSGenerator != nil {
		return domainTopicProperties_STATUSGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDomainTopicProperties_STATUS(generators)
	domainTopicProperties_STATUSGenerator = gen.Struct(reflect.TypeOf(DomainTopicProperties_STATUS{}), generators)

	return domainTopicProperties_STATUSGenerator
}

// AddIndependentPropertyGeneratorsForDomainTopicProperties_STATUS is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForDomainTopicProperties_STATUS(gens map[string]gopter.Gen) {
	gens["ProvisioningState"] = gen.PtrOf(gen.OneConstOf(
		DomainTopicProperties_ProvisioningState_STATUS_Canceled,
		DomainTopicProperties_ProvisioningState_STATUS_Creating,
		DomainTopicProperties_ProvisioningState_STATUS_Deleting,
		DomainTopicProperties_ProvisioningState_STATUS_Failed,
		DomainTopicProperties_ProvisioningState_STATUS_Succeeded,
		DomainTopicProperties_ProvisioningState_STATUS_Updating))
}

func Test_DomainsTopic_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 DomainsTopic_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDomainsTopic_STATUS, DomainsTopic_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual DomainsTopic_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 DomainsTopic_STATUS instances for property testing - lazily instantiated by
// DomainsTopic_STATUSGenerator()
var domainsTopic_STATUSGenerator gopter.Gen

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDomainsTopic_STATUS(generators)
	domainsTopic_STATUSGenerator = gen.Struct(reflect.TypeOf(DomainsTopic_STATUS{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDomainsTopic_STATUS(generators)
	AddRelatedPropertyGeneratorsForDomainsTopic_STATUS(generators)
	domainsTopic_STATUSGenerator = gen.Struct(reflect.TypeOf(DomainsTopic_STATUS{}), generators)

	return domainsTopic_STATUSGenerator
}

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

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