public async Task <IActionResult> Put(string id, [FromBody] UpdateGarmentScrapTransactionCommand command) { Guid guid = Guid.Parse(id); command.SetIdentity(guid); VerifyUser(); var order = await Mediator.Send(command); return(Ok(order.Identity)); }
public async Task Handle_StateUnderTest_ExpectedBehavior() { Guid scrapdestinationId = Guid.NewGuid(); Guid scrapsourceid = Guid.NewGuid(); Guid scrapclassificationid = Guid.NewGuid(); Guid scrapIdentity = Guid.NewGuid(); UpdateGarmentScrapTransactionCommandHandler unitUnderTest = CreateUpdateGarmentScrapTransactionCommandHandler(); CancellationToken cancellationToken = CancellationToken.None; _mockScrapStockRepository .Setup(s => s.Query) .Returns(new List <GarmentScrapStockReadModel> { new GarmentScrapStock(new Guid(), scrapdestinationId, "destination", scrapclassificationid, "name", 100, 1, "KG").GetReadModel() }.AsQueryable()); _mockScrapTransactionRepository .Setup(s => s.Query) .Returns(new List <GarmentScrapTransactionReadModel> { new GarmentScrapTransaction(scrapIdentity, "", "IN", DateTimeOffset.Now, scrapsourceid, "", scrapdestinationId, "").GetReadModel() }.AsQueryable()); _mockScrapTransactionItemRepository .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentScrapTransactionItemReadModel, bool> > >())) .Returns(new List <GarmentScrapTransactionItem>() { new GarmentScrapTransactionItem(new Guid(), scrapIdentity, scrapclassificationid, "", 100, 1, "KG", "") }); UpdateGarmentScrapTransactionCommand updateGarmentScrapTransactionCommand = new UpdateGarmentScrapTransactionCommand() { TransactionType = "IN", TransactionDate = DateTimeOffset.Now, ScrapDestinationId = scrapdestinationId, ScrapDestinationName = "destination", ScrapSourceId = scrapsourceid, ScrapSourceName = "source", TransactionNo = "", Items = new List <GarmentScrapTransactionItemValueObject> { new GarmentScrapTransactionItemValueObject { ScrapClassificationId = scrapclassificationid, ScrapClassificationName = "name", Quantity = 1000, UomId = 1, UomUnit = "KG", Description = "desc" } }, }; updateGarmentScrapTransactionCommand.SetIdentity(scrapIdentity); _mockScrapTransactionRepository .Setup(s => s.Update(It.IsAny <GarmentScrapTransaction>())) .Returns(Task.FromResult(It.IsAny <GarmentScrapTransaction>())); _mockScrapTransactionItemRepository .Setup(s => s.Update(It.IsAny <GarmentScrapTransactionItem>())) .Returns(Task.FromResult(It.IsAny <GarmentScrapTransactionItem>())); _mockScrapStockRepository .Setup(s => s.Update(It.IsAny <GarmentScrapStock>())) .Returns(Task.FromResult(It.IsAny <GarmentScrapStock>())); _MockStorage .Setup(x => x.Save()) .Verifiable(); // Act var result = await unitUnderTest.Handle(updateGarmentScrapTransactionCommand, cancellationToken); // Assert result.Should().NotBeNull(); }