// 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_AdministratorProperties_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 AdministratorProperties_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForAdministratorProperties_STATUS, AdministratorProperties_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual AdministratorProperties_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 AdministratorProperties_STATUS instances for property testing - lazily instantiated by
// AdministratorProperties_STATUSGenerator()
var administratorProperties_STATUSGenerator gopter.Gen

// AdministratorProperties_STATUSGenerator returns a generator of AdministratorProperties_STATUS instances for property testing.
func AdministratorProperties_STATUSGenerator() gopter.Gen {
	if administratorProperties_STATUSGenerator != nil {
		return administratorProperties_STATUSGenerator
	}

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

	return administratorProperties_STATUSGenerator
}

// AddIndependentPropertyGeneratorsForAdministratorProperties_STATUS is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForAdministratorProperties_STATUS(gens map[string]gopter.Gen) {
	gens["AdministratorType"] = gen.PtrOf(gen.OneConstOf(AdministratorProperties_AdministratorType_STATUS_ActiveDirectory))
	gens["AzureADOnlyAuthentication"] = gen.PtrOf(gen.Bool())
	gens["Login"] = gen.PtrOf(gen.AlphaString())
	gens["Sid"] = gen.PtrOf(gen.AlphaString())
	gens["TenantId"] = gen.PtrOf(gen.AlphaString())
}

func Test_ServersAdministrator_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 ServersAdministrator_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForServersAdministrator_STATUS, ServersAdministrator_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual ServersAdministrator_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 ServersAdministrator_STATUS instances for property testing - lazily instantiated by
// ServersAdministrator_STATUSGenerator()
var serversAdministrator_STATUSGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForServersAdministrator_STATUS(generators)
	AddRelatedPropertyGeneratorsForServersAdministrator_STATUS(generators)
	serversAdministrator_STATUSGenerator = gen.Struct(reflect.TypeOf(ServersAdministrator_STATUS{}), generators)

	return serversAdministrator_STATUSGenerator
}

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

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