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

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_PrincipalAssignment_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 PrincipalAssignment via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForPrincipalAssignment, PrincipalAssignmentGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// PrincipalAssignmentGenerator returns a generator of PrincipalAssignment instances for property testing.
func PrincipalAssignmentGenerator() gopter.Gen {
	if principalAssignmentGenerator != nil {
		return principalAssignmentGenerator
	}

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

	return principalAssignmentGenerator
}

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

func Test_PrincipalAssignmentOperatorSpec_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 PrincipalAssignmentOperatorSpec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForPrincipalAssignmentOperatorSpec, PrincipalAssignmentOperatorSpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// PrincipalAssignmentOperatorSpecGenerator returns a generator of PrincipalAssignmentOperatorSpec instances for property testing.
func PrincipalAssignmentOperatorSpecGenerator() gopter.Gen {
	if principalAssignmentOperatorSpecGenerator != nil {
		return principalAssignmentOperatorSpecGenerator
	}

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

	return principalAssignmentOperatorSpecGenerator
}

func Test_PrincipalAssignment_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 PrincipalAssignment_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForPrincipalAssignment_STATUS, PrincipalAssignment_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual PrincipalAssignment_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 PrincipalAssignment_STATUS instances for property testing - lazily instantiated by
// PrincipalAssignment_STATUSGenerator()
var principalAssignment_STATUSGenerator gopter.Gen

// PrincipalAssignment_STATUSGenerator returns a generator of PrincipalAssignment_STATUS instances for property testing.
func PrincipalAssignment_STATUSGenerator() gopter.Gen {
	if principalAssignment_STATUSGenerator != nil {
		return principalAssignment_STATUSGenerator
	}

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

	return principalAssignment_STATUSGenerator
}

// AddIndependentPropertyGeneratorsForPrincipalAssignment_STATUS is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForPrincipalAssignment_STATUS(gens map[string]gopter.Gen) {
	gens["AadObjectId"] = gen.PtrOf(gen.AlphaString())
	gens["Id"] = gen.PtrOf(gen.AlphaString())
	gens["Name"] = gen.PtrOf(gen.AlphaString())
	gens["PrincipalId"] = gen.PtrOf(gen.AlphaString())
	gens["PrincipalName"] = gen.PtrOf(gen.AlphaString())
	gens["PrincipalType"] = gen.PtrOf(gen.AlphaString())
	gens["ProvisioningState"] = gen.PtrOf(gen.AlphaString())
	gens["Role"] = gen.PtrOf(gen.AlphaString())
	gens["TenantId"] = gen.PtrOf(gen.AlphaString())
	gens["TenantName"] = gen.PtrOf(gen.AlphaString())
	gens["Type"] = gen.PtrOf(gen.AlphaString())
}

func Test_PrincipalAssignment_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 PrincipalAssignment_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForPrincipalAssignment_Spec, PrincipalAssignment_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual PrincipalAssignment_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 PrincipalAssignment_Spec instances for property testing - lazily instantiated by
// PrincipalAssignment_SpecGenerator()
var principalAssignment_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForPrincipalAssignment_Spec(generators)
	AddRelatedPropertyGeneratorsForPrincipalAssignment_Spec(generators)
	principalAssignment_SpecGenerator = gen.Struct(reflect.TypeOf(PrincipalAssignment_Spec{}), generators)

	return principalAssignment_SpecGenerator
}

// AddIndependentPropertyGeneratorsForPrincipalAssignment_Spec is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForPrincipalAssignment_Spec(gens map[string]gopter.Gen) {
	gens["AzureName"] = gen.AlphaString()
	gens["OriginalVersion"] = gen.AlphaString()
	gens["PrincipalId"] = gen.PtrOf(gen.AlphaString())
	gens["PrincipalType"] = gen.PtrOf(gen.AlphaString())
	gens["Role"] = gen.PtrOf(gen.AlphaString())
	gens["TenantId"] = gen.PtrOf(gen.AlphaString())
}

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