1- using Desktop . Common ;
1+ using System . Threading . Tasks ;
2+ using Desktop . Common ;
23using Desktop . Tasks ;
34using Desktop . Tests . TestAPI ;
45using FluentAssertions ;
@@ -10,10 +11,15 @@ namespace Desktop.Tests.UnitTests;
1011
1112public class TaskCreationViewModelTests
1213{
14+ private const string TaskCreationFailedMessage =
15+ "Task creation has failed due to " +
16+ "an internal error. The Task won't be created. " +
17+ "Please, try again later." ;
18+
1319 [ Test ]
1420 public void TaskCreation_Fails_MessageNotifiesUserAndTasksIsNotAddedToTheList ( )
1521 {
16- var repository = new InMemoryTaskRepository ( [ AnyDesktopTask ( ) ] ) ;
22+ var repository = new InMemoryTaskRepository ( [ ] ) ;
1723 repository . FailAlways ( ) ;
1824 var messageNotifierMock = new Mock < IMessageNotifier > ( ) ;
1925 var sut = new TaskCreationViewModel (
@@ -24,9 +30,46 @@ public void TaskCreation_Fails_MessageNotifiesUserAndTasksIsNotAddedToTheList()
2430 sut . SaveTask . Execute ( ( closeable . Object , "Any name" , "Any description" ) ) ;
2531
2632 messageNotifierMock . Verify ( x => x . Notify (
27- "Task creation has failed due to " +
28- "an internal error. The Task won't be created. " +
29- "Please, try again later." ) ) ;
33+ TaskCreationFailedMessage ) ) ;
3034 sut . CreatedTask . Should ( ) . BeNull ( ) ;
3135 }
36+
37+ [ Test ]
38+ public async Task
39+ TaskCreation_FailsForOne_NotifiesOnceAndAllowsSavingItToTheRestOfRepositories ( )
40+ {
41+ // Arrange.
42+ var aRepository = new InMemoryTaskRepository ( [ ] ) ;
43+ aRepository . FailAlways ( ) ;
44+ var anotherRepository = new InMemoryTaskRepository ( [ ] ) ;
45+
46+ var messageNotifierMock = new Mock < IMessageNotifier > ( ) ;
47+ var sut = new TaskCreationViewModel (
48+ messageNotifierMock . Object ,
49+ [ aRepository , anotherRepository ] ) ;
50+ var closeable = new Mock < ICloseable > ( ) ;
51+
52+ // Act.
53+ var taskName = "Any name" ;
54+ var taskDescription = "Any description" ;
55+ sut . SaveTask . Execute ( ( closeable . Object , taskName , taskDescription ) ) ;
56+
57+ // Assert.
58+ messageNotifierMock . Verify (
59+ x => x . Notify ( TaskCreationFailedMessage ) ,
60+ Times . Once ) ;
61+ var createdTask = DesktopTask ( taskName , taskDescription ) ;
62+ sut . CreatedTask . Should ( ) . BeEquivalentTo (
63+ createdTask ,
64+ options => options
65+ . ComparingByMembers < Domain . Task > ( )
66+ . Excluding ( x => x . Id ) ) ;
67+
68+ var result = await anotherRepository . All ( ) ;
69+ result . Tasks . Should ( ) . ContainEquivalentOf (
70+ createdTask ,
71+ options => options
72+ . ComparingByMembers < Domain . Task > ( )
73+ . Excluding ( x => x . Id ) ) ;
74+ }
3275}
0 commit comments