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

import (
	"encoding/json"
	"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_ResourceIdentity_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 ResourceIdentity via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForResourceIdentity, ResourceIdentityGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForResourceIdentity(generators)
	AddRelatedPropertyGeneratorsForResourceIdentity(generators)
	resourceIdentityGenerator = gen.Struct(reflect.TypeOf(ResourceIdentity{}), generators)

	return resourceIdentityGenerator
}

// AddIndependentPropertyGeneratorsForResourceIdentity is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForResourceIdentity(gens map[string]gopter.Gen) {
	gens["Type"] = gen.PtrOf(gen.OneConstOf(
		ResourceIdentity_Type_None,
		ResourceIdentity_Type_SystemAssigned,
		ResourceIdentity_Type_SystemAssignedUserAssigned,
		ResourceIdentity_Type_UserAssigned))
}

// AddRelatedPropertyGeneratorsForResourceIdentity is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForResourceIdentity(gens map[string]gopter.Gen) {
	gens["UserAssignedIdentities"] = gen.MapOf(
		gen.AlphaString(),
		UserAssignedIdentityDetailsGenerator())
}

func Test_ServerExternalAdministrator_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 ServerExternalAdministrator via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForServerExternalAdministrator, ServerExternalAdministratorGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// ServerExternalAdministratorGenerator returns a generator of ServerExternalAdministrator instances for property testing.
func ServerExternalAdministratorGenerator() gopter.Gen {
	if serverExternalAdministratorGenerator != nil {
		return serverExternalAdministratorGenerator
	}

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

	return serverExternalAdministratorGenerator
}

// AddIndependentPropertyGeneratorsForServerExternalAdministrator is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForServerExternalAdministrator(gens map[string]gopter.Gen) {
	gens["AdministratorType"] = gen.PtrOf(gen.OneConstOf(ServerExternalAdministrator_AdministratorType_ActiveDirectory))
	gens["AzureADOnlyAuthentication"] = gen.PtrOf(gen.Bool())
	gens["Login"] = gen.PtrOf(gen.AlphaString())
	gens["PrincipalType"] = gen.PtrOf(gen.OneConstOf(ServerExternalAdministrator_PrincipalType_Application, ServerExternalAdministrator_PrincipalType_Group, ServerExternalAdministrator_PrincipalType_User))
	gens["Sid"] = gen.PtrOf(gen.AlphaString())
	gens["TenantId"] = gen.PtrOf(gen.AlphaString())
}

func Test_ServerProperties_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 ServerProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForServerProperties, ServerPropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForServerProperties(generators)
	AddRelatedPropertyGeneratorsForServerProperties(generators)
	serverPropertiesGenerator = gen.Struct(reflect.TypeOf(ServerProperties{}), generators)

	return serverPropertiesGenerator
}

// AddIndependentPropertyGeneratorsForServerProperties is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForServerProperties(gens map[string]gopter.Gen) {
	gens["AdministratorLogin"] = gen.PtrOf(gen.AlphaString())
	gens["AdministratorLoginPassword"] = gen.PtrOf(gen.AlphaString())
	gens["FederatedClientId"] = gen.PtrOf(gen.AlphaString())
	gens["KeyId"] = gen.PtrOf(gen.AlphaString())
	gens["MinimalTlsVersion"] = gen.PtrOf(gen.AlphaString())
	gens["PrimaryUserAssignedIdentityId"] = gen.PtrOf(gen.AlphaString())
	gens["PublicNetworkAccess"] = gen.PtrOf(gen.OneConstOf(ServerProperties_PublicNetworkAccess_Disabled, ServerProperties_PublicNetworkAccess_Enabled))
	gens["RestrictOutboundNetworkAccess"] = gen.PtrOf(gen.OneConstOf(ServerProperties_RestrictOutboundNetworkAccess_Disabled, ServerProperties_RestrictOutboundNetworkAccess_Enabled))
	gens["Version"] = gen.PtrOf(gen.AlphaString())
}

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

func Test_Server_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 Server_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForServer_Spec, Server_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual Server_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 Server_Spec instances for property testing - lazily instantiated by Server_SpecGenerator()
var server_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForServer_Spec(generators)
	AddRelatedPropertyGeneratorsForServer_Spec(generators)
	server_SpecGenerator = gen.Struct(reflect.TypeOf(Server_Spec{}), generators)

	return server_SpecGenerator
}

// AddIndependentPropertyGeneratorsForServer_Spec is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForServer_Spec(gens map[string]gopter.Gen) {
	gens["Location"] = gen.PtrOf(gen.AlphaString())
	gens["Name"] = gen.AlphaString()
	gens["Tags"] = gen.MapOf(
		gen.AlphaString(),
		gen.AlphaString())
}

// AddRelatedPropertyGeneratorsForServer_Spec is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForServer_Spec(gens map[string]gopter.Gen) {
	gens["Identity"] = gen.PtrOf(ResourceIdentityGenerator())
	gens["Properties"] = gen.PtrOf(ServerPropertiesGenerator())
}

func Test_UserAssignedIdentityDetails_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 UserAssignedIdentityDetails via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForUserAssignedIdentityDetails, UserAssignedIdentityDetailsGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// UserAssignedIdentityDetailsGenerator returns a generator of UserAssignedIdentityDetails instances for property testing.
func UserAssignedIdentityDetailsGenerator() gopter.Gen {
	if userAssignedIdentityDetailsGenerator != nil {
		return userAssignedIdentityDetailsGenerator
	}

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

	return userAssignedIdentityDetailsGenerator
}
