// 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_CustomCertificateProperties_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 CustomCertificateProperties via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForCustomCertificateProperties, CustomCertificatePropertiesGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// CustomCertificatePropertiesGenerator returns a generator of CustomCertificateProperties instances for property testing.
func CustomCertificatePropertiesGenerator() gopter.Gen {
	if customCertificatePropertiesGenerator != nil {
		return customCertificatePropertiesGenerator
	}

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

	return customCertificatePropertiesGenerator
}

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

func Test_CustomCertificate_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 CustomCertificate_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForCustomCertificate_Spec, CustomCertificate_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual CustomCertificate_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 CustomCertificate_Spec instances for property testing - lazily instantiated by
// CustomCertificate_SpecGenerator()
var customCertificate_SpecGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForCustomCertificate_Spec(generators)
	AddRelatedPropertyGeneratorsForCustomCertificate_Spec(generators)
	customCertificate_SpecGenerator = gen.Struct(reflect.TypeOf(CustomCertificate_Spec{}), generators)

	return customCertificate_SpecGenerator
}

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

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