// Code generated by azure-service-operator-codegen. DO NOT EDIT.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package v1api20241001

import (
	"encoding/json"
	storage "github.com/Azure/azure-service-operator/v2/api/network/v1api20241001/storage"
	"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_NetworkWatcher_WhenConvertedToHub_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	parameters.MinSuccessfulTests = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from NetworkWatcher to hub returns original",
		prop.ForAll(RunResourceConversionTestForNetworkWatcher, NetworkWatcherGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

// RunResourceConversionTestForNetworkWatcher tests if a specific instance of NetworkWatcher round trips to the hub storage version and back losslessly
func RunResourceConversionTestForNetworkWatcher(subject NetworkWatcher) string {
	// Copy subject to make sure conversion doesn't modify it
	copied := subject.DeepCopy()

	// Convert to our hub version
	var hub storage.NetworkWatcher
	err := copied.ConvertTo(&hub)
	if err != nil {
		return err.Error()
	}

	// Convert from our hub version
	var actual NetworkWatcher
	err = actual.ConvertFrom(&hub)
	if err != nil {
		return err.Error()
	}

	// Compare actual with what we started with
	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 ""
}

func Test_NetworkWatcher_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from NetworkWatcher to NetworkWatcher via AssignProperties_To_NetworkWatcher & AssignProperties_From_NetworkWatcher returns original",
		prop.ForAll(RunPropertyAssignmentTestForNetworkWatcher, NetworkWatcherGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

// RunPropertyAssignmentTestForNetworkWatcher tests if a specific instance of NetworkWatcher can be assigned to storage and back losslessly
func RunPropertyAssignmentTestForNetworkWatcher(subject NetworkWatcher) string {
	// Copy subject to make sure assignment doesn't modify it
	copied := subject.DeepCopy()

	// Use AssignPropertiesTo() for the first stage of conversion
	var other storage.NetworkWatcher
	err := copied.AssignProperties_To_NetworkWatcher(&other)
	if err != nil {
		return err.Error()
	}

	// Use AssignPropertiesFrom() to convert back to our original type
	var actual NetworkWatcher
	err = actual.AssignProperties_From_NetworkWatcher(&other)
	if err != nil {
		return err.Error()
	}

	// Check for a match
	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 ""
}

func Test_NetworkWatcher_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MinSuccessfulTests = 20
	parameters.MaxSize = 3
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip of NetworkWatcher via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForNetworkWatcher, NetworkWatcherGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// NetworkWatcherGenerator returns a generator of NetworkWatcher instances for property testing.
func NetworkWatcherGenerator() gopter.Gen {
	if networkWatcherGenerator != nil {
		return networkWatcherGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddRelatedPropertyGeneratorsForNetworkWatcher(generators)
	networkWatcherGenerator = gen.Struct(reflect.TypeOf(NetworkWatcher{}), generators)

	return networkWatcherGenerator
}

// AddRelatedPropertyGeneratorsForNetworkWatcher is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForNetworkWatcher(gens map[string]gopter.Gen) {
	gens["Spec"] = NetworkWatcher_SpecGenerator()
	gens["Status"] = NetworkWatcher_STATUSGenerator()
}

func Test_NetworkWatcherOperatorSpec_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from NetworkWatcherOperatorSpec to NetworkWatcherOperatorSpec via AssignProperties_To_NetworkWatcherOperatorSpec & AssignProperties_From_NetworkWatcherOperatorSpec returns original",
		prop.ForAll(RunPropertyAssignmentTestForNetworkWatcherOperatorSpec, NetworkWatcherOperatorSpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

// RunPropertyAssignmentTestForNetworkWatcherOperatorSpec tests if a specific instance of NetworkWatcherOperatorSpec can be assigned to storage and back losslessly
func RunPropertyAssignmentTestForNetworkWatcherOperatorSpec(subject NetworkWatcherOperatorSpec) string {
	// Copy subject to make sure assignment doesn't modify it
	copied := subject.DeepCopy()

	// Use AssignPropertiesTo() for the first stage of conversion
	var other storage.NetworkWatcherOperatorSpec
	err := copied.AssignProperties_To_NetworkWatcherOperatorSpec(&other)
	if err != nil {
		return err.Error()
	}

	// Use AssignPropertiesFrom() to convert back to our original type
	var actual NetworkWatcherOperatorSpec
	err = actual.AssignProperties_From_NetworkWatcherOperatorSpec(&other)
	if err != nil {
		return err.Error()
	}

	// Check for a match
	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 ""
}

func Test_NetworkWatcherOperatorSpec_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 NetworkWatcherOperatorSpec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForNetworkWatcherOperatorSpec, NetworkWatcherOperatorSpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// NetworkWatcherOperatorSpecGenerator returns a generator of NetworkWatcherOperatorSpec instances for property testing.
func NetworkWatcherOperatorSpecGenerator() gopter.Gen {
	if networkWatcherOperatorSpecGenerator != nil {
		return networkWatcherOperatorSpecGenerator
	}

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

	return networkWatcherOperatorSpecGenerator
}

func Test_NetworkWatcher_STATUS_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from NetworkWatcher_STATUS to NetworkWatcher_STATUS via AssignProperties_To_NetworkWatcher_STATUS & AssignProperties_From_NetworkWatcher_STATUS returns original",
		prop.ForAll(RunPropertyAssignmentTestForNetworkWatcher_STATUS, NetworkWatcher_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

// RunPropertyAssignmentTestForNetworkWatcher_STATUS tests if a specific instance of NetworkWatcher_STATUS can be assigned to storage and back losslessly
func RunPropertyAssignmentTestForNetworkWatcher_STATUS(subject NetworkWatcher_STATUS) string {
	// Copy subject to make sure assignment doesn't modify it
	copied := subject.DeepCopy()

	// Use AssignPropertiesTo() for the first stage of conversion
	var other storage.NetworkWatcher_STATUS
	err := copied.AssignProperties_To_NetworkWatcher_STATUS(&other)
	if err != nil {
		return err.Error()
	}

	// Use AssignPropertiesFrom() to convert back to our original type
	var actual NetworkWatcher_STATUS
	err = actual.AssignProperties_From_NetworkWatcher_STATUS(&other)
	if err != nil {
		return err.Error()
	}

	// Check for a match
	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 ""
}

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.
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)

	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["ProvisioningState"] = gen.PtrOf(gen.OneConstOf(
		NetworkWatcherProvisioningState_STATUS_Deleting,
		NetworkWatcherProvisioningState_STATUS_Failed,
		NetworkWatcherProvisioningState_STATUS_Succeeded,
		NetworkWatcherProvisioningState_STATUS_Updating))
	gens["Tags"] = gen.MapOf(
		gen.AlphaString(),
		gen.AlphaString())
	gens["Type"] = gen.PtrOf(gen.AlphaString())
}

func Test_NetworkWatcher_Spec_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from NetworkWatcher_Spec to NetworkWatcher_Spec via AssignProperties_To_NetworkWatcher_Spec & AssignProperties_From_NetworkWatcher_Spec returns original",
		prop.ForAll(RunPropertyAssignmentTestForNetworkWatcher_Spec, NetworkWatcher_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

// RunPropertyAssignmentTestForNetworkWatcher_Spec tests if a specific instance of NetworkWatcher_Spec can be assigned to storage and back losslessly
func RunPropertyAssignmentTestForNetworkWatcher_Spec(subject NetworkWatcher_Spec) string {
	// Copy subject to make sure assignment doesn't modify it
	copied := subject.DeepCopy()

	// Use AssignPropertiesTo() for the first stage of conversion
	var other storage.NetworkWatcher_Spec
	err := copied.AssignProperties_To_NetworkWatcher_Spec(&other)
	if err != nil {
		return err.Error()
	}

	// Use AssignPropertiesFrom() to convert back to our original type
	var actual NetworkWatcher_Spec
	err = actual.AssignProperties_From_NetworkWatcher_Spec(&other)
	if err != nil {
		return err.Error()
	}

	// Check for a match
	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 ""
}

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

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

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

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForNetworkWatcher_Spec(generators)
	networkWatcher_SpecGenerator = gen.Struct(reflect.TypeOf(NetworkWatcher_Spec{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForNetworkWatcher_Spec(generators)
	AddRelatedPropertyGeneratorsForNetworkWatcher_Spec(generators)
	networkWatcher_SpecGenerator = gen.Struct(reflect.TypeOf(NetworkWatcher_Spec{}), generators)

	return networkWatcher_SpecGenerator
}

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

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