// 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_MongoUserDefinitionResource_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 MongoUserDefinitionResource via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForMongoUserDefinitionResource, MongoUserDefinitionResourceGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForMongoUserDefinitionResource(generators)
	AddRelatedPropertyGeneratorsForMongoUserDefinitionResource(generators)
	mongoUserDefinitionResourceGenerator = gen.Struct(reflect.TypeOf(MongoUserDefinitionResource{}), generators)

	return mongoUserDefinitionResourceGenerator
}

// AddIndependentPropertyGeneratorsForMongoUserDefinitionResource is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForMongoUserDefinitionResource(gens map[string]gopter.Gen) {
	gens["CustomData"] = gen.PtrOf(gen.AlphaString())
	gens["DatabaseName"] = gen.PtrOf(gen.AlphaString())
	gens["Mechanisms"] = gen.PtrOf(gen.AlphaString())
	gens["Password"] = gen.PtrOf(gen.AlphaString())
	gens["UserName"] = gen.PtrOf(gen.AlphaString())
}

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

func Test_MongodbUserDefinition_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 MongodbUserDefinition_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForMongodbUserDefinition_Spec, MongodbUserDefinition_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual MongodbUserDefinition_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 MongodbUserDefinition_Spec instances for property testing - lazily instantiated by
// MongodbUserDefinition_SpecGenerator()
var mongodbUserDefinition_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForMongodbUserDefinition_Spec(generators)
	AddRelatedPropertyGeneratorsForMongodbUserDefinition_Spec(generators)
	mongodbUserDefinition_SpecGenerator = gen.Struct(reflect.TypeOf(MongodbUserDefinition_Spec{}), generators)

	return mongodbUserDefinition_SpecGenerator
}

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

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