Repository navigation
Expand file tree
/
Copy pathSwitchFixture.cs
More file actions
63 lines (46 loc) · 1.64 KB
/
Copy pathSwitchFixture.cs
File metadata and controls
63 lines (46 loc) · 1.64 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
using System;
using System.Linq;
using System.Reactive.Subjects;
using DynamicData.Tests.Domain;
using FluentAssertions;
using Xunit;
namespace DynamicData.Tests.Cache;
public class SwitchFixture : IDisposable
{
private readonly ChangeSetAggregator<Person, string> _results;
private readonly ISourceCache<Person, string> _source;
private readonly ISubject<ISourceCache<Person, string>> _switchable;
public SwitchFixture()
{
_source = new SourceCache<Person, string>(p => p.Name);
_switchable = new BehaviorSubject<ISourceCache<Person, string>>(_source);
_results = _switchable.Switch().AsAggregator();
}
[Fact]
public void ClearsForNewSource()
{
var inital = Enumerable.Range(1, 100).Select(i => new Person("Person" + i, i)).ToArray();
_source.AddOrUpdate(inital);
_results.Data.Count.Should().Be(100);
var newSource = new SourceCache<Person, string>(p => p.Name);
_switchable.OnNext(newSource);
_results.Data.Count.Should().Be(0);
newSource.AddOrUpdate(inital);
_results.Data.Count.Should().Be(100);
var nextUpdates = Enumerable.Range(101, 100).Select(i => new Person("Person" + i, i)).ToArray();
newSource.AddOrUpdate(nextUpdates);
_results.Data.Count.Should().Be(200);
}
public void Dispose()
{
_source.Dispose();
_results.Dispose();
}
[Fact]
public void PoulatesFirstSource()
{
var inital = Enumerable.Range(1, 100).Select(i => new Person("Person" + i, i)).ToArray();
_source.AddOrUpdate(inital);
_results.Data.Count.Should().Be(100);
}
}