public void Sell_PriceMatchingRequest_DealMadeAsSellWithSellerPrice_Test() { var targetRequest = new PumpkinDeal() { Buyer = "Test buyer", BuyPrice = 10, Seller = null, SellPrice = null, DealPrice = null, DealType = null, SubmitionTime = DateTime.UtcNow }; var dataSource = Substitute.For <IRepository <PumpkinDeal> >(); dataSource.Get().Returns( new List <PumpkinDeal>() { targetRequest }.AsQueryable()); var target = new PumpkinTradeService(dataSource); var result = target.Sell("Test seller", 8); Assert.Multiple(() => { Assert.True(result); Assert.True(targetRequest.DealType == EDealType.Sell); Assert.True(targetRequest.SellPrice == targetRequest.DealPrice); }); Console.Write(target.GetProcessedTrades()); }
public void Flow_ExampleProvidedInTaskDescription_Test() { var dataSource = PumpkinDealListRepository.Instance; var target = new PumpkinTradeService(dataSource); var result1 = target.Buy("A", 10); var result2 = target.Buy("B", 11); var result3 = target.Sell("C", 15); var result4 = target.Sell("D", 9); var result5 = target.Buy("E", 10); var result6 = target.Sell("F", 10); var result7 = target.Buy("G", 100); Assert.Multiple(() => { Assert.False(result1); Assert.False(result2); Assert.False(result3); Assert.True(result4); Assert.False(result5); Assert.True(result6); Assert.True(result7); }); Console.Write(target.GetProcessedTrades()); }
public void GetProcessedTrades_OnlyProcessedReturned() { var dataSource = Substitute.For <IRepository <PumpkinDeal> >(); dataSource.Get().Returns( new List <PumpkinDeal>() { new PumpkinDeal() { Buyer = "Test buyer", BuyPrice = 10, Seller = null, SellPrice = null, DealPrice = null, DealType = null, SubmitionTime = DateTime.UtcNow }, new PumpkinDeal() { Buyer = null, BuyPrice = null, Seller = "Test seller", SellPrice = 10, DealPrice = null, DealType = null, SubmitionTime = DateTime.UtcNow }, new PumpkinDeal() { Buyer = "Test buyer", BuyPrice = 10, Seller = "Test seller", SellPrice = 8, DealPrice = 10, DealType = EDealType.Buy, SubmitionTime = DateTime.UtcNow }, new PumpkinDeal() { Buyer = "Test buyer", BuyPrice = 10, Seller = "Test seller", SellPrice = 8, DealPrice = 8, DealType = EDealType.Sell, SubmitionTime = DateTime.UtcNow } }.AsQueryable()); var target = new PumpkinTradeService(dataSource); var result = target.GetProcessedTrades(); Assert.True(result.Split('\n').Length == 2); Console.Write(result); }
public void Sell_NoRequests_TradeNotProcessed_Test() { var dataSource = Substitute.For <IRepository <PumpkinDeal> >(); dataSource.Get().Returns( new List <PumpkinDeal>() .AsQueryable()); var target = new PumpkinTradeService(dataSource); var result = target.Sell("Test seller", 8); Assert.False(result); }
public void Sell_PriceLessThenRequest_TradeProcessed_Test() { var dataSource = Substitute.For <IRepository <PumpkinDeal> >(); dataSource.Get().Returns( new List <PumpkinDeal>() { new PumpkinDeal() { Buyer = "Test buyer", BuyPrice = 10, Seller = null, SellPrice = null, DealPrice = null, DealType = null, SubmitionTime = DateTime.UtcNow } }.AsQueryable()); var target = new PumpkinTradeService(dataSource); var result = target.Sell("Test seller", 8); Assert.True(result); }