Example #1
0
        public void AddOrUpdate_WithNonEmptyDictionary_ReturnsUpdatedObject()
        {
            FailOnErrors = false;

            LocalCache        cache     = new LocalCache();
            TestIntegerObject resultInt = cache.AddOrUpdate(typeof(TestIntegerObject), () => new TestIntegerObject(TestInteger), out bool wasUpdated) as TestIntegerObject;

            Assert.Equal(TestInteger, resultInt.Value);
            Assert.True(wasUpdated);

            TestStringObject resultString = cache.AddOrUpdate(typeof(TestStringObject), () => new TestStringObject(TestString1), out wasUpdated) as TestStringObject;

            Assert.Equal(TestString1, resultString.Value);
            Assert.True(wasUpdated);
        }
Example #2
0
        public void AddOrUpdate_WithNullValueParameter_ReturnsNull()
        {
            FailOnErrors = false;

            LocalCache cache  = new LocalCache();
            object     result = cache.AddOrUpdate(typeof(TestStringObject), null, out bool wasUpdated);

            Assert.Null(result);
            Assert.False(wasUpdated);
        }
Example #3
0
        public void AddOrUpdate_WithRepeatedEntry_ReturnsSecondObject()
        {
            LocalCache       cache         = new LocalCache();
            TestStringObject resultString1 = cache.GetOrAdd(typeof(TestStringObject), () => new TestStringObject(TestString1), out bool wasAdded) as TestStringObject;

            Assert.Equal(TestString1, resultString1.Value);
            Assert.True(wasAdded);

            TestStringObject resultString2 = cache.AddOrUpdate(typeof(TestStringObject), () => new TestStringObject(TestString2), out bool wasUpdated) as TestStringObject;

            Assert.Equal(resultString2.Value, TestString2);
            Assert.True(wasUpdated);
        }
Example #4
0
        public void AddOrUpdate_InParallelWithEmptyDictionary_ReturnsUpdatedObject()
        {
            FailOnErrors = false;

            LocalCache cache = new LocalCache();

            Parallel.For(0, 10, i =>
            {
                TestStringObject resultString = cache.AddOrUpdate(typeof(TestStringObject), () => new TestStringObject(TestString1), out bool wasUpdated) as TestStringObject;
                Assert.Equal(TestString1, resultString.Value);
                Assert.True(wasUpdated);
            });
        }
Example #5
0
        public void AddOrUpdate_InParallelWithNullTypeParameter_ReturnsNull()
        {
            FailOnErrors = false;

            LocalCache cache = new LocalCache();

            Parallel.For(0, 10, i =>
            {
                object result = cache.AddOrUpdate(null, () => new TestStringObject(TestString1), out bool wasUpdated);
                Assert.Null(result);
                Assert.False(wasUpdated);
            });
        }