// 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_ApplicationInsightsComponentProperties_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 ApplicationInsightsComponentProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForApplicationInsightsComponentProperties, ApplicationInsightsComponentPropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// ApplicationInsightsComponentPropertiesGenerator returns a generator of ApplicationInsightsComponentProperties instances for property testing.
func ApplicationInsightsComponentPropertiesGenerator() gopter.Gen {
	if applicationInsightsComponentPropertiesGenerator != nil {
		return applicationInsightsComponentPropertiesGenerator
	}

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

	return applicationInsightsComponentPropertiesGenerator
}

// AddIndependentPropertyGeneratorsForApplicationInsightsComponentProperties is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForApplicationInsightsComponentProperties(gens map[string]gopter.Gen) {
	gens["Application_Type"] = gen.PtrOf(gen.OneConstOf(ApplicationInsightsComponentProperties_Application_Type_Other, ApplicationInsightsComponentProperties_Application_Type_Web))
	gens["DisableIpMasking"] = gen.PtrOf(gen.Bool())
	gens["DisableLocalAuth"] = gen.PtrOf(gen.Bool())
	gens["Flow_Type"] = gen.PtrOf(gen.OneConstOf(ApplicationInsightsComponentProperties_Flow_Type_Bluefield))
	gens["ForceCustomerStorageForProfiler"] = gen.PtrOf(gen.Bool())
	gens["HockeyAppId"] = gen.PtrOf(gen.AlphaString())
	gens["ImmediatePurgeDataOn30Days"] = gen.PtrOf(gen.Bool())
	gens["IngestionMode"] = gen.PtrOf(gen.OneConstOf(ApplicationInsightsComponentProperties_IngestionMode_ApplicationInsights, ApplicationInsightsComponentProperties_IngestionMode_ApplicationInsightsWithDiagnosticSettings, ApplicationInsightsComponentProperties_IngestionMode_LogAnalytics))
	gens["PublicNetworkAccessForIngestion"] = gen.PtrOf(gen.OneConstOf(PublicNetworkAccessType_Disabled, PublicNetworkAccessType_Enabled))
	gens["PublicNetworkAccessForQuery"] = gen.PtrOf(gen.OneConstOf(PublicNetworkAccessType_Disabled, PublicNetworkAccessType_Enabled))
	gens["Request_Source"] = gen.PtrOf(gen.OneConstOf(ApplicationInsightsComponentProperties_Request_Source_Rest))
	gens["RetentionInDays"] = gen.PtrOf(gen.Int())
	gens["SamplingPercentage"] = gen.PtrOf(gen.Float64())
	gens["WorkspaceResourceId"] = gen.PtrOf(gen.AlphaString())
}

func Test_Component_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 Component_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForComponent_Spec, Component_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual Component_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 Component_Spec instances for property testing - lazily instantiated by Component_SpecGenerator()
var component_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForComponent_Spec(generators)
	AddRelatedPropertyGeneratorsForComponent_Spec(generators)
	component_SpecGenerator = gen.Struct(reflect.TypeOf(Component_Spec{}), generators)

	return component_SpecGenerator
}

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

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