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

import (
	"encoding/json"
	storage "github.com/Azure/azure-service-operator/v2/api/cache/v1api20241101/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_RedisAccessPolicy_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 RedisAccessPolicy to hub returns original",
		prop.ForAll(RunResourceConversionTestForRedisAccessPolicy, RedisAccessPolicyGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

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

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

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

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

// RedisAccessPolicyGenerator returns a generator of RedisAccessPolicy instances for property testing.
func RedisAccessPolicyGenerator() gopter.Gen {
	if redisAccessPolicyGenerator != nil {
		return redisAccessPolicyGenerator
	}

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

	return redisAccessPolicyGenerator
}

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

func Test_RedisAccessPolicyOperatorSpec_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from RedisAccessPolicyOperatorSpec to RedisAccessPolicyOperatorSpec via AssignProperties_To_RedisAccessPolicyOperatorSpec & AssignProperties_From_RedisAccessPolicyOperatorSpec returns original",
		prop.ForAll(RunPropertyAssignmentTestForRedisAccessPolicyOperatorSpec, RedisAccessPolicyOperatorSpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

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

// RedisAccessPolicyOperatorSpecGenerator returns a generator of RedisAccessPolicyOperatorSpec instances for property testing.
func RedisAccessPolicyOperatorSpecGenerator() gopter.Gen {
	if redisAccessPolicyOperatorSpecGenerator != nil {
		return redisAccessPolicyOperatorSpecGenerator
	}

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

	return redisAccessPolicyOperatorSpecGenerator
}

func Test_RedisAccessPolicy_STATUS_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from RedisAccessPolicy_STATUS to RedisAccessPolicy_STATUS via AssignProperties_To_RedisAccessPolicy_STATUS & AssignProperties_From_RedisAccessPolicy_STATUS returns original",
		prop.ForAll(RunPropertyAssignmentTestForRedisAccessPolicy_STATUS, RedisAccessPolicy_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

	// Deserialize back into memory
	var actual RedisAccessPolicy_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 RedisAccessPolicy_STATUS instances for property testing - lazily instantiated by
// RedisAccessPolicy_STATUSGenerator()
var redisAccessPolicy_STATUSGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForRedisAccessPolicy_STATUS(generators)
	AddRelatedPropertyGeneratorsForRedisAccessPolicy_STATUS(generators)
	redisAccessPolicy_STATUSGenerator = gen.Struct(reflect.TypeOf(RedisAccessPolicy_STATUS{}), generators)

	return redisAccessPolicy_STATUSGenerator
}

// AddIndependentPropertyGeneratorsForRedisAccessPolicy_STATUS is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForRedisAccessPolicy_STATUS(gens map[string]gopter.Gen) {
	gens["Id"] = gen.PtrOf(gen.AlphaString())
	gens["Name"] = gen.PtrOf(gen.AlphaString())
	gens["Permissions"] = gen.PtrOf(gen.AlphaString())
	gens["PropertiesType"] = gen.PtrOf(gen.OneConstOf(AccessPolicyType_STATUS_BuiltIn, AccessPolicyType_STATUS_Custom))
	gens["ProvisioningState"] = gen.PtrOf(gen.OneConstOf(
		AccessPolicyProvisioningState_STATUS_Canceled,
		AccessPolicyProvisioningState_STATUS_Deleted,
		AccessPolicyProvisioningState_STATUS_Deleting,
		AccessPolicyProvisioningState_STATUS_Failed,
		AccessPolicyProvisioningState_STATUS_Succeeded,
		AccessPolicyProvisioningState_STATUS_Updating))
	gens["Type"] = gen.PtrOf(gen.AlphaString())
}

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

func Test_RedisAccessPolicy_Spec_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from RedisAccessPolicy_Spec to RedisAccessPolicy_Spec via AssignProperties_To_RedisAccessPolicy_Spec & AssignProperties_From_RedisAccessPolicy_Spec returns original",
		prop.ForAll(RunPropertyAssignmentTestForRedisAccessPolicy_Spec, RedisAccessPolicy_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

	// Deserialize back into memory
	var actual RedisAccessPolicy_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 RedisAccessPolicy_Spec instances for property testing - lazily instantiated by
// RedisAccessPolicy_SpecGenerator()
var redisAccessPolicy_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForRedisAccessPolicy_Spec(generators)
	AddRelatedPropertyGeneratorsForRedisAccessPolicy_Spec(generators)
	redisAccessPolicy_SpecGenerator = gen.Struct(reflect.TypeOf(RedisAccessPolicy_Spec{}), generators)

	return redisAccessPolicy_SpecGenerator
}

// AddIndependentPropertyGeneratorsForRedisAccessPolicy_Spec is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForRedisAccessPolicy_Spec(gens map[string]gopter.Gen) {
	gens["AzureName"] = gen.AlphaString()
	gens["Permissions"] = gen.PtrOf(gen.AlphaString())
}

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