public void CalculateNetWorth_SingleItem() { var tardis = new TimeMachine(); var guid = Guid.NewGuid(); var portfolio = new List <StockHolding> { new StockHolding("FOO", 10) }; var loginResult = tardis.ScheduleSuccess <Guid?>(1, guid); var portfolioResult = tardis.ScheduleSuccess(2, portfolio); var priceResult = tardis.ScheduleSuccess <decimal?>(3, 34.25m); authService.Stub(x => x.AuthenticateUserAsync("jon", "pass")).Return(loginResult); portfolioService.Stub(x => x.GetPortfolioAsync(guid)).Return(portfolioResult); priceService.Stub(x => x.LookupPriceAsync("FOO")).Return(priceResult); tardis.ExecuteInContext(advancer => { var worth = broker.CalculateWorthAsync("jon", "pass"); // Not complete until auth has completed... Assert.IsFalse(worth.IsCompleted); advancer.Advance(); // Not complete until portfolio fetch has completed... Assert.IsFalse(worth.IsCompleted); advancer.Advance(); // Not complete until price fetch has completed... Assert.IsFalse(worth.IsCompleted); advancer.Advance(); AssertCompletion(worth, 10 * 34.25m); }); }
public void CalculateNetWorth_MultipleItems_IncludingNullValue() { var tardis = new TimeMachine(); var guid = Guid.NewGuid(); var portfolio = new List <StockHolding> { new StockHolding("FOO", 10), new StockHolding("BAR", 5) }; var loginResult = tardis.ScheduleSuccess <Guid?>(1, guid); var portfolioResult = tardis.ScheduleSuccess(2, portfolio); var fooResult = tardis.ScheduleSuccess <decimal?>(3, 20m); var barResult = tardis.ScheduleSuccess <decimal?>(4, null); authService.Stub(x => x.AuthenticateUserAsync("jon", "pass")).Return(loginResult); portfolioService.Stub(x => x.GetPortfolioAsync(guid)).Return(portfolioResult); priceService.Stub(x => x.LookupPriceAsync("FOO")).Return(fooResult); priceService.Stub(x => x.LookupPriceAsync("BAR")).Return(barResult); tardis.ExecuteInContext(advancer => { var worth = broker.CalculateWorthAsync("jon", "pass"); advancer.AdvanceBy(4); AssertCompletion(worth, 10 * 20m); }); }
public void CalculateNetWorth_EmptyPortfolio() { var tardis = new TimeMachine(); var guid = Guid.NewGuid(); var loginResult = tardis.ScheduleSuccess <Guid?>(1, guid); var portfolioResult = tardis.ScheduleSuccess(2, new List <StockHolding>()); authService.Stub(x => x.AuthenticateUserAsync("jon", "pass")).Return(loginResult); portfolioService.Stub(x => x.GetPortfolioAsync(guid)).Return(portfolioResult); tardis.ExecuteInContext(advancer => { var worth = broker.CalculateWorthAsync("jon", "pass"); Assert.IsFalse(worth.IsCompleted); advancer.Advance(); Assert.IsFalse(worth.IsCompleted); advancer.Advance(); AssertCompletion(worth, 0); }); }
public void CalculateNetWorthAsync_AuthenticationFailure_ThrowsDelayed() { var tardis = new TimeMachine(); var failedLogin = tardis.ScheduleSuccess <Guid?>(1, null); authService.Stub(x => x.AuthenticateUserAsync("jon", "pass")).Return(failedLogin); tardis.ExecuteInContext(advancer => { var worth = broker.CalculateWorthAsync("jon", "pass"); Assert.IsFalse(worth.IsCompleted); advancer.Advance(); AssertFaulted <AuthenticationException>(worth); }); }