public void The_method_Reborn_should_try_to_refresh_the_cache() { // Arrange var wait = SetUp("GetById"); var phoenix = new Phoenix(_invocation, CacheInfo); // Action phoenix.Reborn(); // Assert Assert.IsTrue(wait.WaitOne(2000)); Global.CacheStoreProvider.GetCacheStore(StoreId).Received(1) .Set("cacheKey", Arg.Is<object>(obj => _id.Equals(((CacheItem) obj).Data)), Arg.Any<DateTimeOffset>()); }
public void The_method_Reborn_should_dispose_and_return_DisposingPhoenix_if_cannot_create_new_cacheItem() { // Arrange var svc = Substitute.For<IUserService>(); svc.GetById(Arg.Any<Guid>()).Returns(null); var wait = SetUp(nameof(IUserService.GetById), svc); var phoenix = new Phoenix(_invocation, CacheInfo); // Action phoenix.Reborn(); Assert.IsTrue(wait.WaitOne(_waitTime)); // Assert var storeId = Global.CacheStoreProvider.GetAsyncCacheStore(StoreId); storeId.Received(1).RemoveAsync("cacheKey"); }
public void The_method_Reborn_should_throw_if_error_and_retry_after_1_second() { // Arrange var svc = Substitute.For<IUserService>(); var wait = SetUp(nameof(IUserService.GetById), svc); svc.When(x => x.GetById(Arg.Any<Guid>())).Do(c => { wait.Set(); throw new Exception(); }); var phoenix = new Phoenix(_invocation, CacheInfo); // Action phoenix.Reborn(); Assert.IsTrue(wait.WaitOne(_waitTime)); wait.Reset(); Assert.IsTrue(wait.WaitOne(_waitTime)); // Assert svc.Received(2).GetById(Arg.Any<Guid>()); }
public void The_method_Reborn_should_work_with_async_method() { // Arrange var wait = SetUp(nameof(IUserService.GetByIdAsync)); var phoenix = new Phoenix(_invocation, CacheInfo); // Action phoenix.Reborn(); // Assert Assert.IsTrue(wait.WaitOne(_waitTime)); Global.CacheStoreProvider.GetAsyncCacheStore(StoreId).Received(1) .SetAsync("cacheKey", Arg.Is<object>(obj => _id.Equals(((CacheItem)obj).Data)), Arg.Any<DateTimeOffset>()); }