public void GetAccountReturnsCachedAccountTest() { var expected = new Account { Id = Guid.NewGuid(), Provider = Guid.NewGuid().ToString(), Subject = Guid.NewGuid().ToString() }; var username = expected.Provider + "|" + expected.Subject; var cacheKey = "Account|" + username; var cache = Substitute.For <IMemoryCache>(); var config = Substitute.For <ICacheConfig>(); object value; cache.TryGetValue(cacheKey, out value).Returns( x => { x[1] = expected.Id; return(true); }); var sut = new AccountCache(cache, config); var actual = sut.GetAccount(username); actual.Should().BeEquivalentTo(expected); }
public void GetAccountThrowsExceptionWithInvalidUsernameTest(string username) { var cache = Substitute.For <IMemoryCache>(); var config = Substitute.For <ICacheConfig>(); var sut = new AccountCache(cache, config); Action action = () => sut.GetAccount(username); action.Should().Throw <ArgumentException>(); }
public void GetAccountReturnsNullWhenCachedAccountNotFoundTest() { var username = Guid.NewGuid().ToString(); var cacheKey = "Account|" + username; var cache = Substitute.For <IMemoryCache>(); var config = Substitute.For <ICacheConfig>(); object value; cache.TryGetValue(cacheKey, out value).Returns(x => false); var sut = new AccountCache(cache, config); var actual = sut.GetAccount(username); actual.Should().BeNull(); }