public async Task Handle_StateUnderTest_ExpectedBehavior() { // Arrange Guid id = Guid.NewGuid(); RemoveGarmentAvalProductCommandHandler unitUnderTest = CreateRemoveGarmentAvalProductCommandHandler(); CancellationToken cancellationToken = CancellationToken.None; RemoveGarmentAvalProductCommand request = new RemoveGarmentAvalProductCommand(); request.SetId(id); _mockGarmentAvalProductRepository .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentAvalProductReadModel, bool> > >())) .Returns(new List <GarmentAvalProduct>() { new GarmentAvalProduct(id, "roNo", "article", DateTimeOffset.Now, new Domain.Shared.ValueObjects.UnitDepartmentId(1), "unitCode", "unitName") }); _mockGarmentAvalProductItemRepository .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentAvalProductItemReadModel, bool> > >())) .Returns(new List <GarmentAvalProductItem>() { new GarmentAvalProductItem(id, id, new GarmentPreparingId("value"), new GarmentPreparingItemId("value"), new ProductId(1), "productCode", "productName", "designColor", 1, new UomId(1), "uomUnit", 1, false) }); _mockGarmentAvalProductItemRepository .Setup(s => s.Update(It.IsAny <GarmentAvalProductItem>())) .Returns(Task.FromResult(It.IsAny <GarmentAvalProductItem>())); _mockGarmentPreparingItemRepository .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentPreparingItemReadModel, bool> > >())) .Returns(new List <Domain.GarmentPreparings.GarmentPreparingItem>() { new Domain.GarmentPreparings.GarmentPreparingItem(id, 1, new Domain.GarmentPreparings.ValueObjects.ProductId(1), "productCode", "productName", "designColor", 1, new Domain.GarmentPreparings.ValueObjects.UomId(1), "uomUnit", "fabricType", 1, 1, id, null) }); _mockGarmentPreparingItemRepository .Setup(s => s.Update(It.IsAny <Domain.GarmentPreparings.GarmentPreparingItem>())) .Returns(Task.FromResult(It.IsAny <Domain.GarmentPreparings.GarmentPreparingItem>())); _mockGarmentAvalProductRepository .Setup(s => s.Update(It.IsAny <GarmentAvalProduct>())) .Returns(Task.FromResult(It.IsAny <GarmentAvalProduct>())); _MockStorage .Setup(x => x.Save()) .Verifiable(); var result = await unitUnderTest.Handle(request, cancellationToken); // Assert result.Should().NotBeNull(); }
public async Task Handle_Throws_ErrorValidation() { // Arrange Guid id = Guid.NewGuid(); RemoveGarmentAvalProductCommandHandler unitUnderTest = CreateRemoveGarmentAvalProductCommandHandler(); CancellationToken cancellationToken = CancellationToken.None; RemoveGarmentAvalProductCommand request = new RemoveGarmentAvalProductCommand(); request.SetId(id); _mockGarmentAvalProductRepository .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentAvalProductReadModel, bool> > >())) .Returns(new List <GarmentAvalProduct>() { }); await Assert.ThrowsAsync <FluentValidation.ValidationException>(() => unitUnderTest.Handle(request, cancellationToken)); }
public async Task <IActionResult> Delete(string id) { VerifyUser(); var avalProductId = Guid.Parse(id); if (!Guid.TryParse(id, out Guid orderId)) { return(NotFound()); } var garmentPreparing = _garmentAvalProductRepository.Find(x => x.Identity == avalProductId).Select(o => new GarmentAvalProductDto(o)).FirstOrDefault(); var command = new RemoveGarmentAvalProductCommand(); command.SetId(orderId); var order = await Mediator.Send(command); return(Ok(order.Identity)); }