Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
id: TASK-17
title: Consolidate duplicate Facts into Theories
status: Done
assignee:
- claude
- piotrzajac
created_date: '2026-04-21 08:21'
updated_date: '2026-04-21 11:06'
labels: []
dependencies: []
priority: low
---

## Acceptance Criteria
<!-- AC:BEGIN -->
- [x] #1 Identify all [Fact] methods across all test projects that test the same behavior with different inputs
- [x] #2 Replace duplicate Facts with a single [Theory] using [InlineData] or [MemberData]/[TheoryData] as appropriate
<!-- AC:END -->
2 changes: 1 addition & 1 deletion dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"rollForward": true
},
"dotnet-stryker": {
"version": "4.14.0",
"version": "4.14.1",
"commands": [
"dotnet-stryker"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,121 +1,114 @@
namespace Objectivity.AutoFixture.XUnit2.Core.Tests.Common
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

using global::AutoFixture.Xunit2;

using Objectivity.AutoFixture.XUnit2.Core.Common;

using Xunit;

[Collection("EnumerableExtensions")]
[Trait("Category", "Common")]
public class EnumerableExtensionsTests
{
[Fact(DisplayName = "GIVEN uninitialized argument WHEN TryGetEnumerableSingleTypeArgument is invoked THEN exception is thrown")]
[SuppressMessage("ReSharper", "UnusedVariable", Justification = "This is good enougth to test the logic.")]
public void GivenUninitializedArgument_WhenTryGetEnumerableSingleTypeArgumentIsInvoked_ThenExceptionIsThrown()
{
// Arrange
Type enumerableType = null;

// Act
object Act() => enumerableType.TryGetEnumerableSingleTypeArgument(out _);

// Assert
var exception = Assert.Throws<ArgumentNullException>(Act);
Assert.Equal("type", exception.ParamName);
}

[InlineData(typeof(int[]), typeof(int))]
[InlineData(typeof(List<int>), typeof(int))]
[InlineData(typeof(Dictionary<int, int>), typeof(KeyValuePair<int, int>))]
[InlineData(typeof(IEnumerable<int>), typeof(int))]
[Theory(DisplayName = "GIVEN valid collection WHEN TryGetEnumerableSingleTypeArgument is invoked THEN collection single type argument returned")]
public void GivenValidCollection_WhenTryGetEnumerableSingleTypeArgumentIsInvoked_ThenCollectionSingleTypeArgumentReturned(Type enumerableType, Type expectedType)
{
// Arrange
// Act
var isSuccessful = enumerableType.TryGetEnumerableSingleTypeArgument(out var itemType);

// Assert
Assert.True(isSuccessful);
Assert.Equal(expectedType, itemType);
}

[InlineData(typeof(Tuple<int, int>))]
[InlineData(typeof(IEnumerable))]
[Theory(DisplayName = "GIVEN invalid collection WHEN TryGetEnumerableSingleTypeArgument is invoked THEN no argument returned")]
public void GivenInvalidCollection_WhenTryGetEnumerableSingleTypeArgumentIsInvoked_ThenNoArgumentReturned(Type enumerableType)
{
// Arrange
// Act
var isSuccessful = enumerableType.TryGetEnumerableSingleTypeArgument(out _);

// Assert
Assert.False(isSuccessful);
}

[Fact(DisplayName = "GIVEN generic definition collection WHEN TryGetEnumerableSingleTypeArgument is invoked THEN no argument returned")]
public void GivenGenericDefinitionCollection_WhenTryGetEnumerableSingleTypeArgumentIsInvoked_ThenNoArgumentReturned()
{
// Arrange
var enumerableType = typeof(IEnumerable<int>).GetGenericTypeDefinition();

// Act
var isSuccessful = enumerableType.TryGetEnumerableSingleTypeArgument(out _);

// Assert
Assert.False(isSuccessful);
}

[InlineData(null, typeof(int), "items")]
[InlineData(new[] { 1 }, null, "itemType")]
[Theory(DisplayName = "GIVEN uninitialized argument WHEN ToTypedArray is invoked THEN exception is thrown")]
public void GivenUninitializedArgument_WhenToTypedArrayIsInvoked_ThenExceptionIsThrown(
IEnumerable items,
Type itemType,
string exceptionParamName)
{
// Arrange
// Act
object Act() => items.ToTypedArray(itemType);

// Assert
var exception = Assert.Throws<ArgumentNullException>(Act);
Assert.Equal(exceptionParamName, exception.ParamName);
}

[AutoData]
[Theory(DisplayName = "GIVEN typed enumerable WHEN ToTypedArray is invoked THEN array is returned")]
public void GivenTypedEnumerable_WhenToTypedArrayIsInvoked_ThenArrayIsReturned(int[] items)
{
// Arrange
var itemType = typeof(int);

// Act
var array = items.ToTypedArray(itemType);

// Assert
Assert.Equal(items, array);
Assert.True(array.GetType().IsArray);
}

[AutoData]
[Theory(DisplayName = "GIVEN enumerable WHEN ToTypedArray is invoked THEN array is returned")]
public void GivenEnumerable_WhenToTypedArrayIsInvoked_ThenArrayIsReturned(BitArray items)
{
// Arrange
var itemType = typeof(bool);

// Act
var array = items.ToTypedArray(itemType);

// Assert
Assert.Equal(items, array);
}
}
}
namespace Objectivity.AutoFixture.XUnit2.Core.Tests.Common
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

using global::AutoFixture.Xunit2;

using Objectivity.AutoFixture.XUnit2.Core.Common;

using Xunit;

[Collection("EnumerableExtensions")]
[Trait("Category", "Common")]
public class EnumerableExtensionsTests
{
public static TheoryData<Type> InvalidCollectionTestData { get; } = new()
{
typeof(Tuple<int, int>),
typeof(IEnumerable),
typeof(IEnumerable<int>).GetGenericTypeDefinition(),
};

[Fact(DisplayName = "GIVEN uninitialized argument WHEN TryGetEnumerableSingleTypeArgument is invoked THEN exception is thrown")]
[SuppressMessage("ReSharper", "UnusedVariable", Justification = "This is good enougth to test the logic.")]
public void GivenUninitializedArgument_WhenTryGetEnumerableSingleTypeArgumentIsInvoked_ThenExceptionIsThrown()
{
// Arrange
Type enumerableType = null;

// Act
object Act() => enumerableType.TryGetEnumerableSingleTypeArgument(out _);

// Assert
var exception = Assert.Throws<ArgumentNullException>(Act);
Assert.Equal("type", exception.ParamName);
}

[InlineData(typeof(int[]), typeof(int))]
[InlineData(typeof(List<int>), typeof(int))]
[InlineData(typeof(Dictionary<int, int>), typeof(KeyValuePair<int, int>))]
[InlineData(typeof(IEnumerable<int>), typeof(int))]
[Theory(DisplayName = "GIVEN valid collection WHEN TryGetEnumerableSingleTypeArgument is invoked THEN collection single type argument returned")]
public void GivenValidCollection_WhenTryGetEnumerableSingleTypeArgumentIsInvoked_ThenCollectionSingleTypeArgumentReturned(Type enumerableType, Type expectedType)
{
// Arrange
// Act
var isSuccessful = enumerableType.TryGetEnumerableSingleTypeArgument(out var itemType);

// Assert
Assert.True(isSuccessful);
Assert.Equal(expectedType, itemType);
}

[MemberData(nameof(InvalidCollectionTestData))]
[Theory(DisplayName = "GIVEN invalid collection WHEN TryGetEnumerableSingleTypeArgument is invoked THEN no argument returned")]
public void GivenInvalidCollection_WhenTryGetEnumerableSingleTypeArgumentIsInvoked_ThenNoArgumentReturned(Type enumerableType)
{
// Arrange
// Act
var isSuccessful = enumerableType.TryGetEnumerableSingleTypeArgument(out _);

// Assert
Assert.False(isSuccessful);
}

[InlineData(null, typeof(int), "items")]
[InlineData(new[] { 1 }, null, "itemType")]
[Theory(DisplayName = "GIVEN uninitialized argument WHEN ToTypedArray is invoked THEN exception is thrown")]
public void GivenUninitializedArgument_WhenToTypedArrayIsInvoked_ThenExceptionIsThrown(
IEnumerable items,
Type itemType,
string exceptionParamName)
{
// Arrange
// Act
object Act() => items.ToTypedArray(itemType);

// Assert
var exception = Assert.Throws<ArgumentNullException>(Act);
Assert.Equal(exceptionParamName, exception.ParamName);
}

[AutoData]
[Theory(DisplayName = "GIVEN typed enumerable WHEN ToTypedArray is invoked THEN array is returned")]
public void GivenTypedEnumerable_WhenToTypedArrayIsInvoked_ThenArrayIsReturned(int[] items)
{
// Arrange
var itemType = typeof(int);

// Act
var array = items.ToTypedArray(itemType);

// Assert
Assert.Equal(items, array);
Assert.True(array.GetType().IsArray);
}

[AutoData]
[Theory(DisplayName = "GIVEN enumerable WHEN ToTypedArray is invoked THEN array is returned")]
public void GivenEnumerable_WhenToTypedArrayIsInvoked_ThenArrayIsReturned(BitArray items)
{
// Arrange
var itemType = typeof(bool);

// Act
var array = items.ToTypedArray(itemType);

// Assert
Assert.Equal(items, array);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
[Trait("Category", "Requests")]
public class ValuesRequestTests
{
public static TheoryData<Type, object[], string> NullArgumentConstructorTestData { get; } = new()
{
{ null, new object[] { 1 }, "operandType" },
{ typeof(int), null, "values" },
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.

public static TheoryData<Type, IEnumerable, Type, IEnumerable, bool> ComparisonTestData { get; } = new()
{
{ typeof(int), new[] { 1 }, typeof(int), new[] { 1 }, true },
Expand All @@ -24,34 +30,18 @@ public class ValuesRequestTests
{ typeof(int), new[] { 1, 2 }, typeof(int), new[] { 2 }, false },
};

[Fact(DisplayName = "GIVEN uninitialized type argument WHEN constructor is invoked THEN exception is thrown")]
public void GivenUninitializedTypeArgument_WhenConstructorIsInvoked_ThenExceptionIsThrown()
[MemberData(nameof(NullArgumentConstructorTestData))]
[Theory(DisplayName = "GIVEN uninitialized argument WHEN constructor is invoked THEN exception is thrown")]
public void GivenUninitializedArgument_WhenConstructorIsInvoked_ThenExceptionIsThrown(
Type type, object[] values, string expectedParamName)
{
// Arrange
Type type = null;
object[] values = null;

// Act
object Act() => new FixedValuesRequest(type, values);

// Assert
var exception = Assert.Throws<ArgumentNullException>(Act);
Assert.Equal("operandType", exception.ParamName);
}

[Fact(DisplayName = "GIVEN uninitialized values argument WHEN constructor is invoked THEN exception is thrown")]
public void GivenUninitializedValuesArgument_WhenConstructorIsInvoked_ThenExceptionIsThrown()
{
// Arrange
var type = typeof(int);
object[] values = null;

// Act
object Act() => new FixedValuesRequest(type, values);

// Assert
var exception = Assert.Throws<ArgumentNullException>(Act);
Assert.Equal("values", exception.ParamName);
Assert.Equal(expectedParamName, exception.ParamName);
}

[Fact(DisplayName = "GIVEN empty values argument WHEN constructor is invoked THEN exception is thrown")]
Expand Down
Loading
Loading