public async Task RemoveAsync_ShouldRemove() { var distributedCacheMock = new Mock <IDistributedCache>(); distributedCacheMock.Setup(c => c.RemoveAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())) .Verifiable(); var cache = new DistributedFlow(distributedCacheMock.Object); await cache.RemoveAsync("Key"); distributedCacheMock.Verify(c => c.RemoveAsync(It.IsAny <string>(), It.IsAny <CancellationToken>()), Times.Once); }
public void Remove_ShouldRemove() { var distributedCacheMock = new Mock <IDistributedCache>(); distributedCacheMock.Setup(c => c.Remove(It.IsAny <string>())) .Verifiable(); var cache = new DistributedFlow(distributedCacheMock.Object); cache.Remove("Key"); distributedCacheMock.Verify(c => c.Remove(It.IsAny <string>()), Times.Once); }
public void TryGetValue_ShouldNotGetValueWhenValueIsDefaultUserDefinedStruct() { var distributedCacheMock = new Mock <IDistributedCache>(); distributedCacheMock.Setup(c => c.Get(It.IsAny <string>())) .Returns((byte[])null) .Verifiable(); var cache = new DistributedFlow(distributedCacheMock.Object); var isSuccess = cache.TryGetValue("key", out DefaultStruct result); Assert.False(isSuccess); Assert.Equal(default, result);
public void TryGetValue_ShouldNotGetValueWhenValueIsNull() { var distributedCacheMock = new Mock <IDistributedCache>(); distributedCacheMock.Setup(c => c.Get(It.IsAny <string>())) .Returns((byte[])null) .Verifiable(); var cache = new DistributedFlow(distributedCacheMock.Object); var result = cache.TryGetValue <object>("key", out _); Assert.False(result); distributedCacheMock.Verify(c => c.Get(It.IsAny <string>()), Times.Once); }
public void Set_ShouldSetValueWhenValueIsDefaultPrimitiveStruct() { var distributedCacheMock = new Mock <IDistributedCache>(); distributedCacheMock.Setup(c => c.Set(It.IsAny <string>(), It.IsAny <byte[]>(), It.IsAny <DistributedCacheEntryOptions>())) .Verifiable(); var cache = new DistributedFlow(distributedCacheMock.Object); cache.Set("Key", default(int), TimeSpan.MaxValue); distributedCacheMock .Verify(c => c.Set(It.IsAny <string>(), It.IsAny <byte[]>(), It.IsAny <DistributedCacheEntryOptions>()), Times.Once); }
public void Set_ShouldNotSetValueWhenValueIsDefaultUserDefinedStruct() { var distributedCacheMock = new Mock <IDistributedCache>(); distributedCacheMock.Setup(c => c.Set(It.IsAny <string>(), It.IsAny <byte[]>(), It.IsAny <DistributedCacheEntryOptions>())) .Verifiable(); var cache = new DistributedFlow(distributedCacheMock.Object); cache.Set("Key", new DefaultStruct(0), TimeSpan.MaxValue); distributedCacheMock.Verify( c => c.Set(It.IsAny <string>(), It.IsAny <byte[]>(), It.IsAny <DistributedCacheEntryOptions>()), Times.Never); }