コード例 #1
0
        public void ExecuteTrade_WhenMetWithOneQuote_JustEnoughVolume_ReturnsTradeResult()
        {
            // Arrange
            const string symbol                = "TestSymbol";
            const uint   volumeRequested       = 100;
            const uint   uneededVolume         = 500;
            const double price                 = 10.00d;
            const double expectedWeightedPrice = 10.00d;// (price * volumeRequested) / volumeRequested

            var sufficientQuote = new Quote(symbol, price, volumeRequested, DateTime.Now.AddDays(1));
            var uneededQuote    = new Quote(symbol, price + 0.15d, uneededVolume, DateTime.Now.AddDays(2));

            var quotes = new List <IQuote>
            {
                sufficientQuote,
                uneededQuote
            };

            _quoteRepoMock[symbol].Returns(quotes);

            // Act
            var tradeResult = _quoteManager.ExecuteTrade(symbol, volumeRequested);

            // Assert
            Assert.IsNotNull(tradeResult);
            Assert.AreNotEqual(Guid.Empty, tradeResult.Id);
            Assert.AreEqual(symbol, tradeResult.Symbol);
            Assert.AreEqual(volumeRequested, tradeResult.VolumeRequested);
            Assert.AreEqual(volumeRequested, tradeResult.VolumeExecuted);
            Assert.AreEqual(expectedWeightedPrice, tradeResult.VolumeWeightedAveragePrice);
            Assert.AreEqual(0, sufficientQuote.AvailableVolume);
            Assert.AreEqual(uneededVolume, uneededQuote.AvailableVolume);
        }