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

import (
	"encoding/json"
	storage "github.com/Azure/azure-service-operator/v2/api/documentdb/v1api20240815/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_MongodbUserDefinition_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 MongodbUserDefinition to hub returns original",
		prop.ForAll(RunResourceConversionTestForMongodbUserDefinition, MongodbUserDefinitionGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

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

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

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

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

// MongodbUserDefinitionGenerator returns a generator of MongodbUserDefinition instances for property testing.
func MongodbUserDefinitionGenerator() gopter.Gen {
	if mongodbUserDefinitionGenerator != nil {
		return mongodbUserDefinitionGenerator
	}

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

	return mongodbUserDefinitionGenerator
}

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

func Test_MongodbUserDefinitionOperatorSpec_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from MongodbUserDefinitionOperatorSpec to MongodbUserDefinitionOperatorSpec via AssignProperties_To_MongodbUserDefinitionOperatorSpec & AssignProperties_From_MongodbUserDefinitionOperatorSpec returns original",
		prop.ForAll(RunPropertyAssignmentTestForMongodbUserDefinitionOperatorSpec, MongodbUserDefinitionOperatorSpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

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

// MongodbUserDefinitionOperatorSpecGenerator returns a generator of MongodbUserDefinitionOperatorSpec instances for property testing.
func MongodbUserDefinitionOperatorSpecGenerator() gopter.Gen {
	if mongodbUserDefinitionOperatorSpecGenerator != nil {
		return mongodbUserDefinitionOperatorSpecGenerator
	}

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

	return mongodbUserDefinitionOperatorSpecGenerator
}

func Test_MongodbUserDefinition_STATUS_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from MongodbUserDefinition_STATUS to MongodbUserDefinition_STATUS via AssignProperties_To_MongodbUserDefinition_STATUS & AssignProperties_From_MongodbUserDefinition_STATUS returns original",
		prop.ForAll(RunPropertyAssignmentTestForMongodbUserDefinition_STATUS, MongodbUserDefinition_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

	// Deserialize back into memory
	var actual MongodbUserDefinition_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 MongodbUserDefinition_STATUS instances for property testing - lazily instantiated by
// MongodbUserDefinition_STATUSGenerator()
var mongodbUserDefinition_STATUSGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForMongodbUserDefinition_STATUS(generators)
	AddRelatedPropertyGeneratorsForMongodbUserDefinition_STATUS(generators)
	mongodbUserDefinition_STATUSGenerator = gen.Struct(reflect.TypeOf(MongodbUserDefinition_STATUS{}), generators)

	return mongodbUserDefinition_STATUSGenerator
}

// AddIndependentPropertyGeneratorsForMongodbUserDefinition_STATUS is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForMongodbUserDefinition_STATUS(gens map[string]gopter.Gen) {
	gens["CustomData"] = gen.PtrOf(gen.AlphaString())
	gens["DatabaseName"] = gen.PtrOf(gen.AlphaString())
	gens["Id"] = gen.PtrOf(gen.AlphaString())
	gens["Mechanisms"] = gen.PtrOf(gen.AlphaString())
	gens["Name"] = gen.PtrOf(gen.AlphaString())
	gens["Type"] = gen.PtrOf(gen.AlphaString())
	gens["UserName"] = gen.PtrOf(gen.AlphaString())
}

// AddRelatedPropertyGeneratorsForMongodbUserDefinition_STATUS is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForMongodbUserDefinition_STATUS(gens map[string]gopter.Gen) {
	gens["Roles"] = gen.SliceOf(Role_STATUSGenerator())
}

func Test_MongodbUserDefinition_Spec_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from MongodbUserDefinition_Spec to MongodbUserDefinition_Spec via AssignProperties_To_MongodbUserDefinition_Spec & AssignProperties_From_MongodbUserDefinition_Spec returns original",
		prop.ForAll(RunPropertyAssignmentTestForMongodbUserDefinition_Spec, MongodbUserDefinition_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

	// Deserialize back into memory
	var actual MongodbUserDefinition_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 MongodbUserDefinition_Spec instances for property testing - lazily instantiated by
// MongodbUserDefinition_SpecGenerator()
var mongodbUserDefinition_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForMongodbUserDefinition_Spec(generators)
	AddRelatedPropertyGeneratorsForMongodbUserDefinition_Spec(generators)
	mongodbUserDefinition_SpecGenerator = gen.Struct(reflect.TypeOf(MongodbUserDefinition_Spec{}), generators)

	return mongodbUserDefinition_SpecGenerator
}

// AddIndependentPropertyGeneratorsForMongodbUserDefinition_Spec is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForMongodbUserDefinition_Spec(gens map[string]gopter.Gen) {
	gens["AzureName"] = gen.AlphaString()
	gens["CustomData"] = gen.PtrOf(gen.AlphaString())
	gens["DatabaseName"] = gen.PtrOf(gen.AlphaString())
	gens["Mechanisms"] = gen.PtrOf(gen.AlphaString())
	gens["UserName"] = gen.PtrOf(gen.AlphaString())
}

// AddRelatedPropertyGeneratorsForMongodbUserDefinition_Spec is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForMongodbUserDefinition_Spec(gens map[string]gopter.Gen) {
	gens["OperatorSpec"] = gen.PtrOf(MongodbUserDefinitionOperatorSpecGenerator())
	gens["Roles"] = gen.SliceOf(RoleGenerator())
}
