From a413ae90a5e59d5b52e2da21d6e9eedb85a6a981 Mon Sep 17 00:00:00 2001
From: Piotr Zajac
Date: Mon, 7 Jul 2025 22:59:49 +0200
Subject: [PATCH 1/7] Prepare documentation
---
docs/attributes/auto-mock-data-attribute.md | 30 ++++++++++
docs/attributes/customize-with-attribute.md | 44 ++++++++++++++
docs/attributes/customize-with-t-attribute.md | 53 +++++++++++++++++
docs/attributes/except-attribute.md | 13 +++++
.../ignore-virtual-members-attribute.md | 36 ++++++++++++
docs/attributes/index.md | 19 ++++++
.../inline-auto-mock-data-attribute.md | 34 +++++++++++
.../member-auto-mock-data-attribute.md | 58 +++++++++++++++++++
docs/attributes/pick-from-range-attribute.md | 13 +++++
docs/attributes/pick-from-values-attribute.md | 14 +++++
docs/attributes/pick-negative-attribute.md | 15 +++++
docs/index.md | 9 +++
docs/supported-mocking-libraries.md | 7 +++
docs/tips-and-tricks.md | 44 ++++++++++++++
14 files changed, 389 insertions(+)
create mode 100644 docs/attributes/auto-mock-data-attribute.md
create mode 100644 docs/attributes/customize-with-attribute.md
create mode 100644 docs/attributes/customize-with-t-attribute.md
create mode 100644 docs/attributes/except-attribute.md
create mode 100644 docs/attributes/ignore-virtual-members-attribute.md
create mode 100644 docs/attributes/index.md
create mode 100644 docs/attributes/inline-auto-mock-data-attribute.md
create mode 100644 docs/attributes/member-auto-mock-data-attribute.md
create mode 100644 docs/attributes/pick-from-range-attribute.md
create mode 100644 docs/attributes/pick-from-values-attribute.md
create mode 100644 docs/attributes/pick-negative-attribute.md
create mode 100644 docs/index.md
create mode 100644 docs/supported-mocking-libraries.md
create mode 100644 docs/tips-and-tricks.md
diff --git a/docs/attributes/auto-mock-data-attribute.md b/docs/attributes/auto-mock-data-attribute.md
new file mode 100644
index 00000000..a87bd2a2
--- /dev/null
+++ b/docs/attributes/auto-mock-data-attribute.md
@@ -0,0 +1,30 @@
+# AutoMockData Attribute
+
+Provides auto-generated data specimens generated by [AutoFixture](https://github.com/AutoFixture/AutoFixture) with a mocking library as an extension to xUnit.net's `Theory` attribute.
+
+## Arguments
+
+- `IgnoreVirtualMembers` - disables generation of members marked as `virtual`; by default set to `false`
+
+## Example
+
+```csharp
+[Theory]
+[AutoMockData]
+public void GivenCurrencyConverter_WhenConvertToPln_ThenMustReturnCorrectConvertedAmount(
+ string testCurrencySymbol,
+ [Frozen] ICurrencyExchangeProvider currencyProvider,
+ CurrencyConverter currencyConverter)
+{
+ // Arrange
+ Mock.Get(currencyProvider)
+ .Setup(cp => cp.GetCurrencyExchangeRate(testCurrencySymbol))
+ .Returns(100M);
+
+ // Act
+ decimal result = currencyConverter.ConvertToPln(testCurrencySymbol, 100M);
+
+ // Assert
+ Assert.Equal(10000M, result);
+}
+```
diff --git a/docs/attributes/customize-with-attribute.md b/docs/attributes/customize-with-attribute.md
new file mode 100644
index 00000000..59af45ad
--- /dev/null
+++ b/docs/attributes/customize-with-attribute.md
@@ -0,0 +1,44 @@
+# CustomizeWith Attribute
+
+An attribute that can be applied to parameters in an `AutoDataAttribute`-driven `Theory` to apply additional customization when the `IFixture` creates an instance of that type.
+
+## Arguments
+
+- `IncludeParameterType` - indicates whether attribute target parameter `Type` should be included as a first argument when creating customization; by default set to `false`
+
+**Caution:** Order is important! Applying `CustomizeWith` attribute to the subsequent parameter makes preceding parameters of the same type to be created without specified customization and the particular parameter with the specified customization.
+
+## Example
+
+```csharp
+public class LocalDatesCustomization : ICustomization
+{
+ public void Customize(IFixture fixture)
+ {
+ fixture.Register(() => LocalDate.FromDateTime(fixture.Create()));
+ }
+}
+```
+
+```csharp
+[Theory]
+[InlineAutoMockData("USD")]
+[InlineAutoMockData("EUR")]
+public void GivenCurrencyConverter_WhenConvertToPlnAtParticularDay_ThenMustReturnCorrectConvertedAmount(
+ string testCurrencySymbol,
+ [CustomizeWith(typeof(LocalDatesCustomization))] LocalDate day,
+ [Frozen] ICurrencyExchangeProvider currencyProvider,
+ CurrencyConverter currencyConverter)
+{
+ // Arrange
+ Mock.Get(currencyProvider)
+ .Setup(cp => cp.GetCurrencyExchangeRate(testCurrencySymbol, day))
+ .Returns(100M);
+
+ // Act
+ decimal result = currencyConverter.ConvertToPln(testCurrencySymbol, 100M, day);
+
+ // Assert
+ Assert.Equal(10000M, result);
+}
+```
diff --git a/docs/attributes/customize-with-t-attribute.md b/docs/attributes/customize-with-t-attribute.md
new file mode 100644
index 00000000..62e4f214
--- /dev/null
+++ b/docs/attributes/customize-with-t-attribute.md
@@ -0,0 +1,53 @@
+# CustomizeWith\ Attribute
+
+A generic version of the `CustomizeWith` attribute has been introduced for ease of use. The same rules apply as for the non-generic version.
+
+## Example
+
+```csharp
+public class EmptyCollectionCustomization : ICustomization
+{
+ public EmptyCollectionCustomization(Type reflectedType)
+ {
+ this.ReflectedType = reflectedType;
+ }
+
+ public Type ReflectedType { get; }
+
+ public void Customize(IFixture fixture)
+ {
+ var emptyArray = Array.CreateInstance(this.ReflectedType.GenericTypeArguments.Single(), 0);
+
+ fixture.Customizations.Add(
+ new FilteringSpecimenBuilder(
+ new FixedBuilder(emptyArray),
+ new ExactTypeSpecification(this.ReflectedType)));
+ }
+}
+```
+
+```csharp
+public sealed class EmptyCollectionAttribute : CustomizeWithAttribute
+{
+ public EmptyCollectionAttribute()
+ {
+ this.IncludeParameterType = true;
+ }
+}
+```
+
+```csharp
+[Theory]
+[AutoData]
+public void CustomizeWithAttributeUsage(
+ IList firstStore,
+ [EmptyCollection] IList secondStore,
+ IList thirdStore,
+ IList fourthStore)
+{
+ Assert.NotEmpty(firstStore);
+ Assert.Empty(secondStore);
+ Assert.Empty(thirdStore);
+ Assert.NotEmpty(fourthStore);
+}
+```
diff --git a/docs/attributes/except-attribute.md b/docs/attributes/except-attribute.md
new file mode 100644
index 00000000..182c2fa4
--- /dev/null
+++ b/docs/attributes/except-attribute.md
@@ -0,0 +1,13 @@
+# Except Attribute
+
+Ensures that values from outside the specified list will be generated.
+
+```csharp
+[Theory]
+[AutoData]
+public void ExceptAttributeUsage(
+ [Except(DayOfWeek.Saturday, DayOfWeek.Sunday)] DayOfWeek workday)
+{
+ Assert.True(workday is >= DayOfWeek.Monday and <= DayOfWeek.Friday);
+}
+```
diff --git a/docs/attributes/ignore-virtual-members-attribute.md b/docs/attributes/ignore-virtual-members-attribute.md
new file mode 100644
index 00000000..b1232858
--- /dev/null
+++ b/docs/attributes/ignore-virtual-members-attribute.md
@@ -0,0 +1,36 @@
+# IgnoreVirtualMembers Attribute
+
+An attribute that can be applied to parameters in an `AutoDataAttribute`-driven `Theory` to indicate that the parameter value should not have `virtual` properties populated when the `IFixture` creates an instance of that type.
+
+This attribute allows to disable the generation of members marked as `virtual` on a decorated type whereas `IgnoreVirtualMembers` arguments of mocking attributes mentioned above disable such a generation for all types created by `IFixture`.
+
+**Caution:** Order is important! Applying `IgnoreVirtualMembers` attribute to the subsequent parameter makes preceding parameters of the same type to have `virtual` properties populated and the particular parameter with the following ones of the same type to have `virtual` properties unpopulated.
+
+## Example
+
+```csharp
+public class User
+{
+ public string Name { get; set; }
+ public virtual Address Address { get; set; }
+}
+```
+
+```csharp
+[Theory]
+[AutoData]
+public void IgnoreVirtualMembersUsage(
+ User firstUser,
+ [IgnoreVirtualMembers] User secondUser,
+ User thirdUser)
+{
+ Assert.NotNull(firstUser.Name);
+ Assert.NotNull(firstUser.Address);
+
+ Assert.NotNull(secondUser.Name);
+ Assert.Null(secondUser.Address);
+
+ Assert.NotNull(thirdUser.Name);
+ Assert.Null(thirdUser.Address);
+}
+```
diff --git a/docs/attributes/index.md b/docs/attributes/index.md
new file mode 100644
index 00000000..9f701f4e
--- /dev/null
+++ b/docs/attributes/index.md
@@ -0,0 +1,19 @@
+# Attributes Overview
+
+This section describes the main attributes provided by AutoFixture.XUnit2.AutoMock for use in your xUnit tests:
+
+## Test Method Attributes
+
+- [AutoMockData](auto-mock-data-attribute.md): Provides auto-generated data specimens using AutoFixture and a mocking library.
+- [InlineAutoMockData](inline-auto-mock-data-attribute.md): Combines inline values with auto-generated data specimens.
+- [MemberAutoMockData](member-auto-mock-data-attribute.md): Uses static members as data sources, combined with auto-generated data.
+- [IgnoreVirtualMembers](ignore-virtual-members-attribute.md): Disables generation of virtual members for a parameter or globally.
+- [CustomizeWith](customize-with-attribute.md): Applies additional customization to a parameter.
+- [CustomizeWith\](customize-with-t-attribute.md): Generic version of CustomizeWith for ease of use.
+
+## Data Filtering Attributes
+
+- [Except](except-attribute.md): Ensures values from outside the specified list will be generated.
+- [PickFromRange](pick-from-range-attribute.md): Ensures only values from a specified range will be generated.
+- [PickNegative](pick-negative-attribute.md): Ensures only negative values will be generated.
+- [PickFromValues](pick-from-values-attribute.md): Ensures only values from the specified list will be generated.
diff --git a/docs/attributes/inline-auto-mock-data-attribute.md b/docs/attributes/inline-auto-mock-data-attribute.md
new file mode 100644
index 00000000..dae70e93
--- /dev/null
+++ b/docs/attributes/inline-auto-mock-data-attribute.md
@@ -0,0 +1,34 @@
+# InlineAutoMockData Attribute
+
+Provides a data source for a `Theory`, with the data coming from inline values combined with auto-generated data specimens generated by [AutoFixture](https://github.com/AutoFixture/AutoFixture) with a mocking library.
+
+## Arguments
+
+- `IgnoreVirtualMembers` - disables generation of members marked as `virtual`; by default set to `false`
+
+## Example
+
+```csharp
+[Theory]
+[InlineAutoMockData("USD", 3, 10, 30)]
+[InlineAutoMockData("EUR", 4, 20, 80)]
+public void GivenCurrencyConverter_WhenConvertToPln_ThenMustReturnCorrectConvertedAmount(
+ string testCurrencySymbol,
+ decimal exchangeRate,
+ decimal currencyAmount,
+ decimal expectedPlnAmount,
+ [Frozen] ICurrencyExchangeProvider currencyProvider,
+ CurrencyConverter currencyConverter)
+{
+ // Arrange
+ Mock.Get(currencyProvider)
+ .Setup(cp => cp.GetCurrencyExchangeRate(testCurrencySymbol))
+ .Returns(exchangeRate);
+
+ // Act
+ decimal result = currencyConverter.ConvertToPln(testCurrencySymbol, currencyAmount);
+
+ // Assert
+ Assert.Equal(expectedPlnAmount, result);
+}
+```
diff --git a/docs/attributes/member-auto-mock-data-attribute.md b/docs/attributes/member-auto-mock-data-attribute.md
new file mode 100644
index 00000000..09a21626
--- /dev/null
+++ b/docs/attributes/member-auto-mock-data-attribute.md
@@ -0,0 +1,58 @@
+# MemberAutoMockData Attribute
+
+Provides a data source for a `Theory`, with the data coming from one of the following sources:
+
+- A static property
+- A static field
+- A static method (with parameters)
+
+combined with auto-generated data specimens generated by [AutoFixture](https://github.com/AutoFixture/AutoFixture) with a mocking library.
+
+The member must return something compatible with `Enumerable