Пример #1
0
        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);
            });
        }
Пример #2
0
        public async Task CalculateNetWorth_SingleItem()
        {
            var guid      = Guid.NewGuid();
            var portfolio = new List <StockHolding>
            {
                new StockHolding("FOO", 10)
            };

            authService.Stub(x => x.AuthenticateUserAsync("jon", "pass")).Return(Delayed <Guid?>(100, guid));
            portfolioService.Stub(x => x.GetPortfolioAsync(guid)).Return(Delayed(200, portfolio));
            priceService.Stub(x => x.LookupPriceAsync("FOO")).Return(Delayed <decimal?>(300, 34.25m));

            Assert.AreEqual(10 * 34.25m, await broker.CalculateWorthAsync("jon", "pass"));
        }