Exemple #1
0
        public void CanAddWithSameAggregateId()
        {
            var lookup = new ConcurrentLookup <ContextElement>();

            lookup.Add(new ContextElement("Type", "Subject", null));
            lookup.Add(new ContextElement("Type", "SubjectS", null));
        }
Exemple #2
0
        public void CanTakeWhenUsingDuplicateIds()
        {
            var lookup = new ConcurrentLookup <ContextElement>();

            lookup.Add(new ContextElement("Type", "Subject", null));
            lookup.Add(new ContextElement("Type", "SubjectS", null));

            Assert.NotNull(lookup.Take("Type"));
            Assert.NotNull(lookup.Take("Type"));
        }
Exemple #3
0
        public void ReturnsNullWhenAllTaken()
        {
            var lookup = new ConcurrentLookup <ContextElement>();

            lookup.Add(new ContextElement("Type", "Subject", null));
            lookup.Add(new ContextElement("Type", "SubjectS", null));

            Assert.NotNull(lookup.Take("Type"));
            Assert.NotNull(lookup.Take("Type"));
            Assert.Null(lookup.Take("Type"));
        }
Exemple #4
0
        public void GetOrEmpty()
        {
            var lookup = new ConcurrentLookup <int, string>();

            lookup.Add(1, "one");
            lookup.Add(2, "two");
            lookup.Add(2, "zwei");

            AssertGetOrEmpty("", 0);
            AssertGetOrEmpty("one", 1);
            AssertGetOrEmpty("two,zwei", 2);

            void AssertGetOrEmpty(string expected, int key) => Assert.AreEqual(expected, lookup.GetOrEmpty(key).ToDelimitedString(","));
        }
        public void This_AfterAddingDuplicateValue_ContainsBothAddedValues()
        {
            List <KeyValuePair <Guid, string> > collection =
                Enumerable.Range(1, Random.Next(10, 100)).Select(
                    n => new KeyValuePair <Guid, string>(Guid.NewGuid(), Random.RandomString(10))).ToList();
            Guid   newKey   = Guid.NewGuid();
            String newValue = Random.RandomString(20);
            ConcurrentLookup <Guid, String> concurrentLookup = new ConcurrentLookup <Guid, string>(collection);

            concurrentLookup.Add(newKey, newValue);
            concurrentLookup.Add(newKey, newValue);
            CollectionAssert.AreEqual(new List <String> {
                newValue, newValue
            }, concurrentLookup[newKey].ToList());
        }
        public void This_AfterAddingKey_ContainsAddedValue()
        {
            List <KeyValuePair <Guid, string> > collection =
                Enumerable.Range(1, Random.Next(10, 100)).Select(
                    n => new KeyValuePair <Guid, string>(Guid.NewGuid(), Random.RandomString(10))).ToList();
            Guid   newKey   = Guid.NewGuid();
            String newValue = Random.RandomString(20);
            ConcurrentLookup <Guid, String> concurrentLookup = new ConcurrentLookup <Guid, string>(collection);

            concurrentLookup.Add(newKey, newValue);
            CollectionAssert.Contains(concurrentLookup[newKey].ToList(), newValue);
        }
Exemple #7
0
        public void Remove()
        {
            var lookup = new ConcurrentLookup <int, string>();

            lookup.Add(1, "one");
            Assert.IsTrue(lookup.TryGetValues(1, out IReadOnlyList <string> ones));
            Assert.AreEqual(1, ones.Count);
            Assert.AreEqual("one", ones[0]);

            lookup.Add(2, "two");
            lookup.Add(2, "zwei");
            Assert.IsTrue(lookup.TryGetValues(2, out IReadOnlyList <string> twos));
            Assert.AreEqual(2, twos.Count);
            Assert.AreEqual("two", twos[0]);
            Assert.AreEqual("zwei", twos[1]);

            Assert.IsFalse(lookup.TryGetValues(0, out IReadOnlyList <string> zeros));
            Assert.IsNull(zeros);

            lookup.Remove(2, "zwei");

            Assert.IsTrue(lookup.TryGetValues(2, out IReadOnlyList <string> oneTwo));
            Assert.AreEqual(1, oneTwo.Count);
            Assert.AreEqual("two", oneTwo[0]);

            lookup.Remove(2, "duo");

            Assert.IsTrue(lookup.TryGetValues(2, out IReadOnlyList <string> stillTwo));
            Assert.AreEqual(1, stillTwo.Count);
            Assert.AreEqual("two", stillTwo[0]);

            lookup.Remove(2, "two");

            Assert.IsFalse(lookup.TryGetValues(2, out IReadOnlyList <string> noTwos));
            Assert.IsNull(noTwos);
        }
 public void This_AfterRemovingDuplicateValue_StillContainsOneAddedValues()
 {
     List<KeyValuePair<Guid, string>> collection =
         Enumerable.Range(1, Random.Next(10, 100)).Select(
             n => new KeyValuePair<Guid, string>(Guid.NewGuid(), Random.RandomString(10))).ToList();
     Guid newKey = Guid.NewGuid();
     String newValue = Random.RandomString(20);
     ConcurrentLookup<Guid, String> concurrentLookup = new ConcurrentLookup<Guid, string>(collection);
     concurrentLookup.Add(newKey, newValue);
     concurrentLookup.Add(newKey, newValue);
     concurrentLookup.Remove(newKey, newValue);
     CollectionAssert.AreEqual(new List<String> {newValue}, concurrentLookup[newKey].ToList());
 }
 public void This_AfterAddingKey_ContainsAddedValue()
 {
     List<KeyValuePair<Guid, string>> collection =
         Enumerable.Range(1, Random.Next(10, 100)).Select(
             n => new KeyValuePair<Guid, string>(Guid.NewGuid(), Random.RandomString(10))).ToList();
     Guid newKey = Guid.NewGuid();
     String newValue = Random.RandomString(20);
     ConcurrentLookup<Guid, String> concurrentLookup = new ConcurrentLookup<Guid, string>(collection);
     concurrentLookup.Add(newKey, newValue);
     CollectionAssert.Contains(concurrentLookup[newKey].ToList(), newValue);
 }