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

import (
	"encoding/json"
	storage "github.com/Azure/azure-service-operator/v2/api/sql/v1api20211101/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_ServersAuditingSetting_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 ServersAuditingSetting to hub returns original",
		prop.ForAll(RunResourceConversionTestForServersAuditingSetting, ServersAuditingSettingGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

	// Convert from our hub version
	var actual ServersAuditingSetting
	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_ServersAuditingSetting_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from ServersAuditingSetting to ServersAuditingSetting via AssignProperties_To_ServersAuditingSetting & AssignProperties_From_ServersAuditingSetting returns original",
		prop.ForAll(RunPropertyAssignmentTestForServersAuditingSetting, ServersAuditingSettingGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

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

// ServersAuditingSettingGenerator returns a generator of ServersAuditingSetting instances for property testing.
func ServersAuditingSettingGenerator() gopter.Gen {
	if serversAuditingSettingGenerator != nil {
		return serversAuditingSettingGenerator
	}

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

	return serversAuditingSettingGenerator
}

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

func Test_ServersAuditingSettingOperatorSpec_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from ServersAuditingSettingOperatorSpec to ServersAuditingSettingOperatorSpec via AssignProperties_To_ServersAuditingSettingOperatorSpec & AssignProperties_From_ServersAuditingSettingOperatorSpec returns original",
		prop.ForAll(RunPropertyAssignmentTestForServersAuditingSettingOperatorSpec, ServersAuditingSettingOperatorSpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

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

// ServersAuditingSettingOperatorSpecGenerator returns a generator of ServersAuditingSettingOperatorSpec instances for property testing.
func ServersAuditingSettingOperatorSpecGenerator() gopter.Gen {
	if serversAuditingSettingOperatorSpecGenerator != nil {
		return serversAuditingSettingOperatorSpecGenerator
	}

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

	return serversAuditingSettingOperatorSpecGenerator
}

func Test_ServersAuditingSetting_STATUS_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from ServersAuditingSetting_STATUS to ServersAuditingSetting_STATUS via AssignProperties_To_ServersAuditingSetting_STATUS & AssignProperties_From_ServersAuditingSetting_STATUS returns original",
		prop.ForAll(RunPropertyAssignmentTestForServersAuditingSetting_STATUS, ServersAuditingSetting_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

	// Use AssignPropertiesFrom() to convert back to our original type
	var actual ServersAuditingSetting_STATUS
	err = actual.AssignProperties_From_ServersAuditingSetting_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_ServersAuditingSetting_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 ServersAuditingSetting_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForServersAuditingSetting_STATUS, ServersAuditingSetting_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual ServersAuditingSetting_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 ServersAuditingSetting_STATUS instances for property testing - lazily instantiated by
// ServersAuditingSetting_STATUSGenerator()
var serversAuditingSetting_STATUSGenerator gopter.Gen

// ServersAuditingSetting_STATUSGenerator returns a generator of ServersAuditingSetting_STATUS instances for property testing.
func ServersAuditingSetting_STATUSGenerator() gopter.Gen {
	if serversAuditingSetting_STATUSGenerator != nil {
		return serversAuditingSetting_STATUSGenerator
	}

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

	return serversAuditingSetting_STATUSGenerator
}

// AddIndependentPropertyGeneratorsForServersAuditingSetting_STATUS is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForServersAuditingSetting_STATUS(gens map[string]gopter.Gen) {
	gens["AuditActionsAndGroups"] = gen.SliceOf(gen.AlphaString())
	gens["Id"] = gen.PtrOf(gen.AlphaString())
	gens["IsAzureMonitorTargetEnabled"] = gen.PtrOf(gen.Bool())
	gens["IsDevopsAuditEnabled"] = gen.PtrOf(gen.Bool())
	gens["IsManagedIdentityInUse"] = gen.PtrOf(gen.Bool())
	gens["IsStorageSecondaryKeyInUse"] = gen.PtrOf(gen.Bool())
	gens["Name"] = gen.PtrOf(gen.AlphaString())
	gens["QueueDelayMs"] = gen.PtrOf(gen.Int())
	gens["RetentionDays"] = gen.PtrOf(gen.Int())
	gens["State"] = gen.PtrOf(gen.OneConstOf(ServerBlobAuditingPolicyProperties_State_STATUS_Disabled, ServerBlobAuditingPolicyProperties_State_STATUS_Enabled))
	gens["StorageAccountSubscriptionId"] = gen.PtrOf(gen.AlphaString())
	gens["StorageEndpoint"] = gen.PtrOf(gen.AlphaString())
	gens["Type"] = gen.PtrOf(gen.AlphaString())
}

func Test_ServersAuditingSetting_Spec_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from ServersAuditingSetting_Spec to ServersAuditingSetting_Spec via AssignProperties_To_ServersAuditingSetting_Spec & AssignProperties_From_ServersAuditingSetting_Spec returns original",
		prop.ForAll(RunPropertyAssignmentTestForServersAuditingSetting_Spec, ServersAuditingSetting_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

	// Use AssignPropertiesFrom() to convert back to our original type
	var actual ServersAuditingSetting_Spec
	err = actual.AssignProperties_From_ServersAuditingSetting_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_ServersAuditingSetting_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 ServersAuditingSetting_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForServersAuditingSetting_Spec, ServersAuditingSetting_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual ServersAuditingSetting_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 ServersAuditingSetting_Spec instances for property testing - lazily instantiated by
// ServersAuditingSetting_SpecGenerator()
var serversAuditingSetting_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForServersAuditingSetting_Spec(generators)
	AddRelatedPropertyGeneratorsForServersAuditingSetting_Spec(generators)
	serversAuditingSetting_SpecGenerator = gen.Struct(reflect.TypeOf(ServersAuditingSetting_Spec{}), generators)

	return serversAuditingSetting_SpecGenerator
}

// AddIndependentPropertyGeneratorsForServersAuditingSetting_Spec is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForServersAuditingSetting_Spec(gens map[string]gopter.Gen) {
	gens["AuditActionsAndGroups"] = gen.SliceOf(gen.AlphaString())
	gens["IsAzureMonitorTargetEnabled"] = gen.PtrOf(gen.Bool())
	gens["IsDevopsAuditEnabled"] = gen.PtrOf(gen.Bool())
	gens["IsManagedIdentityInUse"] = gen.PtrOf(gen.Bool())
	gens["IsStorageSecondaryKeyInUse"] = gen.PtrOf(gen.Bool())
	gens["QueueDelayMs"] = gen.PtrOf(gen.Int())
	gens["RetentionDays"] = gen.PtrOf(gen.Int())
	gens["State"] = gen.PtrOf(gen.OneConstOf(ServerBlobAuditingPolicyProperties_State_Disabled, ServerBlobAuditingPolicyProperties_State_Enabled))
	gens["StorageAccountSubscriptionId"] = gen.PtrOf(gen.AlphaString())
	gens["StorageEndpoint"] = gen.PtrOf(gen.AlphaString())
}

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