Skip to content

Commit 5dfae1d

Browse files
Update Unit Tests
1 parent 4c13ad3 commit 5dfae1d

File tree

4 files changed

+74
-15
lines changed

4 files changed

+74
-15
lines changed

src/AsyncAwaitBestPractices.MVVM/InvalidCommandParameterException.shared.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace AsyncAwaitBestPractices.MVVM;
88
public class InvalidCommandParameterException : Exception
99
{
1010
/// <summary>
11-
/// Initializes a new instance of the <see cref="T:TaskExtensions.MVVM.InvalidCommandParameterException"/> class.
11+
/// Initializes a new instance of the <see cref="T:InvalidCommandParameterException"/> class.
1212
/// </summary>
1313
/// <param name="expectedType">Expected parameter type for AsyncCommand.Execute.</param>
1414
/// <param name="actualType">Actual parameter type for AsyncCommand.Execute.</param>
@@ -19,7 +19,7 @@ public InvalidCommandParameterException(Type expectedType, Type actualType, Exce
1919
}
2020

2121
/// <summary>
22-
/// Initializes a new instance of the <see cref="T:TaskExtensions.MVVM.InvalidCommandParameterException"/> class.
22+
/// Initializes a new instance of the <see cref="T:InvalidCommandParameterException"/> class.
2323
/// </summary>
2424
/// <param name="expectedType">Expected parameter type for AsyncCommand.Execute.</param>
2525
/// <param name="actualType">Actual parameter type for AsyncCommand.Execute.</param>
@@ -29,25 +29,37 @@ public InvalidCommandParameterException(Type expectedType, Type actualType) : ba
2929
}
3030

3131
/// <summary>
32-
/// Initializes a new instance of the <see cref="T:TaskExtensions.MVVM.InvalidCommandParameterException"/> class.
32+
/// Initializes a new instance of the <see cref="T:InvalidCommandParameterException"/> class.
3333
/// </summary>
3434
/// <param name="expectedType">Expected parameter type for AsyncCommand.Execute.</param>
3535
/// <param name="innerException">Inner Exception</param>
3636
public InvalidCommandParameterException(Type expectedType, Exception innerException) : base(CreateErrorMessage(expectedType), innerException)
3737
{
38-
38+
if (innerException is null)
39+
throw new ArgumentNullException(nameof(innerException));
3940
}
4041

4142
/// <summary>
42-
/// Initializes a new instance of the <see cref="T:TaskExtensions.MVVM.InvalidCommandParameterException"/> class.
43+
/// Initializes a new instance of the <see cref="T:InvalidCommandParameterException"/> class.
4344
/// </summary>
4445
/// <param name="expectedType">Expected parameter type for AsyncCommand.Execute.</param>
4546
public InvalidCommandParameterException(Type expectedType) : base(CreateErrorMessage(expectedType))
4647
{
4748

4849
}
4950

50-
static string CreateErrorMessage(Type expectedType) => $"Invalid type for parameter. Expected Type {expectedType}";
51+
static string CreateErrorMessage(Type expectedType) => expectedType is null
52+
? throw new ArgumentNullException(nameof(expectedType))
53+
: $"Invalid type for parameter. Expected Type {expectedType}";
54+
55+
static string CreateErrorMessage(Type expectedType, Type actualType)
56+
{
57+
if (expectedType is null)
58+
throw new ArgumentNullException(nameof(expectedType));
5159

52-
static string CreateErrorMessage(Type expectedType, Type actualType) => $"Invalid type for parameter. Expected Type {expectedType}, but received Type {actualType}";
60+
if (actualType is null)
61+
throw new ArgumentNullException(nameof(actualType));
62+
63+
return $"Invalid type for parameter. Expected Type {expectedType}, but received Type {actualType}";
64+
}
5365
}

