private void SetupServiceMock() { _serviceMock = Substitute.For <ICachingTestService>(); _serviceMock.CallService().Returns(_ => { return(Task.FromResult(_serviceResult)); }); _serviceMock.CallServiceWithAttRefreshTime().Returns(_ => { return(Task.FromResult(_serviceResult)); }); _serviceMock.CallServiceWithoutAttRefreshTime().Returns(_ => { return(Task.FromResult(_serviceResult)); }); _serviceMock.CallRevocableService(Arg.Any <string>()).Returns(async s => { var result = _serviceResult; await _revokeDelay; return(new Revocable <string> { Value = result, RevokeKeys = new[] { s.Args()[0].ToString() } }); }); _serviceResult = FirstResult; var serviceProxyMock = Substitute.For <IServiceProxyProvider <ICachingTestService> >(); serviceProxyMock.Client.Returns(_serviceMock); _kernel.Rebind <IServiceProxyProvider <ICachingTestService> >().ToConstant(serviceProxyMock); }
private void SetupServiceMock() { _serviceMock = Substitute.For <ICachingTestService>(); _serviceMock.CallService().Returns(_ => Task.FromResult(_serviceResult)); _serviceResult = FirstResult; var serviceProxyMock = Substitute.For <IServiceProxyProvider <ICachingTestService> >(); serviceProxyMock.Client.Returns(_serviceMock); _kernel.Rebind <IServiceProxyProvider <ICachingTestService> >().ToConstant(serviceProxyMock); }
public async Task CallWhileRefreshShouldReturnOldValueAndAfterRefreshTheNewValue() { TimeSpan expectedRefreshTime = TimeSpan.FromSeconds(10); await SetCachingPolicyConfig(new[] { "RefreshTime", expectedRefreshTime.ToString() }); var result = await _proxy.CallService(); result.ShouldBe(FirstResult); _now += expectedRefreshTime; _serviceResult = SecondResult; result = await _proxy.CallService(); //trigger a refresh, but until it will finish, return old result result.ShouldBe(FirstResult); await Task.Delay(100); //wait for refresh to end result = await _proxy.CallService(); result.ShouldBe(SecondResult); //refreshed value should be returned }
private async Task TriggerCacheRefreshOnBackground() { await _proxy.CallService(); }