Skip to content

Instantly share code, notes, and snippets.

Last active November 5, 2017 21:03
What would you like to do?
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>()
#region setup the log service
var logServiceMock = new Mock<ILogService>().Log_Mock("Should not get called");
StocksLogic stocksLogic = new StocksLogic(stockServiceMock.Object, logServiceMock.Object);
Trade theBuy = stocksLogic.GetRich("ABC");
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