// 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_ServersAdministrator_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 ServersAdministrator to hub returns original",
		prop.ForAll(RunResourceConversionTestForServersAdministrator, ServersAdministratorGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

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

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

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

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

// ServersAdministratorGenerator returns a generator of ServersAdministrator instances for property testing.
func ServersAdministratorGenerator() gopter.Gen {
	if serversAdministratorGenerator != nil {
		return serversAdministratorGenerator
	}

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

	return serversAdministratorGenerator
}

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

func Test_ServersAdministratorOperatorSpec_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from ServersAdministratorOperatorSpec to ServersAdministratorOperatorSpec via AssignProperties_To_ServersAdministratorOperatorSpec & AssignProperties_From_ServersAdministratorOperatorSpec returns original",
		prop.ForAll(RunPropertyAssignmentTestForServersAdministratorOperatorSpec, ServersAdministratorOperatorSpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

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

// ServersAdministratorOperatorSpecGenerator returns a generator of ServersAdministratorOperatorSpec instances for property testing.
func ServersAdministratorOperatorSpecGenerator() gopter.Gen {
	if serversAdministratorOperatorSpecGenerator != nil {
		return serversAdministratorOperatorSpecGenerator
	}

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

	return serversAdministratorOperatorSpecGenerator
}

func Test_ServersAdministrator_STATUS_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from ServersAdministrator_STATUS to ServersAdministrator_STATUS via AssignProperties_To_ServersAdministrator_STATUS & AssignProperties_From_ServersAdministrator_STATUS returns original",
		prop.ForAll(RunPropertyAssignmentTestForServersAdministrator_STATUS, ServersAdministrator_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

	// Deserialize back into memory
	var actual ServersAdministrator_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 ServersAdministrator_STATUS instances for property testing - lazily instantiated by
// ServersAdministrator_STATUSGenerator()
var serversAdministrator_STATUSGenerator gopter.Gen

// ServersAdministrator_STATUSGenerator returns a generator of ServersAdministrator_STATUS instances for property testing.
func ServersAdministrator_STATUSGenerator() gopter.Gen {
	if serversAdministrator_STATUSGenerator != nil {
		return serversAdministrator_STATUSGenerator
	}

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

	return serversAdministrator_STATUSGenerator
}

// AddIndependentPropertyGeneratorsForServersAdministrator_STATUS is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForServersAdministrator_STATUS(gens map[string]gopter.Gen) {
	gens["AdministratorType"] = gen.PtrOf(gen.OneConstOf(AdministratorProperties_AdministratorType_STATUS_ActiveDirectory))
	gens["AzureADOnlyAuthentication"] = gen.PtrOf(gen.Bool())
	gens["Id"] = gen.PtrOf(gen.AlphaString())
	gens["Login"] = gen.PtrOf(gen.AlphaString())
	gens["Name"] = gen.PtrOf(gen.AlphaString())
	gens["Sid"] = gen.PtrOf(gen.AlphaString())
	gens["TenantId"] = gen.PtrOf(gen.AlphaString())
	gens["Type"] = gen.PtrOf(gen.AlphaString())
}

func Test_ServersAdministrator_Spec_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from ServersAdministrator_Spec to ServersAdministrator_Spec via AssignProperties_To_ServersAdministrator_Spec & AssignProperties_From_ServersAdministrator_Spec returns original",
		prop.ForAll(RunPropertyAssignmentTestForServersAdministrator_Spec, ServersAdministrator_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

	// Deserialize back into memory
	var actual ServersAdministrator_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 ServersAdministrator_Spec instances for property testing - lazily instantiated by
// ServersAdministrator_SpecGenerator()
var serversAdministrator_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForServersAdministrator_Spec(generators)
	AddRelatedPropertyGeneratorsForServersAdministrator_Spec(generators)
	serversAdministrator_SpecGenerator = gen.Struct(reflect.TypeOf(ServersAdministrator_Spec{}), generators)

	return serversAdministrator_SpecGenerator
}

// AddIndependentPropertyGeneratorsForServersAdministrator_Spec is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForServersAdministrator_Spec(gens map[string]gopter.Gen) {
	gens["AdministratorType"] = gen.PtrOf(gen.OneConstOf(AdministratorProperties_AdministratorType_ActiveDirectory))
	gens["Login"] = gen.PtrOf(gen.AlphaString())
	gens["Sid"] = gen.PtrOf(gen.AlphaString())
	gens["TenantId"] = gen.PtrOf(gen.AlphaString())
}

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