From 1228df0051737ffc04f7c1e36971d617e8908088 Mon Sep 17 00:00:00 2001 From: John Stewien Date: Wed, 18 Dec 2024 18:04:38 +1030 Subject: [PATCH] #35 Added some unit tests that illustrate an issue with ConcurrentObservableDictionary --- .../ConcurrentObservableDictionary_Issue35.cs | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 ExamplesAndTests/Swordfish.NET.UnitTestV3/ConcurrentObservableDictionary_Issue35.cs 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)); + } + + + + + } +}