// 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_NatGatewayPropertiesFormat_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 NatGatewayPropertiesFormat via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForNatGatewayPropertiesFormat, NatGatewayPropertiesFormatGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForNatGatewayPropertiesFormat(generators)
	natGatewayPropertiesFormatGenerator = gen.Struct(reflect.TypeOf(NatGatewayPropertiesFormat{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForNatGatewayPropertiesFormat(generators)
	AddRelatedPropertyGeneratorsForNatGatewayPropertiesFormat(generators)
	natGatewayPropertiesFormatGenerator = gen.Struct(reflect.TypeOf(NatGatewayPropertiesFormat{}), generators)

	return natGatewayPropertiesFormatGenerator
}

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

// AddRelatedPropertyGeneratorsForNatGatewayPropertiesFormat is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForNatGatewayPropertiesFormat(gens map[string]gopter.Gen) {
	gens["PublicIpAddresses"] = gen.SliceOf(SubResourceGenerator())
	gens["PublicIpPrefixes"] = gen.SliceOf(SubResourceGenerator())
}

func Test_NatGatewaySku_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 NatGatewaySku via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForNatGatewaySku, NatGatewaySkuGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// NatGatewaySkuGenerator returns a generator of NatGatewaySku instances for property testing.
func NatGatewaySkuGenerator() gopter.Gen {
	if natGatewaySkuGenerator != nil {
		return natGatewaySkuGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForNatGatewaySku(generators)
	natGatewaySkuGenerator = gen.Struct(reflect.TypeOf(NatGatewaySku{}), generators)

	return natGatewaySkuGenerator
}

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

func Test_NatGateway_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 NatGateway_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForNatGateway_Spec, NatGateway_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual NatGateway_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 NatGateway_Spec instances for property testing - lazily instantiated by NatGateway_SpecGenerator()
var natGateway_SpecGenerator gopter.Gen

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForNatGateway_Spec(generators)
	natGateway_SpecGenerator = gen.Struct(reflect.TypeOf(NatGateway_Spec{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForNatGateway_Spec(generators)
	AddRelatedPropertyGeneratorsForNatGateway_Spec(generators)
	natGateway_SpecGenerator = gen.Struct(reflect.TypeOf(NatGateway_Spec{}), generators)

	return natGateway_SpecGenerator
}

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

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