// 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_ApiVersionSetContractProperties_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 ApiVersionSetContractProperties_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForApiVersionSetContractProperties_STATUS, ApiVersionSetContractProperties_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual ApiVersionSetContractProperties_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 ApiVersionSetContractProperties_STATUS instances for property testing - lazily instantiated by
// ApiVersionSetContractProperties_STATUSGenerator()
var apiVersionSetContractProperties_STATUSGenerator gopter.Gen

// ApiVersionSetContractProperties_STATUSGenerator returns a generator of ApiVersionSetContractProperties_STATUS instances for property testing.
func ApiVersionSetContractProperties_STATUSGenerator() gopter.Gen {
	if apiVersionSetContractProperties_STATUSGenerator != nil {
		return apiVersionSetContractProperties_STATUSGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForApiVersionSetContractProperties_STATUS(generators)
	apiVersionSetContractProperties_STATUSGenerator = gen.Struct(reflect.TypeOf(ApiVersionSetContractProperties_STATUS{}), generators)

	return apiVersionSetContractProperties_STATUSGenerator
}

// AddIndependentPropertyGeneratorsForApiVersionSetContractProperties_STATUS is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForApiVersionSetContractProperties_STATUS(gens map[string]gopter.Gen) {
	gens["Description"] = gen.PtrOf(gen.AlphaString())
	gens["DisplayName"] = gen.PtrOf(gen.AlphaString())
	gens["VersionHeaderName"] = gen.PtrOf(gen.AlphaString())
	gens["VersionQueryName"] = gen.PtrOf(gen.AlphaString())
	gens["VersioningScheme"] = gen.PtrOf(gen.OneConstOf(ApiVersionSetContractProperties_VersioningScheme_STATUS_Header, ApiVersionSetContractProperties_VersioningScheme_STATUS_Query, ApiVersionSetContractProperties_VersioningScheme_STATUS_Segment))
}

func Test_ApiVersionSet_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 ApiVersionSet_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForApiVersionSet_STATUS, ApiVersionSet_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual ApiVersionSet_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 ApiVersionSet_STATUS instances for property testing - lazily instantiated by
// ApiVersionSet_STATUSGenerator()
var apiVersionSet_STATUSGenerator gopter.Gen

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForApiVersionSet_STATUS(generators)
	apiVersionSet_STATUSGenerator = gen.Struct(reflect.TypeOf(ApiVersionSet_STATUS{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForApiVersionSet_STATUS(generators)
	AddRelatedPropertyGeneratorsForApiVersionSet_STATUS(generators)
	apiVersionSet_STATUSGenerator = gen.Struct(reflect.TypeOf(ApiVersionSet_STATUS{}), generators)

	return apiVersionSet_STATUSGenerator
}

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

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