// Code generated by azure-service-operator-codegen. DO NOT EDIT.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package storage

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_Product_WhenSerializedToJson_DeserializesAsEqual(t *testing.T) {
	t.Parallel()
	parameters := gopter.DefaultTestParameters()
	parameters.MinSuccessfulTests = 20
	parameters.MaxSize = 3
	properties := gopter.NewProperties(parameters)
	properties.Property(
		"Round trip of Product via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForProduct, ProductGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// ProductGenerator returns a generator of Product instances for property testing.
func ProductGenerator() gopter.Gen {
	if productGenerator != nil {
		return productGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddRelatedPropertyGeneratorsForProduct(generators)
	productGenerator = gen.Struct(reflect.TypeOf(Product{}), generators)

	return productGenerator
}

// AddRelatedPropertyGeneratorsForProduct is a factory method for creating gopter generators
func AddRelatedPropertyGeneratorsForProduct(gens map[string]gopter.Gen) {
	gens["Spec"] = Product_SpecGenerator()
	gens["Status"] = Product_STATUSGenerator()
}

func Test_ProductOperatorSpec_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 ProductOperatorSpec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForProductOperatorSpec, ProductOperatorSpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

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

// ProductOperatorSpecGenerator returns a generator of ProductOperatorSpec instances for property testing.
func ProductOperatorSpecGenerator() gopter.Gen {
	if productOperatorSpecGenerator != nil {
		return productOperatorSpecGenerator
	}

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

	return productOperatorSpecGenerator
}

func Test_Product_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 Product_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForProduct_STATUS, Product_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual Product_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 Product_STATUS instances for property testing - lazily instantiated by Product_STATUSGenerator()
var product_STATUSGenerator gopter.Gen

// Product_STATUSGenerator returns a generator of Product_STATUS instances for property testing.
func Product_STATUSGenerator() gopter.Gen {
	if product_STATUSGenerator != nil {
		return product_STATUSGenerator
	}

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForProduct_STATUS(generators)
	product_STATUSGenerator = gen.Struct(reflect.TypeOf(Product_STATUS{}), generators)

	return product_STATUSGenerator
}

// AddIndependentPropertyGeneratorsForProduct_STATUS is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForProduct_STATUS(gens map[string]gopter.Gen) {
	gens["ApprovalRequired"] = gen.PtrOf(gen.Bool())
	gens["Description"] = gen.PtrOf(gen.AlphaString())
	gens["DisplayName"] = gen.PtrOf(gen.AlphaString())
	gens["Id"] = gen.PtrOf(gen.AlphaString())
	gens["Name"] = gen.PtrOf(gen.AlphaString())
	gens["State"] = gen.PtrOf(gen.AlphaString())
	gens["SubscriptionRequired"] = gen.PtrOf(gen.Bool())
	gens["SubscriptionsLimit"] = gen.PtrOf(gen.Int())
	gens["Terms"] = gen.PtrOf(gen.AlphaString())
	gens["Type"] = gen.PtrOf(gen.AlphaString())
}

func Test_Product_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 Product_Spec via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForProduct_Spec, Product_SpecGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual Product_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 Product_Spec instances for property testing - lazily instantiated by Product_SpecGenerator()
var product_SpecGenerator gopter.Gen

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

	generators := make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForProduct_Spec(generators)
	product_SpecGenerator = gen.Struct(reflect.TypeOf(Product_Spec{}), generators)

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForProduct_Spec(generators)
	AddRelatedPropertyGeneratorsForProduct_Spec(generators)
	product_SpecGenerator = gen.Struct(reflect.TypeOf(Product_Spec{}), generators)

	return product_SpecGenerator
}

// AddIndependentPropertyGeneratorsForProduct_Spec is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForProduct_Spec(gens map[string]gopter.Gen) {
	gens["ApprovalRequired"] = gen.PtrOf(gen.Bool())
	gens["AzureName"] = gen.AlphaString()
	gens["Description"] = gen.PtrOf(gen.AlphaString())
	gens["DisplayName"] = gen.PtrOf(gen.AlphaString())
	gens["OriginalVersion"] = gen.AlphaString()
	gens["State"] = gen.PtrOf(gen.AlphaString())
	gens["SubscriptionRequired"] = gen.PtrOf(gen.Bool())
	gens["SubscriptionsLimit"] = gen.PtrOf(gen.Int())
	gens["Terms"] = gen.PtrOf(gen.AlphaString())
}

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