-
Notifications
You must be signed in to change notification settings - Fork 4
Improve code coverage #342
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
16 commits
Select commit
Hold shift + click to select a range
5e4a224
Add report generation tools for tests
rjmurillo 9894756
Fix typos in comments
rjmurillo de1e706
Change initialization to match project convention
rjmurillo 8dde1ce
Revert "Change initialization to match project convention"
rjmurillo ed84e94
Remove unused code
rjmurillo 0a235c2
Add test project for common elements
rjmurillo 588d569
Add unit tests for ArrayExtensions
rjmurillo 1fa77a8
Move extension tests to existing unit test project
rjmurillo eec9e70
Replace tail recursive implementation FindSetupMethodFromCallbackInvo…
rjmurillo 0467cfd
Add unit tests for EnumerableExtensions
rjmurillo 8dd1fbf
Fix issue with possible null deference
rjmurillo c5439bb
Add tests for EnumerableExtensions
rjmurillo 9761db5
Extend support to ignore valuetask on setup method
rjmurillo c373da6
Fix for SA1515
rjmurillo 8765c5a
Reduce code duplication when checking for Task and ValueTask result
rjmurillo c5f6e50
Merge main
rjmurillo 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
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
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
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
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
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
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
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
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
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,81 @@ | ||
| namespace Moq.Analyzers.Test.Common; | ||
|
|
||
| public class ArrayExtensionTests | ||
| { | ||
| [Fact] | ||
| public void RemoveAt_RemovesElementAtIndex() | ||
| { | ||
| // Arrange | ||
| int[] actual = [1, 2, 3, 4, 5]; | ||
| int[] expected = [1, 2, 4, 5]; | ||
| const int indexToRemove = 2; | ||
|
|
||
| // Act | ||
| int[] result = actual.RemoveAt(indexToRemove); | ||
|
|
||
| // Assert | ||
| Assert.Equal(expected, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void RemoveAt_FirstElement_RemovesCorrectly() | ||
| { | ||
| // Arrange | ||
| int[] input = [1, 2, 3]; | ||
| int[] expected = [2, 3]; | ||
|
|
||
| // Act | ||
| int[] result = input.RemoveAt(0); | ||
|
|
||
| // Assert | ||
| Assert.Equal(expected, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void RemoveAt_LastElement_RemovesCorrectly() | ||
| { | ||
| // Arrange | ||
| int[] input = [1, 2, 3]; | ||
| int[] expected = [1, 2]; | ||
|
|
||
| // Act | ||
| int[] result = input.RemoveAt(input.Length - 1); | ||
|
|
||
| // Assert | ||
| Assert.Equal(expected, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void RemoveAt_SingleElementArray_ReturnsEmptyArray() | ||
| { | ||
| // Arrange | ||
| int[] input = [42]; | ||
|
|
||
| // Act | ||
| int[] result = input.RemoveAt(0); | ||
|
|
||
| // Assert | ||
| Assert.Empty(result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void RemoveAt_IndexOutOfRange_ThrowsException() | ||
| { | ||
| // Arrange | ||
| int[] input = [1, 2, 3]; | ||
|
|
||
| // Act & Assert | ||
| Assert.Throws<ArgumentOutOfRangeException>(() => input.RemoveAt(-1)); | ||
| Assert.Throws<ArgumentOutOfRangeException>(() => input.RemoveAt(3)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void RemoveAt_EmptyArray_ThrowsException() | ||
| { | ||
| // Arrange | ||
| int[] input = []; | ||
|
|
||
| // Act & Assert | ||
| Assert.Throws<ArgumentOutOfRangeException>(() => input.RemoveAt(0)); | ||
| } | ||
| } |
76 changes: 76 additions & 0 deletions
76
tests/Moq.Analyzers.Test/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 |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| namespace Moq.Analyzers.Test.Common; | ||
|
|
||
| public class EnumerableExtensionsTests | ||
| { | ||
| [Fact] | ||
| public void DefaultIfNotSingle_ReturnsNull_WhenSourceIsEmpty() | ||
| { | ||
| IEnumerable<int> source = []; | ||
| int result = source.DefaultIfNotSingle(); | ||
| Assert.Equal(0, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DefaultIfNotSingle_ReturnsElement_WhenSourceContainsSingleElement() | ||
| { | ||
| int[] source = [42]; | ||
| int result = source.DefaultIfNotSingle(); | ||
| Assert.Equal(42, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DefaultIfNotSingle_ReturnsNull_WhenSourceContainsMultipleElements() | ||
| { | ||
| int[] source = [1, 2, 3]; | ||
| int result = source.DefaultIfNotSingle(); | ||
| Assert.Equal(0, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DefaultIfNotSingle_WithPredicate_ReturnsNull_WhenNoElementsMatch() | ||
| { | ||
| int[] source = [1, 2, 3]; | ||
| int result = source.DefaultIfNotSingle(x => x > 10); | ||
| Assert.Equal(0, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DefaultIfNotSingle_WithPredicate_ReturnsElement_WhenOnlyOneMatches() | ||
| { | ||
| int[] source = [1, 2, 3]; | ||
| int result = source.DefaultIfNotSingle(x => x == 2); | ||
| Assert.Equal(2, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DefaultIfNotSingle_WithPredicate_ReturnsNull_WhenMultipleElementsMatch() | ||
| { | ||
| int[] source = [1, 2, 2, 3]; | ||
| int result = source.DefaultIfNotSingle(x => x > 1); | ||
| Assert.Equal(0, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DefaultIfNotSingle_ImmutableArray_ReturnsNull_WhenEmpty() | ||
| { | ||
| ImmutableArray<int> source = ImmutableArray<int>.Empty; | ||
| int result = source.DefaultIfNotSingle(x => x > 0); | ||
| Assert.Equal(0, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DefaultIfNotSingle_ImmutableArray_ReturnsElement_WhenSingleMatch() | ||
| { | ||
| ImmutableArray<int> source = [.. new[] { 5, 10, 15 }]; | ||
| int result = source.DefaultIfNotSingle(x => x == 10); | ||
| Assert.Equal(10, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DefaultIfNotSingle_ImmutableArray_ReturnsNull_WhenMultipleMatches() | ||
| { | ||
| ImmutableArray<int> source = [.. new[] { 5, 10, 10, 15 }]; | ||
| int result = source.DefaultIfNotSingle(x => x > 5); | ||
| Assert.Equal(0, result); | ||
| } | ||
| } |
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.
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.