示例#1
0
        public void RedisCache_Delete_ValidKey_ShouldReturn()
        {
            //--------------Arrange------------------------------
            var mockConnection = new Mock <IRedisConnection>();
            var mockDatabase   = new Mock <IRedisCache>();

            mockDatabase.Setup(db => db.Remove("bob")).Verifiable();
            mockConnection.Setup(conn => conn.Cache).Returns(mockDatabase.Object);
            var redis = new RedisCacheStub(() => mockConnection.Object);

            //--------------Act----------------------------------
            redis.Remove("bob");
            //--------------Assert-------------------------------
            mockDatabase.Verify(db => db.Remove("bob"), Times.Once);
        }
示例#2
0
        public void RedisCache_Delete_NullKey_ShouldThrowArgumentNullException()
        {
            //--------------Arrange------------------------------
            var ext            = System.Threading.Tasks.TaskExtensions.Unwrap(new System.Threading.Tasks.Task <System.Threading.Tasks.Task>(() => System.Threading.Tasks.Task.FromResult(true)));
            var mockConnection = new Mock <IRedisConnection>();
            var mockDatabase   = new Mock <IRedisCache>();

            mockDatabase.Setup(db => db.Remove(It.IsAny <string>())).Verifiable();
            mockConnection.Setup(conn => conn.Cache).Returns(mockDatabase.Object);
            var redis = new RedisCacheStub(() => mockConnection.Object);

            //--------------Act----------------------------------
            redis.Remove(null);
            //--------------Assert-------------------------------
        }