-
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from robsonj/master
#111 - OnItemAdded and OnItemRemoved for SourceCache
- Loading branch information
Showing
3 changed files
with
88 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using DynamicData.Tests.Domain; | ||
using Xunit; | ||
|
||
namespace DynamicData.Tests.Cache | ||
{ | ||
public class OnItemFixture | ||
{ | ||
[Fact] | ||
public void OnItemAddCalled() | ||
{ | ||
var called = false; | ||
var source = new SourceCache<Person, int>(x => x.Age); | ||
|
||
source.Connect() | ||
.OnItemAdded(_ => called = true) | ||
.Subscribe(); | ||
|
||
var person = new Person("A", 1); | ||
|
||
source.AddOrUpdate(person); | ||
Assert.True(called); | ||
} | ||
|
||
[Fact] | ||
public void OnItemRemovedCalled() | ||
{ | ||
var called = false; | ||
var source = new SourceCache<Person, int>(x => x.Age); | ||
|
||
source.Connect() | ||
.OnItemRemoved(_ => called = true) | ||
.Subscribe(); | ||
|
||
var person = new Person("A", 1); | ||
source.AddOrUpdate(person); | ||
source.Remove(person); | ||
Assert.True(called); | ||
} | ||
|
||
[Fact] | ||
public void OnItemUpdatedCalled() | ||
{ | ||
var called = false; | ||
var source = new SourceCache<Person, int>(x => x.Age); | ||
|
||
source.Connect() | ||
.OnItemUpdated((x,y) => called = true) | ||
.Subscribe(); | ||
|
||
var person = new Person("A", 1); | ||
source.AddOrUpdate(person); | ||
var update = new Person("B", 1); | ||
source.AddOrUpdate(update); | ||
Assert.True(called); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters