コード例 #1
0
        public void GetTradeDate_WhenTradeDateExists_ReturnsTradeDate()
        {
            // Arrange
            DateTime date = new DateTime(2018, 12, 31);

            Mock <ITradeDateRepository> tradeDateRepository = new Mock <ITradeDateRepository>();
            TradeDate tradeDate = new TradeDate(new DateTime(2018, 12, 31), true, true, true);

            tradeDateRepository.Setup(r => r.GetTradeDate(date))
            .Returns(Maybe.Create <TradeDate>(tradeDate));

            // Act
            TradeDateService service = new TradeDateService(tradeDateRepository.Object);
            var result = service.GetTradeDate(date);

            // Assert
            result.IsSuccess.Should().BeTrue();
            result.Value.Should().Be(tradeDate);
        }
コード例 #2
0
        public void GetTradeDate_WhenTradeDateDoesNotExist_ReturnsInvalidTradeDateErrorResult()
        {
            // Arrange
            DateTime date = new DateTime(2018, 12, 31);

            Mock <ITradeDateRepository> tradeDateRepository = new Mock <ITradeDateRepository>();

            tradeDateRepository.Setup(r => r.GetTradeDate(date))
            .Returns(Maybe.Create <TradeDate>(null));

            // Act
            TradeDateService service = new TradeDateService(tradeDateRepository.Object);
            var result = service.GetTradeDate(date);

            // Assert
            result.IsSuccess.Should().BeFalse();
            result.Error.Should().BeOfType <InvalidTradeDateError>();
            ((InvalidTradeDateError)result.Error).Date.Should().Be(date);
            result.Value.Should().BeNull();
        }