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

import (
	"encoding/json"
	storage "github.com/Azure/azure-service-operator/v2/api/containerservice/v1api20240901/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_AdvancedNetworking_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from AdvancedNetworking to AdvancedNetworking via AssignProperties_To_AdvancedNetworking & AssignProperties_From_AdvancedNetworking returns original",
		prop.ForAll(RunPropertyAssignmentTestForAdvancedNetworking, AdvancedNetworkingGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

// RunPropertyAssignmentTestForAdvancedNetworking tests if a specific instance of AdvancedNetworking can be assigned to storage and back losslessly
func RunPropertyAssignmentTestForAdvancedNetworking(subject AdvancedNetworking) 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.AdvancedNetworking
	err := copied.AssignProperties_To_AdvancedNetworking(&other)
	if err != nil {
		return err.Error()
	}

	// Use AssignPropertiesFrom() to convert back to our original type
	var actual AdvancedNetworking
	err = actual.AssignProperties_From_AdvancedNetworking(&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_AdvancedNetworking_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 AdvancedNetworking via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForAdvancedNetworking, AdvancedNetworkingGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// AdvancedNetworkingGenerator returns a generator of AdvancedNetworking instances for property testing.
func AdvancedNetworkingGenerator() gopter.Gen {
	if advancedNetworkingGenerator != nil {
		return advancedNetworkingGenerator
	}

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

	return advancedNetworkingGenerator
}

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

func Test_AdvancedNetworkingObservability_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from AdvancedNetworkingObservability to AdvancedNetworkingObservability via AssignProperties_To_AdvancedNetworkingObservability & AssignProperties_From_AdvancedNetworkingObservability returns original",
		prop.ForAll(RunPropertyAssignmentTestForAdvancedNetworkingObservability, AdvancedNetworkingObservabilityGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

// RunPropertyAssignmentTestForAdvancedNetworkingObservability tests if a specific instance of AdvancedNetworkingObservability can be assigned to storage and back losslessly
func RunPropertyAssignmentTestForAdvancedNetworkingObservability(subject AdvancedNetworkingObservability) 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.AdvancedNetworkingObservability
	err := copied.AssignProperties_To_AdvancedNetworkingObservability(&other)
	if err != nil {
		return err.Error()
	}

	// Use AssignPropertiesFrom() to convert back to our original type
	var actual AdvancedNetworkingObservability
	err = actual.AssignProperties_From_AdvancedNetworkingObservability(&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_AdvancedNetworkingObservability_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 AdvancedNetworkingObservability via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForAdvancedNetworkingObservability, AdvancedNetworkingObservabilityGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// AdvancedNetworkingObservabilityGenerator returns a generator of AdvancedNetworkingObservability instances for property testing.
func AdvancedNetworkingObservabilityGenerator() gopter.Gen {
	if advancedNetworkingObservabilityGenerator != nil {
		return advancedNetworkingObservabilityGenerator
	}

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

	return advancedNetworkingObservabilityGenerator
}

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