diff --git a/ExamplesAndTests/Swordfish.NET.UnitTestV3/ConcurrentObservableDictionary_Issue35.cs b/ExamplesAndTests/Swordfish.NET.UnitTestV3/ConcurrentObservableDictionary_Issue35.cs new file mode 100644 index 0000000..268e8db --- /dev/null +++ b/ExamplesAndTests/Swordfish.NET.UnitTestV3/ConcurrentObservableDictionary_Issue35.cs @@ -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 +{ + /// + /// This is a group of tests for Issue 35 on github + /// https://github.com/stewienj/SwordfishCollections/issues/35 + /// + [TestClass] + public class ConcurrentObservableDictionary_Issue35 + { + [TestMethod] + public void AddRangeRemoveRangeTest() + { + var keyValuePairs = Enumerable.Range(0, 10) + .Select(i => new KeyValuePair(new object(), i)).ToArray(); + + var testCollection = new ConcurrentObservableDictionary(); + 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(new object(), i)).ToArray(); + + var testCollection = new ConcurrentObservableDictionary(); + 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(new object(), i)).ToArray(); + + var testCollection = new ConcurrentObservableDictionary(); + 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(new object(), i)).ToArray(); + + var testCollection = new ConcurrentObservableDictionary(); + 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)); + } + + + + + } +}