-
Notifications
You must be signed in to change notification settings - Fork 6
refactor(tests): consolidate duplicate Facts into Theories #334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
.backlog/tasks/task-17 - Consolidate-duplicate-Facts-into-Theories.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
235 changes: 114 additions & 121 deletions
235
src/Objectivity.AutoFixture.XUnit2.Core.Tests/Common/EnumerableExtensionsTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.