// 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_MongoRoleDefinitionResource_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 MongoRoleDefinitionResource via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForMongoRoleDefinitionResource, MongoRoleDefinitionResourceGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForMongoRoleDefinitionResource(generators)
	AddRelatedPropertyGeneratorsForMongoRoleDefinitionResource(generators)
	mongoRoleDefinitionResourceGenerator = gen.Struct(reflect.TypeOf(MongoRoleDefinitionResource{}), generators)

	return mongoRoleDefinitionResourceGenerator
}

// AddIndependentPropertyGeneratorsForMongoRoleDefinitionResource is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForMongoRoleDefinitionResource(gens map[string]gopter.Gen) {
	gens["DatabaseName"] = gen.PtrOf(gen.AlphaString())
	gens["RoleName"] = gen.PtrOf(gen.AlphaString())
	gens["Type"] = gen.PtrOf(gen.OneConstOf(MongoRoleDefinitionResource_Type_BuiltInRole, MongoRoleDefinitionResource_Type_CustomRole))
}

// AddRelatedPropertyGeneratorsForMongoRoleDefinitionResource is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForMongoRoleDefinitionResource(gens map[string]gopter.Gen) {
	gens["Privileges"] = gen.SliceOf(PrivilegeGenerator())
	gens["Roles"] = gen.SliceOf(RoleGenerator())
}

func Test_MongodbRoleDefinition_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 MongodbRoleDefinition_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForMongodbRoleDefinition_Spec, MongodbRoleDefinition_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual MongodbRoleDefinition_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 MongodbRoleDefinition_Spec instances for property testing - lazily instantiated by
// MongodbRoleDefinition_SpecGenerator()
var mongodbRoleDefinition_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForMongodbRoleDefinition_Spec(generators)
	AddRelatedPropertyGeneratorsForMongodbRoleDefinition_Spec(generators)
	mongodbRoleDefinition_SpecGenerator = gen.Struct(reflect.TypeOf(MongodbRoleDefinition_Spec{}), generators)

	return mongodbRoleDefinition_SpecGenerator
}

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

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

func Test_Privilege_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 Privilege via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForPrivilege, PrivilegeGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForPrivilege(generators)
	AddRelatedPropertyGeneratorsForPrivilege(generators)
	privilegeGenerator = gen.Struct(reflect.TypeOf(Privilege{}), generators)

	return privilegeGenerator
}

// AddIndependentPropertyGeneratorsForPrivilege is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForPrivilege(gens map[string]gopter.Gen) {
	gens["Actions"] = gen.SliceOf(gen.AlphaString())
}

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

func Test_Privilege_Resource_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 Privilege_Resource via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForPrivilege_Resource, Privilege_ResourceGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// Privilege_ResourceGenerator returns a generator of Privilege_Resource instances for property testing.
func Privilege_ResourceGenerator() gopter.Gen {
	if privilege_ResourceGenerator != nil {
		return privilege_ResourceGenerator
	}

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

	return privilege_ResourceGenerator
}

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

func Test_Role_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 Role via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForRole, RoleGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// RoleGenerator returns a generator of Role instances for property testing.
func RoleGenerator() gopter.Gen {
	if roleGenerator != nil {
		return roleGenerator
	}

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

	return roleGenerator
}

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