// 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_NetworkWatcherPropertiesFormat_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 NetworkWatcherPropertiesFormat_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForNetworkWatcherPropertiesFormat_STATUS, NetworkWatcherPropertiesFormat_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual NetworkWatcherPropertiesFormat_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 NetworkWatcherPropertiesFormat_STATUS instances for property testing - lazily instantiated by
// NetworkWatcherPropertiesFormat_STATUSGenerator()
var networkWatcherPropertiesFormat_STATUSGenerator gopter.Gen

// NetworkWatcherPropertiesFormat_STATUSGenerator returns a generator of NetworkWatcherPropertiesFormat_STATUS instances for property testing.
func NetworkWatcherPropertiesFormat_STATUSGenerator() gopter.Gen {
	if networkWatcherPropertiesFormat_STATUSGenerator != nil {
		return networkWatcherPropertiesFormat_STATUSGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForNetworkWatcherPropertiesFormat_STATUS(generators)
	networkWatcherPropertiesFormat_STATUSGenerator = gen.Struct(reflect.TypeOf(NetworkWatcherPropertiesFormat_STATUS{}), generators)

	return networkWatcherPropertiesFormat_STATUSGenerator
}

// AddIndependentPropertyGeneratorsForNetworkWatcherPropertiesFormat_STATUS is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForNetworkWatcherPropertiesFormat_STATUS(gens map[string]gopter.Gen) {
	gens["ProvisioningState"] = gen.PtrOf(gen.OneConstOf(
		NetworkWatcherProvisioningState_STATUS_Deleting,
		NetworkWatcherProvisioningState_STATUS_Failed,
		NetworkWatcherProvisioningState_STATUS_Succeeded,
		NetworkWatcherProvisioningState_STATUS_Updating))
}

func Test_NetworkWatcher_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 NetworkWatcher_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForNetworkWatcher_STATUS, NetworkWatcher_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual NetworkWatcher_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 NetworkWatcher_STATUS instances for property testing - lazily instantiated by
// NetworkWatcher_STATUSGenerator()
var networkWatcher_STATUSGenerator gopter.Gen

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForNetworkWatcher_STATUS(generators)
	networkWatcher_STATUSGenerator = gen.Struct(reflect.TypeOf(NetworkWatcher_STATUS{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForNetworkWatcher_STATUS(generators)
	AddRelatedPropertyGeneratorsForNetworkWatcher_STATUS(generators)
	networkWatcher_STATUSGenerator = gen.Struct(reflect.TypeOf(NetworkWatcher_STATUS{}), generators)

	return networkWatcher_STATUSGenerator
}

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

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