// 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_DiagnosticSetting_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 DiagnosticSetting_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDiagnosticSetting_Spec, DiagnosticSetting_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual DiagnosticSetting_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 DiagnosticSetting_Spec instances for property testing - lazily instantiated by
// DiagnosticSetting_SpecGenerator()
var diagnosticSetting_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDiagnosticSetting_Spec(generators)
	AddRelatedPropertyGeneratorsForDiagnosticSetting_Spec(generators)
	diagnosticSetting_SpecGenerator = gen.Struct(reflect.TypeOf(DiagnosticSetting_Spec{}), generators)

	return diagnosticSetting_SpecGenerator
}

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

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

func Test_DiagnosticSettings_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 DiagnosticSettings via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForDiagnosticSettings, DiagnosticSettingsGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForDiagnosticSettings(generators)
	AddRelatedPropertyGeneratorsForDiagnosticSettings(generators)
	diagnosticSettingsGenerator = gen.Struct(reflect.TypeOf(DiagnosticSettings{}), generators)

	return diagnosticSettingsGenerator
}

// AddIndependentPropertyGeneratorsForDiagnosticSettings is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForDiagnosticSettings(gens map[string]gopter.Gen) {
	gens["EventHubAuthorizationRuleId"] = gen.PtrOf(gen.AlphaString())
	gens["EventHubName"] = gen.PtrOf(gen.AlphaString())
	gens["LogAnalyticsDestinationType"] = gen.PtrOf(gen.AlphaString())
	gens["MarketplacePartnerId"] = gen.PtrOf(gen.AlphaString())
	gens["ServiceBusRuleId"] = gen.PtrOf(gen.AlphaString())
	gens["StorageAccountId"] = gen.PtrOf(gen.AlphaString())
	gens["WorkspaceId"] = gen.PtrOf(gen.AlphaString())
}

// AddRelatedPropertyGeneratorsForDiagnosticSettings is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForDiagnosticSettings(gens map[string]gopter.Gen) {
	gens["Logs"] = gen.SliceOf(LogSettingsGenerator())
	gens["Metrics"] = gen.SliceOf(MetricSettingsGenerator())
}

func Test_LogSettings_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 LogSettings via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForLogSettings, LogSettingsGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForLogSettings(generators)
	AddRelatedPropertyGeneratorsForLogSettings(generators)
	logSettingsGenerator = gen.Struct(reflect.TypeOf(LogSettings{}), generators)

	return logSettingsGenerator
}

// AddIndependentPropertyGeneratorsForLogSettings is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForLogSettings(gens map[string]gopter.Gen) {
	gens["Category"] = gen.PtrOf(gen.AlphaString())
	gens["CategoryGroup"] = gen.PtrOf(gen.AlphaString())
	gens["Enabled"] = gen.PtrOf(gen.Bool())
}

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

func Test_MetricSettings_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 MetricSettings via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForMetricSettings, MetricSettingsGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForMetricSettings(generators)
	AddRelatedPropertyGeneratorsForMetricSettings(generators)
	metricSettingsGenerator = gen.Struct(reflect.TypeOf(MetricSettings{}), generators)

	return metricSettingsGenerator
}

// AddIndependentPropertyGeneratorsForMetricSettings is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForMetricSettings(gens map[string]gopter.Gen) {
	gens["Category"] = gen.PtrOf(gen.AlphaString())
	gens["Enabled"] = gen.PtrOf(gen.Bool())
	gens["TimeGrain"] = gen.PtrOf(gen.AlphaString())
}

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

func Test_RetentionPolicy_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 RetentionPolicy via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForRetentionPolicy, RetentionPolicyGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// RetentionPolicyGenerator returns a generator of RetentionPolicy instances for property testing.
func RetentionPolicyGenerator() gopter.Gen {
	if retentionPolicyGenerator != nil {
		return retentionPolicyGenerator
	}

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

	return retentionPolicyGenerator
}

// AddIndependentPropertyGeneratorsForRetentionPolicy is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForRetentionPolicy(gens map[string]gopter.Gen) {
	gens["Days"] = gen.PtrOf(gen.Int())
	gens["Enabled"] = gen.PtrOf(gen.Bool())
}