src/AsyncAwaitBestPractices.UnitTests/Tests_InvalidCommandParameterException.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,39 @@ public void InvalidCommandParameterException_InheritsFromException()
9090
//Assert
9191
Assert.That(exception, Is.InstanceOf<Exception>());
9292
}
93+
94+
[Test]
95+
public void InvalidCommandParameterException_NullExpectedType_ThrowsArgumentNullException()
96+
{
97+
// Assert
98+
Assert.Throws<ArgumentNullException>(() => new InvalidCommandParameterException(null!));
99+
}
100+
101+
[Test]
102+
public void InvalidCommandParameterException_NullActualType_ThrowsArgumentNullException()
103+
{
104+
// Assert
105+
Assert.Throws<ArgumentNullException>(() => new InvalidCommandParameterException(typeof(string), (Type)null!));
106+
}
107+
108+
[Test]
109+
public void InvalidCommandParameterException_NullInnerException_ThrowsArgumentNullException()
110+
{
111+
// Assert
112+
Assert.Throws<ArgumentNullException>(() => new InvalidCommandParameterException(typeof(string), (Exception)null!));
113+
}
114+
115+
[Test]
116+
public void InvalidCommandParameterException_NullExpectedTypeAndNullInnerException_ThrowsArgumentNullException()
117+
{
118+
// Assert
119+
Assert.Throws<ArgumentNullException>(() => new InvalidCommandParameterException(null!, (Exception)null!));
120+
}
121+
122+
[Test]
123+
public void InvalidCommandParameterException_NullExpectedTypeAndNullActualType_ThrowsArgumentNullException()
124+
{
125+
// Assert
126+
Assert.Throws<ArgumentNullException>(() => new InvalidCommandParameterException(null!, (Exception)null!));
127+
}
93128
}

src/AsyncAwaitBestPractices.UnitTests/Tests_InvalidHandleEventException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void InvalidHandleEventException_Constructor_NullMessage()
3232
var targetParameterCountException = new TargetParameterCountException("Parameter count mismatch");
3333

3434
//Act & Assert
35-
Assert.DoesNotThrow(() => new InvalidHandleEventException(null!, targetParameterCountException));
35+
Assert.Throws<ArgumentNullException>(() => new InvalidHandleEventException(null!, targetParameterCountException));
3636
}
3737

3838
[Test]
@@ -42,7 +42,7 @@ public void InvalidHandleEventException_Constructor_NullInnerException()
4242
const string message = "Test exception message";
4343

4444
//Act & Assert
45-
Assert.DoesNotThrow(() => new InvalidHandleEventException(message, null!));
45+
Assert.Throws<ArgumentNullException>(() => new InvalidHandleEventException(message, null!));
4646
}
4747

4848
[Test]

src/AsyncAwaitBestPractices/InvalidHandleEventException.shared.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,23 @@ namespace AsyncAwaitBestPractices;
66
/// <summary>
77
/// Represents errors that occur during WeakEventManager.HandleEvent execution.
88
/// </summary>
9-
/// <remarks>
10-
/// Initializes a new instance of the <see cref="T:AsyncAwaitBestPractices.InvalidHandleEventException"/> class.
11-
/// </remarks>
12-
/// <param name="message">Message.</param>
13-
/// <param name="targetParameterCountException">Target parameter count exception.</param>
14-
public class InvalidHandleEventException(string message, TargetParameterCountException targetParameterCountException) : Exception(message, targetParameterCountException)
9+
public class InvalidHandleEventException : Exception
1510
{
11+
/// <summary>
12+
/// Represents errors that occur during WeakEventManager.HandleEvent execution.
13+
/// </summary>
14+
/// <remarks>
15+
/// Initializes a new instance of the <see cref="T:AsyncAwaitBestPractices.InvalidHandleEventException"/> class.
16+
/// </remarks>
17+
/// <param name="message">Message.</param>
18+
/// <param name="targetParameterCountException">Target parameter count exception.</param>
19+
public InvalidHandleEventException(string message, TargetParameterCountException targetParameterCountException) : base(message, targetParameterCountException)
20+
{
21+
if (message is null)
22+
throw new ArgumentNullException(nameof(message));
23+
24+
if(targetParameterCountException is null)
25+
throw new ArgumentNullException(nameof(targetParameterCountException));
26+
}
27+
1628
}

0 commit comments

Comments
 (0)