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()); }
private bool ThreadSafeSell(PumpkinDeal deal, string userName, decimal price) { lock (deal) { if (deal.SellPrice == null) { deal.Seller = userName; deal.SellPrice = price; deal.DealPrice = price; deal.DealType = EDealType.Sell; deal.DealTime = DateTime.UtcNow; return(true); } return(Sell(userName, price)); } }
internal static string GetDealResult(this PumpkinDeal deal) { return(deal.DealType == EDealType.Buy ? $"{deal.Buyer} bought a pumpkin from {deal.Seller} for {deal.DealPrice.Value.ToString("C0",new CultureInfo("fr-FR"))}" : $"{deal.Seller} sold a pumpkin to {deal.Buyer} for {deal.DealPrice.Value.ToString("C0", new CultureInfo("fr-FR"))}"); }