// 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_WorkspaceConnectionProps_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 WorkspaceConnectionProps_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForWorkspaceConnectionProps_STATUS, WorkspaceConnectionProps_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual WorkspaceConnectionProps_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 WorkspaceConnectionProps_STATUS instances for property testing - lazily instantiated by
// WorkspaceConnectionProps_STATUSGenerator()
var workspaceConnectionProps_STATUSGenerator gopter.Gen

// WorkspaceConnectionProps_STATUSGenerator returns a generator of WorkspaceConnectionProps_STATUS instances for property testing.
func WorkspaceConnectionProps_STATUSGenerator() gopter.Gen {
	if workspaceConnectionProps_STATUSGenerator != nil {
		return workspaceConnectionProps_STATUSGenerator
	}

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

	return workspaceConnectionProps_STATUSGenerator
}

// AddIndependentPropertyGeneratorsForWorkspaceConnectionProps_STATUS is a factory method for creating gopter generators
func AddIndependentPropertyGeneratorsForWorkspaceConnectionProps_STATUS(gens map[string]gopter.Gen) {
	gens["AuthType"] = gen.PtrOf(gen.AlphaString())
	gens["Category"] = gen.PtrOf(gen.AlphaString())
	gens["Target"] = gen.PtrOf(gen.AlphaString())
	gens["Value"] = gen.PtrOf(gen.AlphaString())
	gens["ValueFormat"] = gen.PtrOf(gen.OneConstOf(WorkspaceConnectionProps_ValueFormat_STATUS_JSON))
}

func Test_WorkspacesConnection_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 WorkspacesConnection_STATUS via JSON returns original",
		prop.ForAll(RunJSONSerializationTestForWorkspacesConnection_STATUS, WorkspacesConnection_STATUSGenerator()))
	properties.TestingRun(t, gopter.NewFormatedReporter(true, 240, os.Stdout))
}

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

	// Deserialize back into memory
	var actual WorkspacesConnection_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 WorkspacesConnection_STATUS instances for property testing - lazily instantiated by
// WorkspacesConnection_STATUSGenerator()
var workspacesConnection_STATUSGenerator gopter.Gen

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

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

	// The above call to gen.Struct() captures the map, so create a new one
	generators = make(map[string]gopter.Gen)
	AddIndependentPropertyGeneratorsForWorkspacesConnection_STATUS(generators)
	AddRelatedPropertyGeneratorsForWorkspacesConnection_STATUS(generators)
	workspacesConnection_STATUSGenerator = gen.Struct(reflect.TypeOf(WorkspacesConnection_STATUS{}), generators)

	return workspacesConnection_STATUSGenerator
}

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

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