Beispiel #1
0
        public async Task Should_Not_Cache_Exceptions()
        {
            Assert.AreEqual(0, StockQuoteHandler.Called);
            var getQuote = new GetStockQuote("EX");

            try
            {
                await _mediator.SendAsync(getQuote.Cached());

                Assert.Fail("Expected exception");
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Stock Exchange is down", ex.Message);
            }
            try
            {
                await _mediator.SendAsync(getQuote.Cached());

                Assert.Fail("Expected exception");
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Stock Exchange is down", ex.Message);
            }
            Assert.AreEqual(2, StockQuoteHandler.Called);
        }
Beispiel #2
0
        public async Task Should_Make_Initial_Request()
        {
            Assert.AreEqual(0, StockQuoteHandler.Called);
            var getQuote = new GetStockQuote("AAPL");
            var quote    = await _mediator.SendAsync(getQuote.Cached());

            Assert.AreEqual(1, StockQuoteHandler.Called);
        }
Beispiel #3
0
        public async Task Should_Cache_Initial_Response()
        {
            Assert.AreEqual(0, StockQuoteHandler.Called);
            var getQuote = new GetStockQuote("AAPL");
            var quote1   = await _mediator.SendAsync(getQuote.Cached());

            var quote2 = await _mediator.SendAsync(getQuote.Cached());

            Assert.AreEqual(1, StockQuoteHandler.Called);
            Assert.AreEqual(quote1.Value, quote2.Value);
        }
Beispiel #4
0
        public async Task Should_Refresh_Response_If_Old()
        {
            Assert.AreEqual(0, StockQuoteHandler.Called);
            var getQuote = new GetStockQuote("AAPL");
            await _mediator.SendAsync(getQuote.Cached());

            await Task.Delay(TimeSpan.FromSeconds(.2));

            await _mediator.SendAsync(getQuote.Cached(TimeSpan.FromSeconds(.1)));

            Assert.AreEqual(2, StockQuoteHandler.Called);
        }
Beispiel #5
0
        public async Task Should_Invalidate_Cache()
        {
            Assert.AreEqual(0, StockQuoteHandler.Called);
            var getQuote = new GetStockQuote("AAPL");
            var quote1   = await _mediator.SendAsync(getQuote.Cached());

            var quote2 = await _mediator.SendAsync(getQuote.Cached());

            var quote3 = await _mediator.SendAsync(getQuote.InvalidateCache());

            var quote4 = await _mediator.SendAsync(getQuote.Cached());

            Assert.AreEqual(2, StockQuoteHandler.Called);
            Assert.AreEqual(quote1.Value, quote2.Value);
            Assert.AreEqual(quote1.Value, quote3.Value);
            Assert.AreEqual(quote1.Value, quote3.Value);
        }
Beispiel #6
0
 public bool Equals(GetStockQuote other)
 {
     return(Symbol == other.Symbol);
 }