// 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_ActionGroupsInformation_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 ActionGroupsInformation via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForActionGroupsInformation, ActionGroupsInformationGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// ActionGroupsInformationGenerator returns a generator of ActionGroupsInformation instances for property testing.
func ActionGroupsInformationGenerator() gopter.Gen {
	if actionGroupsInformationGenerator != nil {
		return actionGroupsInformationGenerator
	}

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

	return actionGroupsInformationGenerator
}

// AddIndependentPropertyGeneratorsForActionGroupsInformation is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForActionGroupsInformation(gens map[string]gopter.Gen) {
	gens["CustomEmailSubject"] = gen.PtrOf(gen.AlphaString())
	gens["CustomWebhookPayload"] = gen.PtrOf(gen.AlphaString())
	gens["GroupIds"] = gen.SliceOf(gen.AlphaString())
}

func Test_AlertRuleProperties_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 AlertRuleProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForAlertRuleProperties, AlertRulePropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForAlertRuleProperties(generators)
	AddRelatedPropertyGeneratorsForAlertRuleProperties(generators)
	alertRulePropertiesGenerator = gen.Struct(reflect.TypeOf(AlertRuleProperties{}), generators)

	return alertRulePropertiesGenerator
}

// AddIndependentPropertyGeneratorsForAlertRuleProperties is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForAlertRuleProperties(gens map[string]gopter.Gen) {
	gens["Description"] = gen.PtrOf(gen.AlphaString())
	gens["Frequency"] = gen.PtrOf(gen.AlphaString())
	gens["Scope"] = gen.SliceOf(gen.AlphaString())
	gens["Severity"] = gen.PtrOf(gen.OneConstOf(
		AlertRuleProperties_Severity_Sev0,
		AlertRuleProperties_Severity_Sev1,
		AlertRuleProperties_Severity_Sev2,
		AlertRuleProperties_Severity_Sev3,
		AlertRuleProperties_Severity_Sev4))
	gens["State"] = gen.PtrOf(gen.OneConstOf(AlertRuleProperties_State_Disabled, AlertRuleProperties_State_Enabled))
}

// AddRelatedPropertyGeneratorsForAlertRuleProperties is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForAlertRuleProperties(gens map[string]gopter.Gen) {
	gens["ActionGroups"] = gen.PtrOf(ActionGroupsInformationGenerator())
	gens["Detector"] = gen.PtrOf(DetectorGenerator())
	gens["Throttling"] = gen.PtrOf(ThrottlingInformationGenerator())
}

func Test_Detector_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 Detector via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDetector, DetectorGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// DetectorGenerator returns a generator of Detector instances for property testing.
func DetectorGenerator() gopter.Gen {
	if detectorGenerator != nil {
		return detectorGenerator
	}

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

	return detectorGenerator
}

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

func Test_SmartDetectorAlertRule_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 SmartDetectorAlertRule_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForSmartDetectorAlertRule_Spec, SmartDetectorAlertRule_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual SmartDetectorAlertRule_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 SmartDetectorAlertRule_Spec instances for property testing - lazily instantiated by
// SmartDetectorAlertRule_SpecGenerator()
var smartDetectorAlertRule_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForSmartDetectorAlertRule_Spec(generators)
	AddRelatedPropertyGeneratorsForSmartDetectorAlertRule_Spec(generators)
	smartDetectorAlertRule_SpecGenerator = gen.Struct(reflect.TypeOf(SmartDetectorAlertRule_Spec{}), generators)

	return smartDetectorAlertRule_SpecGenerator
}

// AddIndependentPropertyGeneratorsForSmartDetectorAlertRule_Spec is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForSmartDetectorAlertRule_Spec(gens map[string]gopter.Gen) {
	gens["Location"] = gen.PtrOf(gen.AlphaString())
	gens["Name"] = gen.AlphaString()
	gens["Tags"] = gen.MapOf(
		gen.AlphaString(),
		gen.AlphaString())
}

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

func Test_ThrottlingInformation_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 ThrottlingInformation via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForThrottlingInformation, ThrottlingInformationGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// ThrottlingInformationGenerator returns a generator of ThrottlingInformation instances for property testing.
func ThrottlingInformationGenerator() gopter.Gen {
	if throttlingInformationGenerator != nil {
		return throttlingInformationGenerator
	}

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

	return throttlingInformationGenerator
}

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