public async Task CallsBothDatastoresCorrectly() { await _sut.DeleteToken("foo"); await _cache.Received(1).RemoveAsync("foo"); await _tokenDb.Received(1).DeleteToken("foo"); }
public async Task ReturnsValuesThatExistInSQL_ButNotInCache(string expectedKey, string expectedValue) { _cache.GetAsync(expectedKey).Returns <byte[]>(x => null); _tokenDb.GetToken(expectedKey).Returns(new Models.Token() { Key = expectedKey, Value = expectedValue }); var expectedToken = await _sut.GetToken(expectedKey); Assert.IsType <Models.Token>(expectedToken); Assert.Equal(expectedKey, expectedToken.Key); Assert.Equal(expectedValue, expectedToken.Value); await _cache.Received(1).GetAsync(expectedKey); await _tokenDb.Received(1).GetToken(expectedKey); }
public async Task EnsureTokenIsWrittenToBothCacheAndDB() { var valueAsBytes = Encoding.ASCII.GetBytes("bar"); await _sut.InsertToken("foo", "bar"); await _tokenDb.Received(1).InsertToken("foo", "bar"); await _cache.Received(1) .SetAsync( "foo", Arg.Is <byte[]>(x => valueAsBytes.SequenceEqual(x)), Arg.Any <DistributedCacheEntryOptions>(), Arg.Any <System.Threading.CancellationToken>() ); }