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

import (
	"encoding/json"
	storage "github.com/Azure/azure-service-operator/v2/api/kusto/v1api20240413/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_PrincipalAssignment_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 PrincipalAssignment to hub returns original",
		prop.ForAll(RunResourceConversionTestForPrincipalAssignment, PrincipalAssignmentGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

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

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

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

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

// PrincipalAssignmentGenerator returns a generator of PrincipalAssignment instances for property testing.
func PrincipalAssignmentGenerator() gopter.Gen {
	if principalAssignmentGenerator != nil {
		return principalAssignmentGenerator
	}

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

	return principalAssignmentGenerator
}

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

func Test_PrincipalAssignmentOperatorSpec_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from PrincipalAssignmentOperatorSpec to PrincipalAssignmentOperatorSpec via AssignProperties_To_PrincipalAssignmentOperatorSpec & AssignProperties_From_PrincipalAssignmentOperatorSpec returns original",
		prop.ForAll(RunPropertyAssignmentTestForPrincipalAssignmentOperatorSpec, PrincipalAssignmentOperatorSpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

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

// PrincipalAssignmentOperatorSpecGenerator returns a generator of PrincipalAssignmentOperatorSpec instances for property testing.
func PrincipalAssignmentOperatorSpecGenerator() gopter.Gen {
	if principalAssignmentOperatorSpecGenerator != nil {
		return principalAssignmentOperatorSpecGenerator
	}

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

	return principalAssignmentOperatorSpecGenerator
}

func Test_PrincipalAssignment_STATUS_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from PrincipalAssignment_STATUS to PrincipalAssignment_STATUS via AssignProperties_To_PrincipalAssignment_STATUS & AssignProperties_From_PrincipalAssignment_STATUS returns original",
		prop.ForAll(RunPropertyAssignmentTestForPrincipalAssignment_STATUS, PrincipalAssignment_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

	// Deserialize back into memory
	var actual PrincipalAssignment_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 PrincipalAssignment_STATUS instances for property testing - lazily instantiated by
// PrincipalAssignment_STATUSGenerator()
var principalAssignment_STATUSGenerator gopter.Gen

// PrincipalAssignment_STATUSGenerator returns a generator of PrincipalAssignment_STATUS instances for property testing.
func PrincipalAssignment_STATUSGenerator() gopter.Gen {
	if principalAssignment_STATUSGenerator != nil {
		return principalAssignment_STATUSGenerator
	}

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

	return principalAssignment_STATUSGenerator
}

// AddIndependentPropertyGeneratorsForPrincipalAssignment_STATUS is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForPrincipalAssignment_STATUS(gens map[string]gopter.Gen) {
	gens["AadObjectId"] = gen.PtrOf(gen.AlphaString())
	gens["Id"] = gen.PtrOf(gen.AlphaString())
	gens["Name"] = gen.PtrOf(gen.AlphaString())
	gens["PrincipalId"] = gen.PtrOf(gen.AlphaString())
	gens["PrincipalName"] = gen.PtrOf(gen.AlphaString())
	gens["PrincipalType"] = gen.PtrOf(gen.OneConstOf(DatabasePrincipalProperties_PrincipalType_STATUS_App, DatabasePrincipalProperties_PrincipalType_STATUS_Group, DatabasePrincipalProperties_PrincipalType_STATUS_User))
	gens["ProvisioningState"] = gen.PtrOf(gen.OneConstOf(
		ProvisioningState_STATUS_Canceled,
		ProvisioningState_STATUS_Creating,
		ProvisioningState_STATUS_Deleting,
		ProvisioningState_STATUS_Failed,
		ProvisioningState_STATUS_Moving,
		ProvisioningState_STATUS_Running,
		ProvisioningState_STATUS_Succeeded))
	gens["Role"] = gen.PtrOf(gen.OneConstOf(
		DatabasePrincipalProperties_Role_STATUS_Admin,
		DatabasePrincipalProperties_Role_STATUS_Ingestor,
		DatabasePrincipalProperties_Role_STATUS_Monitor,
		DatabasePrincipalProperties_Role_STATUS_UnrestrictedViewer,
		DatabasePrincipalProperties_Role_STATUS_User,
		DatabasePrincipalProperties_Role_STATUS_Viewer))
	gens["TenantId"] = gen.PtrOf(gen.AlphaString())
	gens["TenantName"] = gen.PtrOf(gen.AlphaString())
	gens["Type"] = gen.PtrOf(gen.AlphaString())
}

func Test_PrincipalAssignment_Spec_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from PrincipalAssignment_Spec to PrincipalAssignment_Spec via AssignProperties_To_PrincipalAssignment_Spec & AssignProperties_From_PrincipalAssignment_Spec returns original",
		prop.ForAll(RunPropertyAssignmentTestForPrincipalAssignment_Spec, PrincipalAssignment_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

	// Deserialize back into memory
	var actual PrincipalAssignment_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 PrincipalAssignment_Spec instances for property testing - lazily instantiated by
// PrincipalAssignment_SpecGenerator()
var principalAssignment_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForPrincipalAssignment_Spec(generators)
	AddRelatedPropertyGeneratorsForPrincipalAssignment_Spec(generators)
	principalAssignment_SpecGenerator = gen.Struct(reflect.TypeOf(PrincipalAssignment_Spec{}), generators)

	return principalAssignment_SpecGenerator
}

// AddIndependentPropertyGeneratorsForPrincipalAssignment_Spec is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForPrincipalAssignment_Spec(gens map[string]gopter.Gen) {
	gens["AzureName"] = gen.AlphaString()
	gens["PrincipalId"] = gen.PtrOf(gen.AlphaString())
	gens["PrincipalType"] = gen.PtrOf(gen.OneConstOf(DatabasePrincipalProperties_PrincipalType_App, DatabasePrincipalProperties_PrincipalType_Group, DatabasePrincipalProperties_PrincipalType_User))
	gens["Role"] = gen.PtrOf(gen.OneConstOf(
		DatabasePrincipalProperties_Role_Admin,
		DatabasePrincipalProperties_Role_Ingestor,
		DatabasePrincipalProperties_Role_Monitor,
		DatabasePrincipalProperties_Role_UnrestrictedViewer,
		DatabasePrincipalProperties_Role_User,
		DatabasePrincipalProperties_Role_Viewer))
	gens["TenantId"] = gen.PtrOf(gen.AlphaString())
}

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