// 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_Route_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 Route via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForRoute, RouteGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForRoute(generators)
	routeGenerator = gen.Struct(reflect.TypeOf(Route{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForRoute(generators)
	AddRelatedPropertyGeneratorsForRoute(generators)
	routeGenerator = gen.Struct(reflect.TypeOf(Route{}), generators)

	return routeGenerator
}

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

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

func Test_RouteTablePropertiesFormat_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 RouteTablePropertiesFormat via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForRouteTablePropertiesFormat, RouteTablePropertiesFormatGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForRouteTablePropertiesFormat(generators)
	routeTablePropertiesFormatGenerator = gen.Struct(reflect.TypeOf(RouteTablePropertiesFormat{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForRouteTablePropertiesFormat(generators)
	AddRelatedPropertyGeneratorsForRouteTablePropertiesFormat(generators)
	routeTablePropertiesFormatGenerator = gen.Struct(reflect.TypeOf(RouteTablePropertiesFormat{}), generators)

	return routeTablePropertiesFormatGenerator
}

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

// AddRelatedPropertyGeneratorsForRouteTablePropertiesFormat is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForRouteTablePropertiesFormat(gens map[string]gopter.Gen) {
	gens["Routes"] = gen.SliceOf(RouteGenerator())
}

func Test_RouteTable_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 RouteTable_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForRouteTable_Spec, RouteTable_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual RouteTable_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 RouteTable_Spec instances for property testing - lazily instantiated by RouteTable_SpecGenerator()
var routeTable_SpecGenerator gopter.Gen

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForRouteTable_Spec(generators)
	routeTable_SpecGenerator = gen.Struct(reflect.TypeOf(RouteTable_Spec{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForRouteTable_Spec(generators)
	AddRelatedPropertyGeneratorsForRouteTable_Spec(generators)
	routeTable_SpecGenerator = gen.Struct(reflect.TypeOf(RouteTable_Spec{}), generators)

	return routeTable_SpecGenerator
}

// AddIndependentPropertyGeneratorsForRouteTable_Spec is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForRouteTable_Spec(gens map[string]gopter.Gen) {
	gens["Location"] = gen.PtrOf(gen.AlphaString())
	gens["Name"] = gen.AlphaString()
	gens["Tags"] = gen.MapOf(
		gen.AlphaString(),
		gen.AlphaString())
}

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