-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addition of new unit tests for extension methods, removing dead code, and fixing some documentation typos - Added configuration for a new reporting tool to generate coverage reports. - Enhanced async method analysis and streamlined APIs by removing redundant extension methods. - Corrected documentation typos to improve clarity. - Expanded unit test coverage for array operations, enumerable behavior, and asynchronous scenarios.
- Loading branch information
Showing
13 changed files
with
235 additions
and
69 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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.