/
ObservableCollectionBindListFixture.cs
82 lines (69 loc) · 2.59 KB
/
ObservableCollectionBindListFixture.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
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
using System;
using System.Linq;
using DynamicData.Binding;
using DynamicData.Tests.Domain;
using FluentAssertions;
using Xunit;
namespace DynamicData.Tests.Binding
{
public class ObservableCollectionBindListFixture: IDisposable
{
private readonly ObservableCollectionExtended<Person> _collection = new ObservableCollectionExtended<Person>();
private readonly SourceList<Person> _source;
private readonly IDisposable _binder;
private readonly RandomPersonGenerator _generator = new RandomPersonGenerator();
public ObservableCollectionBindListFixture()
{
_collection = new ObservableCollectionExtended<Person>();
_source = new SourceList<Person>();
_binder = _source.Connect().Bind(_collection).Subscribe();
}
public void Dispose()
{
_binder.Dispose();
_source.Dispose();
}
[Fact]
public void AddToSourceAddsToDestination()
{
var person = new Person("Adult1", 50);
_source.Add(person);
_collection.Count.Should().Be(1, "Should be 1 item in the collection");
_collection.First().Should().Be(person, "Should be same person");
}
[Fact]
public void UpdateToSourceUpdatesTheDestination()
{
var person = new Person("Adult1", 50);
var personUpdated = new Person("Adult1", 51);
_source.Add(person);
_source.Replace(person, personUpdated);
_collection.Count.Should().Be(1, "Should be 1 item in the collection");
_collection.First().Should().Be(personUpdated, "Should be updated person");
}
[Fact]
public void RemoveSourceRemovesFromTheDestination()
{
var person = new Person("Adult1", 50);
_source.Add(person);
_source.Remove(person);
_collection.Count.Should().Be(0, "Should be 1 item in the collection");
}
[Fact]
public void AddRange()
{
var people = _generator.Take(100).ToList();
_source.AddRange(people);
_collection.Count.Should().Be(100, "Should be 100 items in the collection");
_collection.Should().BeEquivalentTo(_collection, "Collections should be equivalent");
}
[Fact]
public void Clear()
{
var people = _generator.Take(100).ToList();
_source.AddRange(people);
_source.Clear();
_collection.Count.Should().Be(0, "Should be 100 items in the collection");
}
}
}