From 188389545c9686a2717b24819d80393c3103e707 Mon Sep 17 00:00:00 2001
From: Werebunny <18252929+Werebunny@users.noreply.github.com>
Date: Sun, 10 Nov 2024 13:11:19 -0700
Subject: [PATCH 001/330] * Fix #123: Add Immutable & Frozen Support. * Add
options to all tools. * Support comparing collection type. * Support ignoring
equatable comparisons.
---
docs/pages/General-V2Migration.md | 20 +++
src/CreateAndFake/Attributes/SizeAttribute.cs | 1 -
.../Design/Content/IToolOptions.cs | 8 +
src/CreateAndFake/Design/Data/NameData.cs | 2 +-
.../Design/Randomization/DataRandom.cs | 2 +-
.../Design/Randomization/ValueRandom.cs | 10 +-
.../Extensions/AssertExtensions.cs | 16 +-
.../Extensions/CreateExtensions.cs | 4 +-
.../CompilerFeatureRequiredAttribute.cs | 31 ++++
.../Properties/IsExternalInit.cs | 17 ++
.../Properties/RequiredMemberAttribute.cs | 15 ++
.../SetsRequiredMembersAttribute.cs | 15 ++
.../Toolbox/AsserterTool/Asserter.cs | 42 ++---
.../Toolbox/AsserterTool/AsserterOptions.cs | 15 ++
.../AsserterTool/Fluent/AssertBehavior.cs | 5 +-
.../AsserterTool/Fluent/AssertBehaviorBase.cs | 17 +-
.../AsserterTool/Fluent/AssertChainer.cs | 23 ++-
.../AsserterTool/Fluent/AssertComparable.cs | 5 +-
.../Fluent/AssertComparableBase.cs | 23 ++-
.../AsserterTool/Fluent/AssertError.cs | 5 +-
.../AsserterTool/Fluent/AssertErrorBase.cs | 11 +-
.../AsserterTool/Fluent/AssertGroup.cs | 4 +-
.../AsserterTool/Fluent/AssertGroupBase.cs | 30 ++--
.../AsserterTool/Fluent/AssertObject.cs | 7 +-
.../AsserterTool/Fluent/AssertObjectBase.cs | 33 ++--
.../Toolbox/AsserterTool/Fluent/AssertText.cs | 5 +-
.../AsserterTool/Fluent/AssertTextBase.cs | 19 +-
.../Toolbox/AsserterTool/Fluent/AssertType.cs | 5 +-
.../AsserterTool/Fluent/AssertTypeBase.cs | 15 +-
.../CopyHints/DeepCloneableCopyHint.cs | 2 +-
.../CopyHints/FrozenCollectionCopyHint.cs | 77 +++++++++
.../CopyHints/ImmutableCollectionCopyHint.cs | 89 ++++++++++
.../Toolbox/DuplicatorTool/Duplicator.cs | 69 ++++----
.../DuplicatorTool/DuplicatorChainer.cs | 9 +-
.../DuplicatorTool/DuplicatorOptions.cs | 18 ++
.../Toolbox/DuplicatorTool/IDuplicator.cs | 11 +-
src/CreateAndFake/Toolbox/FakerTool/Faker.cs | 13 +-
.../Toolbox/FakerTool/FakerOptions.cs | 11 ++
src/CreateAndFake/Toolbox/FakerTool/IFaker.cs | 3 +
.../Toolbox/FakerTool/Proxy/CallData.cs | 11 +-
.../Toolbox/MutatorTool/IMutator.cs | 3 +
.../Toolbox/MutatorTool/Mutator.cs | 32 ++--
.../Toolbox/MutatorTool/MutatorOptions.cs | 26 +++
.../RandomizerTool/CreateCollectionHint.cs | 9 -
.../CreateHints/AsyncCollectionCreateHint.cs | 41 ++---
.../CreateHints/CollectionCreateHint.cs | 17 +-
.../CreateHints/CommonSystemCreateHint.cs | 14 +-
.../CreateHints/EnumCreateHint.cs | 2 +-
.../CreateHints/ExceptionCreateHint.cs | 2 +-
.../CreateHints/FakeCreateHint.cs | 2 +-
.../CreateHints/FakedCreateHint.cs | 2 +-
.../CreateHints/FrozenCollectionCreateHint.cs | 42 +++++
.../CreateHints/GenericCreateHint.cs | 6 +-
.../ImmutableCollectionCreateHint.cs | 113 ++++++++++++
.../CreateHints/InjectedCreateHint.cs | 4 +-
.../CreateHints/LegacyCollectionCreateHint.cs | 16 +-
.../CreateHints/ObjectCreateHint.cs | 12 +-
.../CreateHints/OptionsCreateHint.cs | 23 +++
.../CreateHints/StringCreateHint.cs | 18 +-
.../CreateHints/ValueCreateHint.cs | 4 +-
.../Toolbox/RandomizerTool/IRandomizer.cs | 37 +---
.../RandomizerTool/MethodCallWrapper.cs | 38 +---
.../Toolbox/RandomizerTool/Randomizer.cs | 162 ++++++------------
.../RandomizerTool/RandomizerChainer.cs | 61 +++----
.../RandomizerTool/RandomizerOptions.cs | 89 ++++++++++
.../Toolbox/TesterTool/Tester.cs | 82 ++++-----
.../Toolbox/TesterTool/TesterOptions.cs | 30 ++++
src/CreateAndFake/Toolbox/ToolSet.cs | 15 +-
.../AsyncEnumerableCompareHint.cs | 5 +
.../CompareHints/DictionaryCompareHint.cs | 7 +-
.../CompareHints/EarlyFailCompareHint.cs | 5 +-
.../CompareHints/EnumerableCompareHint.cs | 5 +
.../CompareHints/EquatableCompareHint.cs | 9 +-
.../CompareHints/ValueEquatableCompareHint.cs | 2 +-
.../ValuerEquatableCompareHint.cs | 2 +-
.../Toolbox/ValuerTool/IValuer.cs | 30 ++--
.../Toolbox/ValuerTool/Valuer.cs | 88 ++++++----
.../Toolbox/ValuerTool/ValuerChainer.cs | 13 +-
.../Toolbox/ValuerTool/ValuerOptions.cs | 21 +++
.../Attributes/RandomDataAttributeTests.cs | 5 +-
.../Extensions/AssertExtensionsTests.cs | 6 +
.../IssueReplication/000-050/Issue001Tests.cs | 2 +-
.../IssueReplication/000-050/Issue028Tests.cs | 5 +-
.../IssueReplication/050-100/Issue052Tests.cs | 16 +-
.../IssueReplication/050-100/Issue094Tests.cs | 32 ++++
.../IssueReplication/100-150/Issue109Tests.cs | 6 +-
.../IssueReplication/100-150/Issue123Tests.cs | 19 ++
.../TestBases/CompareHintTestBase.cs | 4 +-
.../TestBases/CopyHintTestBase.cs | 2 +-
.../TestBases/CreateHintTestBase.cs | 12 +-
.../TestBases/ValueRandomTestBase.cs | 7 +
.../TestSamples/ValuerEquatableSample.cs | 2 +-
.../Toolbox/AsserterTool/AsserterTests.cs | 5 +-
.../AsserterTool/Fluent/AssertChainerTests.cs | 2 +-
.../FrozenCollectionCopyHintTests.cs | 14 ++
.../ImmutableCollectionCopyHintTests.cs | 14 ++
.../Toolbox/DuplicatorTool/DuplicatorTests.cs | 43 +++--
.../Toolbox/FakerTool/BehaviorTests.cs | 4 +-
.../Toolbox/FakerTool/Fake[T]Tests.cs | 4 +-
.../Toolbox/FakerTool/FakerTests.cs | 2 +-
.../Toolbox/MutatorTool/MutatorTests.cs | 18 +-
.../FrozenCollectionCreateHintTests.cs | 50 ++++++
.../ImmutableCollectionCreateHintTests.cs | 53 ++++++
.../CreateHints/OptionsCreateHintTests.cs | 16 ++
.../CreateHints/StringCreateHintTests.cs | 33 ++--
.../RandomizerTool/RandomizerChainerTests.cs | 3 +-
.../Toolbox/RandomizerTool/RandomizerTests.cs | 97 +++--------
.../Toolbox/TesterTool/TesterTests.cs | 29 ++--
.../Toolbox/ValuerTool/ValuerTests.cs | 83 ++++++---
109 files changed, 1547 insertions(+), 848 deletions(-)
create mode 100644 docs/pages/General-V2Migration.md
create mode 100644 src/CreateAndFake/Design/Content/IToolOptions.cs
create mode 100644 src/CreateAndFake/Properties/CompilerFeatureRequiredAttribute.cs
create mode 100644 src/CreateAndFake/Properties/IsExternalInit.cs
create mode 100644 src/CreateAndFake/Properties/RequiredMemberAttribute.cs
create mode 100644 src/CreateAndFake/Properties/SetsRequiredMembersAttribute.cs
create mode 100644 src/CreateAndFake/Toolbox/AsserterTool/AsserterOptions.cs
create mode 100644 src/CreateAndFake/Toolbox/DuplicatorTool/CopyHints/FrozenCollectionCopyHint.cs
create mode 100644 src/CreateAndFake/Toolbox/DuplicatorTool/CopyHints/ImmutableCollectionCopyHint.cs
create mode 100644 src/CreateAndFake/Toolbox/DuplicatorTool/DuplicatorOptions.cs
create mode 100644 src/CreateAndFake/Toolbox/FakerTool/FakerOptions.cs
create mode 100644 src/CreateAndFake/Toolbox/MutatorTool/MutatorOptions.cs
delete mode 100644 src/CreateAndFake/Toolbox/RandomizerTool/CreateCollectionHint.cs
create mode 100644 src/CreateAndFake/Toolbox/RandomizerTool/CreateHints/FrozenCollectionCreateHint.cs
create mode 100644 src/CreateAndFake/Toolbox/RandomizerTool/CreateHints/ImmutableCollectionCreateHint.cs
create mode 100644 src/CreateAndFake/Toolbox/RandomizerTool/CreateHints/OptionsCreateHint.cs
create mode 100644 src/CreateAndFake/Toolbox/RandomizerTool/RandomizerOptions.cs
create mode 100644 src/CreateAndFake/Toolbox/TesterTool/TesterOptions.cs
create mode 100644 src/CreateAndFake/Toolbox/ValuerTool/ValuerOptions.cs
create mode 100644 tests/CreateAndFakeTests/IssueReplication/050-100/Issue094Tests.cs
create mode 100644 tests/CreateAndFakeTests/IssueReplication/100-150/Issue123Tests.cs
create mode 100644 tests/CreateAndFakeTests/Toolbox/DuplicatorTool/CopyHints/FrozenCollectionCopyHintTests.cs
create mode 100644 tests/CreateAndFakeTests/Toolbox/DuplicatorTool/CopyHints/ImmutableCollectionCopyHintTests.cs
create mode 100644 tests/CreateAndFakeTests/Toolbox/RandomizerTool/CreateHints/FrozenCollectionCreateHintTests.cs
create mode 100644 tests/CreateAndFakeTests/Toolbox/RandomizerTool/CreateHints/ImmutableCollectionCreateHintTests.cs
create mode 100644 tests/CreateAndFakeTests/Toolbox/RandomizerTool/CreateHints/OptionsCreateHintTests.cs
diff --git a/docs/pages/General-V2Migration.md b/docs/pages/General-V2Migration.md
new file mode 100644
index 00000000..d5f46b0e
--- /dev/null
+++ b/docs/pages/General-V2Migration.md
@@ -0,0 +1,20 @@
+# Migrating v1 -> v2
+
+This doc details the changes necessary to migrate a code base using 1.x.x versions to version 2.0.0.
+
+No changes are needed if the code base compiles. Changes are mainly required for code customizing the tools instead of using the default set with their default configurations.
+
+## Why
+
+In general, backwards compatibility is a high priority for normal releases. This leads to wanting new behavior be customizable and restricted to changes not breaking the existing API. Tools are highly configurable, but the methodology was found to be lacking especially when only wanting a change on a case by case basis. Using configuration records with optional fluent per method customization resolves these issues.
+
+## Randomizer Changes
+
+```c#
+/// Test that will fail.
+[Theory, RandomData]
+public void Tools_DataSampleExample(DataSample original)
+{
+ Tools.Asserter.Is(original, Tools.Mutator.Variant(original));
+}
+```
diff --git a/src/CreateAndFake/Attributes/SizeAttribute.cs b/src/CreateAndFake/Attributes/SizeAttribute.cs
index d9fd9e7d..c2df5b2b 100644
--- a/src/CreateAndFake/Attributes/SizeAttribute.cs
+++ b/src/CreateAndFake/Attributes/SizeAttribute.cs
@@ -3,7 +3,6 @@ namespace CreateAndFake;
/// Flag to create the attached collection with items.
///
///
-///
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
public sealed class SizeAttribute(int count) : Attribute
{
diff --git a/src/CreateAndFake/Design/Content/IToolOptions.cs b/src/CreateAndFake/Design/Content/IToolOptions.cs
new file mode 100644
index 00000000..b5f5dc75
--- /dev/null
+++ b/src/CreateAndFake/Design/Content/IToolOptions.cs
@@ -0,0 +1,8 @@
+#pragma warning disable CA1040 // Avoid empty interfaces: For identifying option records.
+
+namespace CreateAndFake.Design.Content;
+
+/// Configuration for controlling tool behavior.
+public interface IToolOptions { }
+
+#pragma warning restore CA1040 // Avoid empty interfaces.
diff --git a/src/CreateAndFake/Design/Data/NameData.cs b/src/CreateAndFake/Design/Data/NameData.cs
index 9599aa02..9f6b01cf 100644
--- a/src/CreateAndFake/Design/Data/NameData.cs
+++ b/src/CreateAndFake/Design/Data/NameData.cs
@@ -4,7 +4,7 @@ namespace CreateAndFake.Design.Data;
public static class NameData
{
/// Possible names for randomization.
- public static ICollection Values { get; } =
+ public static IReadOnlyCollection Values { get; } =
[
// Aa
"Aaron",
diff --git a/src/CreateAndFake/Design/Randomization/DataRandom.cs b/src/CreateAndFake/Design/Randomization/DataRandom.cs
index 30c11ccf..1131316a 100644
--- a/src/CreateAndFake/Design/Randomization/DataRandom.cs
+++ b/src/CreateAndFake/Design/Randomization/DataRandom.cs
@@ -17,7 +17,7 @@ public sealed class DataRandom
};
/// All searchable names.
- internal static ICollection SupportedProperties => _Matcher.Keys;
+ internal static IReadOnlyCollection SupportedProperties => _Matcher.Keys;
///
private readonly IRandom _gen;
diff --git a/src/CreateAndFake/Design/Randomization/ValueRandom.cs b/src/CreateAndFake/Design/Randomization/ValueRandom.cs
index 1fa28e82..61a6d62d 100644
--- a/src/CreateAndFake/Design/Randomization/ValueRandom.cs
+++ b/src/CreateAndFake/Design/Randomization/ValueRandom.cs
@@ -48,7 +48,7 @@ private static T Create(ValueRandom gen, Func converter, shor
}
/// All supported value types.
- public static ICollection ValueTypes => _Gens.Keys;
+ public static IReadOnlyCollection ValueTypes => _Gens.Keys;
/// Flag to prevent generating invalid values (NaN, -∞ and +∞).
public bool OnlyValidValues { get; set; } = onlyValidValues;
@@ -179,6 +179,10 @@ public T NextItem(IEnumerable items)
{
return collection.ElementAt(Next(collection.Count));
}
+ else if (items is IReadOnlyCollection readOnlyCollection && readOnlyCollection.Count > 0)
+ {
+ return readOnlyCollection.ElementAt(Next(readOnlyCollection.Count));
+ }
else
{
return items.OrderBy(i => Next()).First();
@@ -197,6 +201,10 @@ public T NextItemOrDefault(IEnumerable? items)
{
return collection.ElementAt(Next(collection.Count))!;
}
+ else if (items is IReadOnlyCollection readOnlyCollection && readOnlyCollection.Count > 0)
+ {
+ return readOnlyCollection.ElementAt(Next(readOnlyCollection.Count))!;
+ }
else
{
return items.OrderBy(i => Next()).FirstOrDefault()!;
diff --git a/src/CreateAndFake/Extensions/AssertExtensions.cs b/src/CreateAndFake/Extensions/AssertExtensions.cs
index 10ddca4a..2c3afbb1 100644
--- a/src/CreateAndFake/Extensions/AssertExtensions.cs
+++ b/src/CreateAndFake/Extensions/AssertExtensions.cs
@@ -11,7 +11,7 @@ public static class AssertExtensions
/// Asserter to test with.
public static AssertObject Assert(this object? actual)
{
- return new AssertObject(Tools.Gen, Tools.Valuer, actual);
+ return new AssertObject(Tools.Asserter.Options, actual);
}
///
@@ -19,7 +19,7 @@ public static AssertObject Assert(this object? actual)
/// Asserter to test with.
public static AssertGroup Assert(this IEnumerable? collection)
{
- return new AssertGroup(Tools.Gen, Tools.Valuer, collection);
+ return new AssertGroup(Tools.Asserter.Options, collection);
}
///
@@ -27,7 +27,7 @@ public static AssertGroup Assert(this IEnumerable? collection)
/// Asserter to test with.
public static AssertText Assert(this string? text)
{
- return new AssertText(Tools.Gen, Tools.Valuer, text);
+ return new AssertText(Tools.Asserter.Options, text);
}
///
@@ -35,7 +35,7 @@ public static AssertText Assert(this string? text)
/// Asserter to test with.
public static AssertComparable Assert(this IComparable? value)
{
- return new AssertComparable(Tools.Gen, Tools.Valuer, value);
+ return new AssertComparable(Tools.Asserter.Options, value);
}
///
@@ -43,7 +43,7 @@ public static AssertComparable Assert(this IComparable? value)
/// Asserter to test with.
public static AssertType Assert(this Type? type)
{
- return new AssertType(Tools.Gen, Tools.Valuer, type);
+ return new AssertType(Tools.Asserter.Options, type);
}
///
@@ -51,7 +51,7 @@ public static AssertType Assert(this Type? type)
/// Asserter to test with.
public static AssertError Assert(this Exception? error)
{
- return new AssertError(Tools.Gen, Tools.Valuer, error);
+ return new AssertError(Tools.Asserter.Options, error);
}
///
@@ -59,7 +59,7 @@ public static AssertError Assert(this Exception? error)
/// Asserter to test with.
public static AssertBehavior Assert(this Action? behavior)
{
- return new AssertBehavior(Tools.Gen, Tools.Valuer, behavior);
+ return new AssertBehavior(Tools.Asserter.Options, behavior);
}
///
@@ -68,7 +68,7 @@ public static AssertBehavior Assert(this Action? behavior)
/// Asserter to test with.
public static AssertBehavior Assert(this Func? behavior)
{
- return new AssertBehavior(Tools.Gen, Tools.Valuer, behavior);
+ return new AssertBehavior(Tools.Asserter.Options, behavior);
}
/// Handles assertion calls for runtime .
diff --git a/src/CreateAndFake/Extensions/CreateExtensions.cs b/src/CreateAndFake/Extensions/CreateExtensions.cs
index 691e5aa6..035b5660 100644
--- a/src/CreateAndFake/Extensions/CreateExtensions.cs
+++ b/src/CreateAndFake/Extensions/CreateExtensions.cs
@@ -8,7 +8,7 @@ namespace CreateAndFake.Fluent;
/// Provides fluent randomization options.
public static class CreateExtensions
{
- ///
+ ///
[return: NotNullIfNotNull(nameof(source))]
public static T CreateDeepClone(this T source)
{
@@ -27,7 +27,7 @@ public static T CreateUnique(this T source)
return Tools.Mutator.Unique(source);
}
- ///
+ ///
public static object CreateRandomInstance(this Type type)
{
return Tools.Randomizer.Create(type);
diff --git a/src/CreateAndFake/Properties/CompilerFeatureRequiredAttribute.cs b/src/CreateAndFake/Properties/CompilerFeatureRequiredAttribute.cs
new file mode 100644
index 00000000..130c4ca5
--- /dev/null
+++ b/src/CreateAndFake/Properties/CompilerFeatureRequiredAttribute.cs
@@ -0,0 +1,31 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+#if LEGACY // Required feature shipped with C# 13 / .NET 11.0
+
+namespace System.Runtime.CompilerServices;
+
+///
+/// Indicates that compiler support for a particular feature is required for the location where this attribute is applied.
+///
+///
+[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
+internal sealed class CompilerFeatureRequiredAttribute(string featureName) : Attribute
+{
+ /// The name of the compiler feature.
+ public string FeatureName { get; } = featureName;
+
+ ///
+ /// If true, the compiler can choose to allow access to the location where
+ /// this attribute is applied if it does not understand .
+ ///
+ public bool IsOptional { get; init; }
+
+ /// The used for the ref structs C# feature.
+ public const string RefStructs = nameof(RefStructs);
+
+ /// The used for the required members C# feature.
+ public const string RequiredMembers = nameof(RequiredMembers);
+}
+
+#endif
diff --git a/src/CreateAndFake/Properties/IsExternalInit.cs b/src/CreateAndFake/Properties/IsExternalInit.cs
new file mode 100644
index 00000000..7e45a3e1
--- /dev/null
+++ b/src/CreateAndFake/Properties/IsExternalInit.cs
@@ -0,0 +1,17 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+#if LEGACY // Init type shipped with C# 7 / .NET 5.0
+
+using System.ComponentModel;
+
+namespace System.Runtime.CompilerServices;
+
+///
+/// Reserved to be used by the compiler for tracking metadata.
+/// This class should not be used by developers in source code.
+///
+[EditorBrowsable(EditorBrowsableState.Never)]
+internal sealed class IsExternalInit { }
+
+#endif
diff --git a/src/CreateAndFake/Properties/RequiredMemberAttribute.cs b/src/CreateAndFake/Properties/RequiredMemberAttribute.cs
new file mode 100644
index 00000000..c50042ef
--- /dev/null
+++ b/src/CreateAndFake/Properties/RequiredMemberAttribute.cs
@@ -0,0 +1,15 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+#if LEGACY // Required member shipped with C# 11 / .NET 7.0
+
+namespace System.Runtime.CompilerServices;
+
+/// Specifies that a type has required members or that a member is required.
+[AttributeUsage(
+ AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field | AttributeTargets.Property,
+ AllowMultiple = false,
+ Inherited = false)]
+internal sealed class RequiredMemberAttribute : Attribute { }
+
+#endif
diff --git a/src/CreateAndFake/Properties/SetsRequiredMembersAttribute.cs b/src/CreateAndFake/Properties/SetsRequiredMembersAttribute.cs
new file mode 100644
index 00000000..92bfb0b8
--- /dev/null
+++ b/src/CreateAndFake/Properties/SetsRequiredMembersAttribute.cs
@@ -0,0 +1,15 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+#if LEGACY // Required feature shipped with C# 13 / .NET 11.0
+
+namespace System.Diagnostics.CodeAnalysis;
+
+///
+/// Specifies that this constructor sets all required members for the current type,
+/// and callers do not need to set any required members themselves.
+///
+[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
+internal sealed class SetsRequiredMembersAttribute : Attribute { }
+
+#endif
diff --git a/src/CreateAndFake/Toolbox/AsserterTool/Asserter.cs b/src/CreateAndFake/Toolbox/AsserterTool/Asserter.cs
index 82bb9a0b..8f0b9dc1 100644
--- a/src/CreateAndFake/Toolbox/AsserterTool/Asserter.cs
+++ b/src/CreateAndFake/Toolbox/AsserterTool/Asserter.cs
@@ -1,22 +1,16 @@
using System.Collections;
using System.Diagnostics.CodeAnalysis;
-using CreateAndFake.Design.Randomization;
using CreateAndFake.Toolbox.AsserterTool.Fluent;
-using CreateAndFake.Toolbox.ValuerTool;
namespace CreateAndFake.Toolbox.AsserterTool;
/// Handles common test scenarios.
-///
-///
+///
/// If given a null parameter.
-public class Asserter(IRandom gen, IValuer valuer)
+public class Asserter(AsserterOptions options)
{
- /// Core randomizer with a potential seed for logging.
- protected IRandom Gen { get; } = gen ?? throw new ArgumentNullException(nameof(gen));
-
- /// Handles comparisons for assertion checks.
- protected IValuer Valuer { get; } = valuer ?? throw new ArgumentNullException(nameof(valuer));
+ /// Configured options for this.
+ public AsserterOptions Options { get; } = options ?? throw new ArgumentNullException(nameof(options));
/// Runs each case and aggregates exceptions.
/// Assert cases.
@@ -53,7 +47,7 @@ public virtual void CheckAll(params Action[] cases)
///
public virtual void Fail(string? details = null)
{
- throw new AssertException("Test failed.", details, Gen.InitialSeed);
+ throw new AssertException("Test failed.", details, Options.Gen.InitialSeed);
}
/// Throws an assert exception.
@@ -61,7 +55,7 @@ public virtual void Fail(string? details = null)
/// Optional failure details to include.
public virtual void Fail(Exception exception, string? details = null)
{
- throw new AssertException("Test failed.", details, Gen.InitialSeed, exception);
+ throw new AssertException("Test failed.", details, Options.Gen.InitialSeed, exception);
}
///
@@ -69,7 +63,7 @@ public virtual void Fail(Exception exception, string? details = null)
///
public void Is(object? expected, object? actual, string? details = null)
{
- _ = new AssertObject(Gen, Valuer, actual).Is(expected, details);
+ _ = new AssertObject(Options, actual).Is(expected, details);
}
///
@@ -77,7 +71,7 @@ public void Is(object? expected, object? actual, string? details = null)
///
public void IsNot(object? expected, object? actual, string? details = null)
{
- _ = new AssertObject(Gen, Valuer, actual).IsNot(expected, details);
+ _ = new AssertObject(Options, actual).IsNot(expected, details);
}
///
@@ -85,7 +79,7 @@ public void IsNot(object? expected, object? actual, string? details = null)
///
public virtual void IsEmpty(IEnumerable? collection, string? details = null)
{
- _ = new AssertGroup(Gen, Valuer, collection).IsEmpty(details);
+ _ = new AssertGroup(Options, collection).IsEmpty(details);
}
///
@@ -93,7 +87,7 @@ public virtual void IsEmpty(IEnumerable? collection, string? details = null)
///
public virtual void IsNotEmpty(IEnumerable? collection, string? details = null)
{
- _ = new AssertGroup(Gen, Valuer, collection).IsNotEmpty(details);
+ _ = new AssertGroup(Options, collection).IsNotEmpty(details);
}
///
@@ -101,7 +95,7 @@ public virtual void IsNotEmpty(IEnumerable? collection, string? details = null)
///
public virtual void HasCount(int count, IEnumerable? collection, string? details = null)
{
- _ = new AssertGroup(Gen, Valuer, collection).HasCount(count, details);
+ _ = new AssertGroup(Options, collection).HasCount(count, details);
}
///
@@ -109,7 +103,7 @@ public virtual void HasCount(int count, IEnumerable? collection, string? details
///
public virtual void ReferenceEqual(object? expected, object? actual, string? details = null)
{
- _ = new AssertObject(Gen, Valuer, actual).ReferenceEqual(expected, details);
+ _ = new AssertObject(Options, actual).ReferenceEqual(expected, details);
}
///
@@ -117,7 +111,7 @@ public virtual void ReferenceEqual(object? expected, object? actual, string? det
///
public virtual void ReferenceNotEqual(object? expected, object? actual, string? details = null)
{
- _ = new AssertObject(Gen, Valuer, actual).ReferenceNotEqual(expected, details);
+ _ = new AssertObject(Options, actual).ReferenceNotEqual(expected, details);
}
///
@@ -125,7 +119,7 @@ public virtual void ReferenceNotEqual(object? expected, object? actual, string?
///
public virtual void ValuesEqual(object? expected, object? actual, string? details = null)
{
- _ = new AssertObject(Gen, Valuer, actual).ValuesEqual(expected, details);
+ _ = new AssertObject(Options, actual).ValuesEqual(expected, details);
}
///
@@ -133,7 +127,7 @@ public virtual void ValuesEqual(object? expected, object? actual, string? detail
///
public virtual void ValuesNotEqual(object? expected, object? actual, string? details = null)
{
- _ = new AssertObject(Gen, Valuer, actual).ValuesNotEqual(expected, details);
+ _ = new AssertObject(Options, actual).ValuesNotEqual(expected, details);
}
///
@@ -141,20 +135,20 @@ public virtual void ValuesNotEqual(object? expected, object? actual, string? det
///
public virtual void AreUnique(object? expected, object? actual, string? details = null)
{
- _ = new AssertObject(Gen, Valuer, actual).UniqueFrom(expected, details);
+ _ = new AssertObject(Options, actual).UniqueFrom(expected, details);
}
///
///
public virtual T Throws(Action? behavior, string? details = null) where T : Exception
{
- return new AssertBehavior(Gen, Valuer, behavior).Throws(details);
+ return new AssertBehavior(Options, behavior).Throws(details);
}
///
///
public virtual T Throws(Func