Repository navigation
Expand file tree
/
Copy pathExceptFixture.cs
More file actions
83 lines (65 loc) · 2.53 KB
/
Copy pathExceptFixture.cs
File metadata and controls
83 lines (65 loc) · 2.53 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
using System;
using System.Collections.Generic;
using DynamicData.Tests.Domain;
using FluentAssertions;
using Xunit;
namespace DynamicData.Tests.Cache;
public class ExceptFixture : ExceptFixtureBase
{
protected override IObservable<IChangeSet<Person, string>> CreateObservable() => _targetSource.Connect().Except(_exceptSource.Connect());
}
public class ExceptCollectionFixture : ExceptFixtureBase
{
protected override IObservable<IChangeSet<Person, string>> CreateObservable()
{
var l = new List<IObservable<IChangeSet<Person, string>>> { _targetSource.Connect(), _exceptSource.Connect() };
return l.Except();
}
}
public abstract class ExceptFixtureBase : IDisposable
{
protected ISourceCache<Person, string> _exceptSource;
protected ISourceCache<Person, string> _targetSource;
private readonly ChangeSetAggregator<Person, string> _results;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2214:Do not call overridable methods in constructors", Justification = "Accepted as part of a test.")]
protected ExceptFixtureBase()
{
_targetSource = new SourceCache<Person, string>(p => p.Name);
_exceptSource = new SourceCache<Person, string>(p => p.Name);
_results = CreateObservable().AsAggregator();
}
public void Dispose()
{
_targetSource.Dispose();
_exceptSource.Dispose();
_results.Dispose();
}
[Fact]
public void DoNotIncludeExceptListItems()
{
var person = new Person("Adult1", 50);
_exceptSource.AddOrUpdate(person);
_targetSource.AddOrUpdate(person);
_results.Messages.Count.Should().Be(0, "Should have no updates");
_results.Data.Count.Should().Be(0, "Cache should have no items");
}
[Fact]
public void RemovedAnItemFromExceptThenIncludesTheItem()
{
var person = new Person("Adult1", 50);
_exceptSource.AddOrUpdate(person);
_targetSource.AddOrUpdate(person);
_exceptSource.Remove(person);
_results.Messages.Count.Should().Be(1, "Should be 2 updates");
_results.Data.Count.Should().Be(1, "Cache should have no items");
}
[Fact]
public void UpdatingOneSourceOnlyProducesResult()
{
var person = new Person("Adult1", 50);
_targetSource.AddOrUpdate(person);
_results.Messages.Count.Should().Be(1, "Should be 1 updates");
_results.Data.Count.Should().Be(1, "Should be 1 item in the cache");
}
protected abstract IObservable<IChangeSet<Person, string>> CreateObservable();
}