Skip to content

Commit 5da7ece

Browse files
committed
Fixed unit tests with RelayCommand and value types
1 parent 504c3e2 commit 5da7ece

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

UnitTests/UnitTests.Shared/Mvvm/Test_AsyncRelayCommand{T}.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ public void Test_AsyncRelayCommandOfT_NullWithValueType()
125125
return Task.CompletedTask;
126126
});
127127

128-
// Special case for null value types
129-
Assert.IsTrue(command.CanExecute(null));
128+
Assert.IsFalse(command.CanExecute(null));
129+
Assert.ThrowsException<NullReferenceException>(() => command.Execute(null));
130130

131131
command = new AsyncRelayCommand<int>(
132132
i =>
@@ -135,7 +135,8 @@ public void Test_AsyncRelayCommandOfT_NullWithValueType()
135135
return Task.CompletedTask;
136136
}, i => i > 0);
137137

138-
Assert.ThrowsException<NullReferenceException>(() => command.CanExecute(null));
138+
Assert.IsFalse(command.CanExecute(null));
139+
Assert.ThrowsException<NullReferenceException>(() => command.Execute(null));
139140
}
140141
}
141142
}

UnitTests/UnitTests.Shared/Mvvm/Test_RelayCommand{T}.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,13 @@ public void Test_RelayCommand_NullWithValueType()
7474

7575
var command = new RelayCommand<int>(i => n = i);
7676

77-
// Special case for null value types
78-
Assert.IsTrue(command.CanExecute(null));
77+
Assert.IsFalse(command.CanExecute(null));
78+
Assert.ThrowsException<NullReferenceException>(() => command.Execute(null));
7979

8080
command = new RelayCommand<int>(i => n = i, i => i > 0);
8181

82-
Assert.ThrowsException<NullReferenceException>(() => command.CanExecute(null));
82+
Assert.IsFalse(command.CanExecute(null));
83+
Assert.ThrowsException<NullReferenceException>(() => command.Execute(null));
8384
}
8485
}
8586
}

0 commit comments

Comments
 (0)