-
Notifications
You must be signed in to change notification settings - Fork 2
/
ComputedBindableBaseTest.cs
45 lines (41 loc) · 1.46 KB
/
ComputedBindableBaseTest.cs
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
using ViewModel;
using Xunit;
namespace Tests
{
public class ComputedBindableBaseTest
{
[Fact]
public void TestAll()
{
var computedCalledTimes = 0;
var lastFullname = "";
var wololo = new Contact();
wololo.PropertyChanged += (sender, e) =>
{
if (e.PropertyName == nameof(wololo.Fullname))
{
computedCalledTimes += 1;
lastFullname = wololo.Fullname;
}
};
Assert.Equal(0, computedCalledTimes);
Assert.Equal("", lastFullname);
wololo.Name = "Servostasio";
Assert.Equal(1, computedCalledTimes);
Assert.Equal("Servostasio", lastFullname);
wololo.Surname = "Tandori";
Assert.Equal(2, computedCalledTimes);
Assert.Equal("Servostasio Tandori", lastFullname);
Assert.Equal("Servostasio Tandori", wololo.Fullname);
}
class Contact : ComputedBindableBase
{
private string name;
public string Name { get => name; set => Set(ref name, value); }
private string surname;
public string Surname { get => surname; set => Set(ref surname, value); }
[PropertySource(nameof(Name), nameof(Surname))]
public string Fullname => $"{Name} {Surname}".Trim();
}
}
}