Exemplo n.º 1
0
        public async Task CacheAsync_CalledWithKeyAndValue_CallsStoreInImplementation()
        {
            await Cache.CacheAsync(User.Test);

            CacheImplementationMock
            .Verify(i => i.CacheAsync(KEY, User.Test, It.IsAny <CacheOptions>()), Times.Once);
        }
Exemplo n.º 2
0
        public async Task RetrieveAsync_CalledWithKey_CallsRetrieveInImplementation()
        {
            var result = await Cache.RetrieveAsync <User>(KEY);

            CacheImplementationMock
            .Verify(i => i.RetrieveAsync <User>(KEY), Times.Once);
        }
Exemplo n.º 3
0
        public async Task RetrieveAsync_MissingConfiguration_ThrowsException()
        {
            Func <Task> cacheAsync = async() => await Cache.CacheAsync(Order.Test);

            await cacheAsync.Should().ThrowAsync <ConfigurationNotFoundException>();

            CacheImplementationMock
            .Verify(i => i.CacheAsync(It.IsAny <string>(), It.IsAny <User>(), It.IsAny <CacheOptions>()), Times.Never);
        }
Exemplo n.º 4
0
        public async Task RetrieveAsync_MissingConfiguration_ThrowsException()
        {
            Func <Task <Order> > retrieveAsync = async() => await Cache.RetrieveAsync <Order>(new { Id = 1, LastName = "Test" });

            await retrieveAsync.Should().ThrowAsync <ConfigurationNotFoundException>();

            CacheImplementationMock
            .Verify(i => i.RetrieveAsync <Order>(It.IsAny <string>()), Times.Never);
        }
        public async Task CacheAsync_GenericImplementation_UsesGenericCache()
        {
            var cache = CacheBuilder
                        .For <User>(u => u.UseAsKey(KEY).Complete())
                        .Build();

            await cache.CacheAsync(User.Test);

            CacheImplementationMock
            .Verify(i => i.CacheAsync(KEY, User.Test, It.IsAny <CacheOptions>()), Times.Once);
        }
        public async Task CacheAsync_SpecificImplementation_UsesSpecificCache()
        {
            var cache = CacheBuilder
                        .For <User>(u => u.UseAsKey(KEY).Complete(_userSpecificImplementationMock.Object))
                        .Build();

            await cache.CacheAsync(User.Test);

            _userSpecificImplementationMock
            .Verify(i => i.CacheAsync(KEY, User.Test, It.IsAny <CacheOptions>()), Times.Once);
            CacheImplementationMock
            .Verify(i => i.CacheAsync(It.IsAny <string>(), It.IsAny <User>(), It.IsAny <CacheOptions>()), Times.Never);
        }