-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNotificationsViewModelTests.cs
More file actions
121 lines (95 loc) · 3.4 KB
/
Copy pathNotificationsViewModelTests.cs
File metadata and controls
121 lines (95 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.Collections.ObjectModel;
using BorgMate.Models;
using BorgMate.Services.Journal;
using BorgMate.ViewModels;
using NSubstitute;
namespace BorgMate.Tests;
public class NotificationsViewModelTests
{
private static (NotificationsViewModel vm, ObservableCollection<JournalEntry> entries) CreateVm()
{
var journal = Substitute.For<IJournalService>();
var entries = new ObservableCollection<JournalEntry>();
journal.Entries.Returns(entries);
var vm = new NotificationsViewModel(journal);
return (vm, entries);
}
[Fact]
public void EmptyJournal_NoItems()
{
var (vm, _) = CreateVm();
Assert.Empty(vm.Items);
}
[Fact]
public void FinishedEntry_AppearsInItems()
{
var (vm, entries) = CreateVm();
var entry = new JournalEntry(JournalEventKind.Backup, ["test"], null, "repo",
DateTime.Now.AddMinutes(-5), DateTime.Now, JournalResult.Completed);
entries.Add(entry);
Assert.Single(vm.Items);
Assert.Equal(entry, vm.Items[0].Entry);
}
[Fact]
public void RunningEntry_NotInItems_UntilCompleted()
{
var (vm, entries) = CreateVm();
var entry = new JournalEntry(JournalEventKind.Backup, ["test"], null, "repo",
DateTime.Now, null, JournalResult.Running);
entries.Add(entry);
Assert.Empty(vm.Items);
// Complete the entry
entry.Complete(JournalResult.Completed);
Assert.Single(vm.Items);
}
[Fact]
public void FailedEntry_AppearsInItems()
{
var (vm, entries) = CreateVm();
var entry = new JournalEntry(JournalEventKind.Check, ["repo"], null, "repo",
DateTime.Now.AddMinutes(-1), DateTime.Now, JournalResult.Failed);
entries.Add(entry);
Assert.Single(vm.Items);
}
[Fact]
public void CancelledEntry_AppearsInItems()
{
var (vm, entries) = CreateVm();
var entry = new JournalEntry(JournalEventKind.Compact, ["repo"], null, "repo",
DateTime.Now.AddMinutes(-1), DateTime.Now, JournalResult.Cancelled);
entries.Add(entry);
Assert.Single(vm.Items);
}
[Fact]
public void MultipleEntries_AllAppear()
{
var (vm, entries) = CreateVm();
entries.Add(new JournalEntry(JournalEventKind.Backup, ["a"], null, "a",
DateTime.Now.AddMinutes(-10), DateTime.Now.AddMinutes(-5), JournalResult.Completed));
entries.Add(new JournalEntry(JournalEventKind.Check, ["b"], null, "b",
DateTime.Now.AddMinutes(-3), DateTime.Now, JournalResult.Failed));
Assert.Equal(2, vm.Items.Count);
}
[Fact]
public void EntriesCleared_ItemsCleared()
{
var (vm, entries) = CreateVm();
entries.Add(new JournalEntry(JournalEventKind.Backup, ["test"], null, "repo",
DateTime.Now.AddMinutes(-5), DateTime.Now, JournalResult.Completed));
Assert.Single(vm.Items);
entries.Clear();
Assert.Empty(vm.Items);
}
[Fact]
public void EntryRemoved_ItemRemoved()
{
var (vm, entries) = CreateVm();
var entry = new JournalEntry(JournalEventKind.Backup, ["test"], null, "repo",
DateTime.Now.AddMinutes(-5), DateTime.Now, JournalResult.Completed);
entries.Add(entry);
Assert.Single(vm.Items);
entries.Remove(entry);
Assert.Empty(vm.Items);
}
}