public void Remove_Succeeds_For_Item_Not_In_The_Cache()
        {
            var cache = new DictionaryCache();

            cache.Remove("Not actually something that is in this cache.");
        }
Beispiel #2
0
        public void Get_Calls_Source_Get_Transformer_Transform_Validator_Validate_And_Coercer_Coerce_Twice_Each_When_Callback_Invoked_Via_Property_Twice_When_Using_A_Real_Cache_Implementation_And_The_Property_Is_Removed_From_The_Cache_In_Between()
        {
            const string name = ConfigWrapper<object>.ThePropertyName;

            var expectedRaw = "{}";
            var expectedValue = new object();
            var cache = new DictionaryCache();

            var sourceMock = new Mock<IValueSource>();
            sourceMock.Setup(s => s.Get(name, It.IsAny<PropertyInfo>(), out expectedRaw))
                .Returns(true);

            var transformerMock = new Mock<IValueTransformer>();
            transformerMock.Setup(x => x.Transform(expectedRaw, name, It.IsAny<PropertyInfo>()))
                .Returns(expectedRaw);

            var validatorMock = new Mock<IValueValidator>();
            validatorMock.Setup(s => s.Validate(expectedRaw, name, It.IsAny<PropertyInfo>(), out expectedValue))
                .Returns(false);

            var coercerMock = new Mock<IValueCoercer>();
            coercerMock.Setup(c => c.Coerce(expectedRaw, name, It.IsAny<PropertyInfo>(), out expectedValue))
                .Returns(true);

            var config = new ConfigWrapper<object>(cache, sourceMock.Object, transformerMock.Object, validatorMock.Object, coercerMock.Object);

            var result1 = config.TheProperty;
            cache.Remove(name);
            var result2 = config.TheProperty;

            sourceMock.Verify(s => s.Get(name, It.IsAny<PropertyInfo>(), out expectedRaw), Times.Exactly(2));
            transformerMock.Verify(x => x.Transform(expectedRaw, name, It.IsAny<PropertyInfo>()), Times.Exactly(2));
            validatorMock.Verify(v => v.Validate(expectedRaw, name, It.IsAny<PropertyInfo>(), out expectedValue), Times.Exactly(2));
            coercerMock.Verify(c => c.Coerce(expectedRaw, name, It.IsAny<PropertyInfo>(), out expectedValue), Times.Exactly(2));
            Assert.AreEqual(expectedValue, result1);
            Assert.AreSame(result1, result2);
        }