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

import (
	"encoding/json"
	v20210701s "github.com/Azure/azure-service-operator/v2/api/machinelearningservices/v1api20210701/storage"
	v20240401s "github.com/Azure/azure-service-operator/v2/api/machinelearningservices/v1api20240401/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_WorkspacesConnection_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 WorkspacesConnection to hub returns original",
		prop.ForAll(RunResourceConversionTestForWorkspacesConnection, WorkspacesConnectionGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

// RunPropertyAssignmentTestForWorkspacesConnection tests if a specific instance of WorkspacesConnection can be assigned to storage and back losslessly
func RunPropertyAssignmentTestForWorkspacesConnection(subject WorkspacesConnection) string {
	// Copy subject to make sure assignment doesn't modify it
	copied := subject.DeepCopy()

	// Use AssignPropertiesTo() for the first stage of conversion
	var other v20210701s.WorkspacesConnection
	err := copied.AssignProperties_To_WorkspacesConnection(&other)
	if err != nil {
		return err.Error()
	}

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

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

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

// WorkspacesConnectionGenerator returns a generator of WorkspacesConnection instances for property testing.
func WorkspacesConnectionGenerator() gopter.Gen {
	if workspacesConnectionGenerator != nil {
		return workspacesConnectionGenerator
	}

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

	return workspacesConnectionGenerator
}

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

func Test_WorkspacesConnectionOperatorSpec_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from WorkspacesConnectionOperatorSpec to WorkspacesConnectionOperatorSpec via AssignProperties_To_WorkspacesConnectionOperatorSpec & AssignProperties_From_WorkspacesConnectionOperatorSpec returns original",
		prop.ForAll(RunPropertyAssignmentTestForWorkspacesConnectionOperatorSpec, WorkspacesConnectionOperatorSpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

// RunPropertyAssignmentTestForWorkspacesConnectionOperatorSpec tests if a specific instance of WorkspacesConnectionOperatorSpec can be assigned to storage and back losslessly
func RunPropertyAssignmentTestForWorkspacesConnectionOperatorSpec(subject WorkspacesConnectionOperatorSpec) string {
	// Copy subject to make sure assignment doesn't modify it
	copied := subject.DeepCopy()

	// Use AssignPropertiesTo() for the first stage of conversion
	var other v20210701s.WorkspacesConnectionOperatorSpec
	err := copied.AssignProperties_To_WorkspacesConnectionOperatorSpec(&other)
	if err != nil {
		return err.Error()
	}

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

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

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

// WorkspacesConnectionOperatorSpecGenerator returns a generator of WorkspacesConnectionOperatorSpec instances for property testing.
func WorkspacesConnectionOperatorSpecGenerator() gopter.Gen {
	if workspacesConnectionOperatorSpecGenerator != nil {
		return workspacesConnectionOperatorSpecGenerator
	}

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

	return workspacesConnectionOperatorSpecGenerator
}

func Test_WorkspacesConnection_STATUS_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from WorkspacesConnection_STATUS to WorkspacesConnection_STATUS via AssignProperties_To_WorkspacesConnection_STATUS & AssignProperties_From_WorkspacesConnection_STATUS returns original",
		prop.ForAll(RunPropertyAssignmentTestForWorkspacesConnection_STATUS, WorkspacesConnection_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

	// Deserialize back into memory
	var actual WorkspacesConnection_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 WorkspacesConnection_STATUS instances for property testing - lazily instantiated by
// WorkspacesConnection_STATUSGenerator()
var workspacesConnection_STATUSGenerator gopter.Gen

// WorkspacesConnection_STATUSGenerator returns a generator of WorkspacesConnection_STATUS instances for property testing.
func WorkspacesConnection_STATUSGenerator() gopter.Gen {
	if workspacesConnection_STATUSGenerator != nil {
		return workspacesConnection_STATUSGenerator
	}

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

	return workspacesConnection_STATUSGenerator
}

// AddIndependentPropertyGeneratorsForWorkspacesConnection_STATUS is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForWorkspacesConnection_STATUS(gens map[string]gopter.Gen) {
	gens["AuthType"] = gen.PtrOf(gen.AlphaString())
	gens["Category"] = gen.PtrOf(gen.AlphaString())
	gens["Id"] = gen.PtrOf(gen.AlphaString())
	gens["Name"] = gen.PtrOf(gen.AlphaString())
	gens["Target"] = gen.PtrOf(gen.AlphaString())
	gens["Type"] = gen.PtrOf(gen.AlphaString())
	gens["Value"] = gen.PtrOf(gen.AlphaString())
	gens["ValueFormat"] = gen.PtrOf(gen.OneConstOf(WorkspaceConnectionProps_ValueFormat_STATUS_JSON))
}

func Test_WorkspacesConnection_Spec_WhenPropertiesConverted_RoundTripsWithoutLoss(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MaxSize = 10
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip from WorkspacesConnection_Spec to WorkspacesConnection_Spec via AssignProperties_To_WorkspacesConnection_Spec & AssignProperties_From_WorkspacesConnection_Spec returns original",
		prop.ForAll(RunPropertyAssignmentTestForWorkspacesConnection_Spec, WorkspacesConnection_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(false, 240, os.Stdout))
}

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

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

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

	// Deserialize back into memory
	var actual WorkspacesConnection_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 WorkspacesConnection_Spec instances for property testing - lazily instantiated by
// WorkspacesConnection_SpecGenerator()
var workspacesConnection_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForWorkspacesConnection_Spec(generators)
	AddRelatedPropertyGeneratorsForWorkspacesConnection_Spec(generators)
	workspacesConnection_SpecGenerator = gen.Struct(reflect.TypeOf(WorkspacesConnection_Spec{}), generators)

	return workspacesConnection_SpecGenerator
}

// AddIndependentPropertyGeneratorsForWorkspacesConnection_Spec is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForWorkspacesConnection_Spec(gens map[string]gopter.Gen) {
	gens["AuthType"] = gen.PtrOf(gen.AlphaString())
	gens["AzureName"] = gen.AlphaString()
	gens["Category"] = gen.PtrOf(gen.AlphaString())
	gens["Target"] = gen.PtrOf(gen.AlphaString())
	gens["Value"] = gen.PtrOf(gen.AlphaString())
	gens["ValueFormat"] = gen.PtrOf(gen.OneConstOf(WorkspaceConnectionProps_ValueFormat_JSON))
}

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