// 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_RuleSetProperties_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 RuleSetProperties_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForRuleSetProperties_STATUS, RuleSetProperties_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual RuleSetProperties_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 RuleSetProperties_STATUS instances for property testing - lazily instantiated by
// RuleSetProperties_STATUSGenerator()
var ruleSetProperties_STATUSGenerator gopter.Gen

// RuleSetProperties_STATUSGenerator returns a generator of RuleSetProperties_STATUS instances for property testing.
func RuleSetProperties_STATUSGenerator() gopter.Gen {
	if ruleSetProperties_STATUSGenerator != nil {
		return ruleSetProperties_STATUSGenerator
	}

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

	return ruleSetProperties_STATUSGenerator
}

// AddIndependentPropertyGeneratorsForRuleSetProperties_STATUS is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForRuleSetProperties_STATUS(gens map[string]gopter.Gen) {
	gens["DeploymentStatus"] = gen.PtrOf(gen.OneConstOf(
		RuleSetProperties_DeploymentStatus_STATUS_Failed,
		RuleSetProperties_DeploymentStatus_STATUS_InProgress,
		RuleSetProperties_DeploymentStatus_STATUS_NotStarted,
		RuleSetProperties_DeploymentStatus_STATUS_Succeeded))
	gens["ProfileName"] = gen.PtrOf(gen.AlphaString())
	gens["ProvisioningState"] = gen.PtrOf(gen.OneConstOf(
		RuleSetProperties_ProvisioningState_STATUS_Creating,
		RuleSetProperties_ProvisioningState_STATUS_Deleting,
		RuleSetProperties_ProvisioningState_STATUS_Failed,
		RuleSetProperties_ProvisioningState_STATUS_Succeeded,
		RuleSetProperties_ProvisioningState_STATUS_Updating))
}

func Test_RuleSet_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 RuleSet_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForRuleSet_STATUS, RuleSet_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual RuleSet_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 RuleSet_STATUS instances for property testing - lazily instantiated by RuleSet_STATUSGenerator()
var ruleSet_STATUSGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForRuleSet_STATUS(generators)
	AddRelatedPropertyGeneratorsForRuleSet_STATUS(generators)
	ruleSet_STATUSGenerator = gen.Struct(reflect.TypeOf(RuleSet_STATUS{}), generators)

	return ruleSet_STATUSGenerator
}

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

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