Ejemplo n.º 1
0
    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);
    }
Ejemplo n.º 2
0
    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);
    }
Ejemplo n.º 3
0
    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);
Ejemplo n.º 4
0
    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);
    }
Ejemplo n.º 5
0
    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);
    }
Ejemplo n.º 6
0
    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);
    }