// 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_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 ApiVersionSetContractProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForApiVersionSetContractProperties, ApiVersionSetContractPropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// ApiVersionSetContractPropertiesGenerator returns a generator of ApiVersionSetContractProperties instances for property testing.
func ApiVersionSetContractPropertiesGenerator() gopter.Gen {
	if apiVersionSetContractPropertiesGenerator != nil {
		return apiVersionSetContractPropertiesGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForApiVersionSetContractProperties(generators)
	apiVersionSetContractPropertiesGenerator = gen.Struct(reflect.TypeOf(ApiVersionSetContractProperties{}), generators)

	return apiVersionSetContractPropertiesGenerator
}

// AddIndependentPropertyGeneratorsForApiVersionSetContractProperties is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForApiVersionSetContractProperties(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_Header, ApiVersionSetContractProperties_VersioningScheme_Query, ApiVersionSetContractProperties_VersioningScheme_Segment))
}

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

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

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

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForApiVersionSet_Spec(generators)
	apiVersionSet_SpecGenerator = gen.Struct(reflect.TypeOf(ApiVersionSet_Spec{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForApiVersionSet_Spec(generators)
	AddRelatedPropertyGeneratorsForApiVersionSet_Spec(generators)
	apiVersionSet_SpecGenerator = gen.Struct(reflect.TypeOf(ApiVersionSet_Spec{}), generators)

	return apiVersionSet_SpecGenerator
}

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

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