public async Task <IActionResult> Delete(string id) { VerifyUser(); var deliveryReturnId = Guid.Parse(id); if (!Guid.TryParse(id, out Guid orderId)) { return(NotFound()); } var garmentDeliveryReturnItems = _garmentDeliveryReturnItemRepository.Find(x => x.DRId == deliveryReturnId); foreach (var item in garmentDeliveryReturnItems) { if (item.ProductName != "FABRIC") { await PutGarmentUnitExpenditureNoteCreateForDeliveryReturn(item.UENItemId, 0, item.Quantity); } } ; var command = new RemoveGarmentDeliveryReturnCommand(); command.SetId(orderId); var order = await Mediator.Send(command); return(Ok(order.Identity)); }
public async Task Handle_StateUnderTest_ExpectedBehavior() { // Arrange Guid id = Guid.NewGuid(); RemoveGarmentDeliveryReturnCommandHandler unitUnderTest = CreateRemoveGarmentDeliveryReturnCommandHandler(); CancellationToken cancellationToken = CancellationToken.None; _mockGarmentDeliveryReturnRepository .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentDeliveryReturnReadModel, bool> > >())) .Returns(new List <GarmentDeliveryReturn>() { new GarmentDeliveryReturn(id, "drNo", "roNo", "article", 1, "unitDONo", 1, "preparingId", DateTimeOffset.Now, "returnType", new UnitDepartmentId(1), "unitCode", "unitName", new StorageId(1), "storageName", "storageCode", true) }); _mockGarmentDeliveryReturnItemRepository .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentDeliveryReturnItemReadModel, bool> > >())) .Returns(new List <GarmentDeliveryReturnItem>() { new GarmentDeliveryReturnItem(id, id, 1, 1, "preparingItemId", new ProductId(1), "productCode", "FABRIC", "designColor", "roNo", 1, new UomId(1), "uomUnit") }); _mockGarmentDeliveryReturnItemRepository .Setup(s => s.Update(It.IsAny <GarmentDeliveryReturnItem>())) .Returns(Task.FromResult(It.IsAny <GarmentDeliveryReturnItem>())); GarmentPreparingItem garmentPreparingItem = new GarmentPreparingItem(id, 1, new Domain.GarmentPreparings.ValueObjects.ProductId(1), "productCode", "productName", "designColor", 1, new Domain.GarmentPreparings.ValueObjects.UomId(1), "uomUnit", "FABRIC", 1, 1, id, null); _mockGarmentPreparingItemRepository .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentPreparingItemReadModel, bool> > >())) .Returns(new List <GarmentPreparingItem>() { garmentPreparingItem }); _mockGarmentPreparingItemRepository .Setup(s => s.Update(It.IsAny <GarmentPreparingItem>())) .Returns(Task.FromResult(It.IsAny <GarmentPreparingItem>())); _mockGarmentDeliveryReturnRepository .Setup(s => s.Update(It.IsAny <GarmentDeliveryReturn>())) .Returns(Task.FromResult(It.IsAny <GarmentDeliveryReturn>())); _MockStorage .Setup(x => x.Save()) .Verifiable(); // Act RemoveGarmentDeliveryReturnCommand request = new RemoveGarmentDeliveryReturnCommand(); request.SetId(id); var result = await unitUnderTest.Handle(request, cancellationToken); // Assert result.Should().NotBeNull(); }
public async Task Handle_Throws_ValidationException() { // Arrange Guid id = Guid.NewGuid(); RemoveGarmentDeliveryReturnCommandHandler unitUnderTest = CreateRemoveGarmentDeliveryReturnCommandHandler(); CancellationToken cancellationToken = CancellationToken.None; _mockGarmentDeliveryReturnRepository .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentDeliveryReturnReadModel, bool> > >())) .Returns(new List <GarmentDeliveryReturn>() { }); // Act RemoveGarmentDeliveryReturnCommand request = new RemoveGarmentDeliveryReturnCommand(); request.SetId(id); await Assert.ThrowsAsync <FluentValidation.ValidationException>(() => unitUnderTest.Handle(request, cancellationToken)); }