This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
public void BuyWhenLastTradeWasSell_Test() | |
{ | |
#region setup the stock service | |
decimal simulatedCurrentPrice = 8.03m; | |
Trade simulatedLastTrade = new Trade | |
{ | |
Ticker = "ABC", | |
Side = "sell", | |
TradeDate = DateTimeOffset.Now.AddHours(-1), | |
TradePrice = 10.00m | |
}; | |
Trade simulatedBuy = new Trade | |
{ | |
Ticker = "ABC", | |
Side = "buy", | |
TradeDate = DateTimeOffset.Now, | |
TradePrice = 11.50m | |
}; | |
//Here we simulate the current price being lower than 15% less | |
//than our last sell. | |
//This should exercise the logic of a sell only. | |
var stockServiceMock = new Mock<IStockService>() | |
.GetCurrentPrice_Mock(simulatedCurrentPrice) | |
.GetLastTrade_Mock(simulatedLastTrade) | |
.Buy_Mock(simulatedBuy); | |
#endregion | |
#region setup the log service | |
var logServiceMock = new Mock<ILogService>().Log_Mock("Should not get called"); | |
#endregion | |
StocksLogic stocksLogic = new StocksLogic(stockServiceMock.Object, logServiceMock.Object); | |
Trade theBuy = stocksLogic.GetRich("ABC"); | |
Assert.IsNotNull(theBuy); | |
Assert.AreEqual("buy", theBuy.Side); | |
Assert.AreEqual(theBuy.TradeDate, simulatedBuy.TradeDate, "Simulated buy date equals buy date"); | |
stockServiceMock.Verify(m => m.Buy(It.IsAny<string>(), It.IsAny<decimal>()), Times.Once); | |
stockServiceMock.Verify(m => m.Sell(It.IsAny<string>(), It.IsAny<decimal>()), Times.Never); | |
//Only exception will log so validate log was not called | |
logServiceMock.Verify(m => m.Log(It.IsAny<string>()), Times.Never); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment