-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#35 Added some unit tests that illustrate an issue with ConcurrentObs…
…ervableDictionary
- Loading branch information
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
ExamplesAndTests/Swordfish.NET.UnitTestV3/ConcurrentObservableDictionary_Issue35.cs
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,89 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Swordfish.NET.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
|
||
namespace Swordfish.NET.UnitTestV3 | ||
{ | ||
/// <summary> | ||
/// This is a group of tests for Issue 35 on github | ||
/// https://github.com/stewienj/SwordfishCollections/issues/35 | ||
/// </summary> | ||
[TestClass] | ||
public class ConcurrentObservableDictionary_Issue35 | ||
{ | ||
[TestMethod] | ||
public void AddRangeRemoveRangeTest() | ||
{ | ||
var keyValuePairs = Enumerable.Range(0, 10) | ||
.Select(i => new KeyValuePair<object, int>(new object(), i)).ToArray(); | ||
|
||
var testCollection = new ConcurrentObservableDictionary<object, int>(); | ||
testCollection.AddRange(keyValuePairs); | ||
testCollection.Should().BeEquivalentTo(keyValuePairs); | ||
testCollection.RemoveRange(keyValuePairs.Take(5).Select(pair => pair.Key)); | ||
testCollection.Count.Should().Be(5); | ||
testCollection.Should().BeEquivalentTo(keyValuePairs.Skip(5)); | ||
} | ||
|
||
[TestMethod] | ||
public void AddRangeRemoveTest() | ||
{ | ||
var keyValuePairs = Enumerable.Range(0, 10) | ||
.Select(i => new KeyValuePair<object, int>(new object(), i)).ToArray(); | ||
|
||
var testCollection = new ConcurrentObservableDictionary<object, int>(); | ||
testCollection.AddRange(keyValuePairs); | ||
testCollection.Should().BeEquivalentTo(keyValuePairs); | ||
foreach (var key in keyValuePairs.Take(5).Select(pair => pair.Key)) | ||
{ | ||
testCollection.Remove(key); | ||
} | ||
testCollection.Count.Should().Be(5); | ||
testCollection.Should().BeEquivalentTo(keyValuePairs.Skip(5)); | ||
} | ||
|
||
[TestMethod] | ||
public void AddRemoveRangeTest() | ||
{ | ||
var keyValuePairs = Enumerable.Range(0, 10) | ||
.Select(i => new KeyValuePair<object, int>(new object(), i)).ToArray(); | ||
|
||
var testCollection = new ConcurrentObservableDictionary<object, int>(); | ||
foreach (var pair in keyValuePairs) | ||
{ | ||
testCollection.Add(pair.Key, pair.Value); | ||
} | ||
testCollection.Should().BeEquivalentTo(keyValuePairs); | ||
testCollection.RemoveRange(keyValuePairs.Take(5).Select(pair => pair.Key)); | ||
testCollection.Count.Should().Be(5); | ||
testCollection.Should().BeEquivalentTo(keyValuePairs.Skip(5)); | ||
} | ||
|
||
[TestMethod] | ||
public void AddRemoveTest() | ||
{ | ||
var keyValuePairs = Enumerable.Range(0, 10) | ||
.Select(i => new KeyValuePair<object, int>(new object(), i)).ToArray(); | ||
|
||
var testCollection = new ConcurrentObservableDictionary<object, int>(); | ||
foreach (var pair in keyValuePairs) | ||
{ | ||
testCollection.Add(pair.Key, pair.Value); | ||
} | ||
testCollection.Should().BeEquivalentTo(keyValuePairs); | ||
foreach (var key in keyValuePairs.Take(5).Select(pair => pair.Key)) | ||
{ | ||
testCollection.Remove(key); | ||
} | ||
testCollection.Count.Should().Be(5); | ||
testCollection.Should().BeEquivalentTo(keyValuePairs.Skip(5)); | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
} |