File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using System . Collections . Generic ;
2+ using System . Threading . Tasks ;
3+ using Desktop . Tasks ;
4+
5+ namespace Desktop . Tests . TestAPI ;
6+
7+ using SystemTask = Task ;
8+
9+ public class InMemoryTaskRepository : ITaskRepository
10+ {
11+ private readonly List < Domain . Task > tasks = [ ] ;
12+
13+ public InMemoryTaskRepository ( IEnumerable < Domain . Task > with )
14+ {
15+ tasks . AddRange ( with ) ;
16+ }
17+
18+ public Task < IReadOnlyList < Domain . Task > > All ( )
19+ {
20+ return SystemTask . FromResult < IReadOnlyList < Domain . Task > > ( tasks . ToArray ( ) ) ;
21+ }
22+
23+ public SystemTask Save ( Domain . Task task )
24+ {
25+ tasks . Add ( task ) ;
26+
27+ return SystemTask . CompletedTask ;
28+ }
29+
30+ public SystemTask Delete ( Domain . Task toBeDeleted )
31+ {
32+ tasks . Remove ( toBeDeleted ) ;
33+
34+ return SystemTask . CompletedTask ;
35+ }
36+ }
Original file line number Diff line number Diff line change 1+ using System ;
2+
3+ namespace Desktop . Tests . TestAPI ;
4+
5+ public class Utils
6+ {
7+ public const int SeveralTimes = 5 ;
8+
9+ public static void Repeat ( Action what , int times )
10+ {
11+ for ( var i = 0 ; i < times ; i ++ )
12+ what ( ) ;
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Threading . Tasks ;
3+ using Desktop . Project ;
4+ using Desktop . Tasks ;
5+ using Desktop . Tests . TestAPI ;
6+ using FluentAssertions ;
7+ using NUnit . Framework ;
8+ using static Desktop . Tests . TestAPI . TaskFactory ;
9+ using static Desktop . Tests . TestAPI . Utils ;
10+
11+ namespace Desktop . Tests . UnitTests ;
12+
13+ public class TaskListViewModelTests
14+ {
15+ [ Test ]
16+ [ Category ( "Regression" ) ]
17+ public async Task TasksPopulation_IsIdempotent ( )
18+ {
19+ var taskRepository = new InMemoryTaskRepository ( [ DesktopTask ( ) ] ) ;
20+ var sut = TaskListViewModel ( taskRepository ) ;
21+
22+ Repeat ( sut . PopulateTasks , SeveralTimes ) ;
23+
24+ sut . Tasks . Should ( ) . BeEquivalentTo ( await taskRepository . All ( ) ) ;
25+ }
26+
27+ private static TaskListViewModel TaskListViewModel ( InMemoryTaskRepository taskRepository )
28+ {
29+ return new TaskListViewModel (
30+ taskRepository ,
31+ new TaskCreationViewModel ( taskRepository ) ) ;
32+ }
33+ }
Original file line number Diff line number Diff line change @@ -44,6 +44,8 @@ public TaskListViewModel(
4444
4545 public void PopulateTasks ( )
4646 {
47+ Tasks . Clear ( ) ;
48+
4749 // TODO: load this async and deferred from the ctor.
4850 var retrievedTasks = SystemTask . Run ( taskRepository . All ) . Result ;
4951 foreach ( var task in retrievedTasks )
Original file line number Diff line number Diff line change 1- - fix: Tasks are duplicated when reloading Task List view
2- - docs: project directory structure: vertical slicing vs by tech.
1+ - docs: project directory structure: vertical slicing vs by tech.
32- docs: the focus on UX with the accelerators/shortcuts.
43- docs: when and why use comments & summaries.
54- refactor: use Commands and ViewModels instead of code behinds.
You can’t perform that action at this time.
0 commit comments