public async Task <IActionResult> Put(string id, [FromBody] UpdateGarmentSewingOutCommand command) { Guid guid = Guid.Parse(id); command.SetIdentity(guid); VerifyUser(); var order = await Mediator.Send(command); return(Ok(order.Identity)); }
public void Place_ShouldHaveError() { // Arrange var validator = GetValidationRules(); var unitUnderTest = new UpdateGarmentSewingOutCommand(); // Action var result = validator.TestValidate(unitUnderTest); // Assert result.ShouldHaveError(); }
public void Place_HaveError_Date() { // Arrange var validator = GetValidationRules(); var unitUnderTest = new UpdateGarmentSewingOutCommand(); unitUnderTest.SewingOutDate = DateTimeOffset.Now.AddDays(-7); unitUnderTest.SewingInDate = DateTimeOffset.Now; // Action var result = validator.TestValidate(unitUnderTest); // Assert result.ShouldHaveError(); }
public void Place_ShouldNotHaveError() { // Arrange Guid id = Guid.NewGuid(); var unitUnderTest = new UpdateGarmentSewingOutCommand() { Article = "Article", IsDifferentSize = true, SewingInDate = DateTimeOffset.Now, Comodity = new GarmentComodity() { Id = 1, Code = "Code", Name = "Name" }, Buyer = new Buyer() { Id = 1, Code = "Code", Name = "Name" }, RONo = "RONo", SewingOutDate = DateTimeOffset.Now, SewingOutNo = "SewingOutNo", SewingTo = "SewingTo", Unit = new UnitDepartment() { Id = 1, Code = "Code", Name = "Name" }, UnitTo = new UnitDepartment() { Id = 1, Code = "Code", Name = "Name" }, Items = new List <GarmentSewingOutItemValueObject>() { new GarmentSewingOutItemValueObject() { BasicPrice = 1, Color = "Color", DesignColor = "DesignColor", Id = id, IsDifferentSize = true, IsSave = true, Price = 1, Product = new Product() { Id = 1, Code = "Code", Name = "Name" }, Quantity = 1, SewingInId = id, RemainingQuantity = 2, SewingInItemId = id, SewingInQuantity = 1, SewingOutId = id, Size = new SizeValueObject() { Id = 1, Size = "Size" }, TotalQuantity = 1, Uom = new Uom() { Id = 1, Unit = "Unit" }, Details = new List <GarmentSewingOutDetailValueObject>() { new GarmentSewingOutDetailValueObject() { Id = id, Quantity = 1, SewingOutItemId = id, Size = new SizeValueObject() { Id = 1, Size = "Size" }, Uom = new Uom() { Id = 1, Unit = "Unit" } } } } } }; // Action var validator = GetValidationRules(); var result = validator.TestValidate(unitUnderTest); // Assert result.ShouldNotHaveError(); }
public async Task Handle_StateUnderTest_ExpectedBehavior() { // Arrange Guid sewingInItemGuid = Guid.NewGuid(); Guid sewingOutGuid = Guid.NewGuid(); Guid sewingInId = Guid.NewGuid(); UpdateGarmentSewingOutCommandHandler unitUnderTest = CreateUpdateGarmentSewingOutCommandHandler(); CancellationToken cancellationToken = CancellationToken.None; UpdateGarmentSewingOutCommand UpdateGarmentSewingOutCommand = new UpdateGarmentSewingOutCommand() { RONo = "RONo", Unit = new UnitDepartment(1, "UnitCode", "UnitName"), UnitTo = new UnitDepartment(2, "UnitCode2", "UnitName2"), Article = "Article", IsDifferentSize = true, Buyer = new Buyer(1, "BuyerCode", "BuyerName"), SewingTo = "FINISHING", Comodity = new GarmentComodity(1, "ComoCode", "ComoName"), SewingOutDate = DateTimeOffset.Now, Items = new List <GarmentSewingOutItemValueObject> { new GarmentSewingOutItemValueObject { Product = new Product(1, "ProductCode", "ProductName"), Uom = new Uom(1, "UomUnit"), SewingInId = sewingInId, SewingInItemId = sewingInItemGuid, Color = "Color", Size = new SizeValueObject(1, "Size"), IsSave = true, Quantity = 1, DesignColor = "ColorD", Details = new List <GarmentSewingOutDetailValueObject> { new GarmentSewingOutDetailValueObject { Size = new SizeValueObject(1, "Size"), Uom = new Uom(1, "UomUnit"), Quantity = 1 } } } }, }; UpdateGarmentSewingOutCommand.SetIdentity(sewingOutGuid); _mockSewingOutRepository .Setup(s => s.Query) .Returns(new List <GarmentSewingOutReadModel>() { new GarmentSewingOutReadModel(sewingOutGuid) }.AsQueryable()); _mockSewingOutItemRepository .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentSewingOutItemReadModel, bool> > >())) .Returns(new List <GarmentSewingOutItem>() { new GarmentSewingOutItem(Guid.Empty, sewingOutGuid, Guid.Empty, sewingInItemGuid, new ProductId(1), null, null, null, new SizeId(1), null, 1, new UomId(1), null, null, 1, 1, 1) }); _mockSewingOutDetailRepository .Setup(s => s.Find(It.IsAny <Expression <Func <GarmentSewingOutDetailReadModel, bool> > >())) .Returns(new List <GarmentSewingOutDetail>() { new GarmentSewingOutDetail(Guid.Empty, Guid.Empty, new SizeId(1), null, 1, new UomId(1), null) }); GarmentComodityPrice garmentComodity = new GarmentComodityPrice( Guid.NewGuid(), true, DateTimeOffset.Now, new UnitDepartmentId(UpdateGarmentSewingOutCommand.Unit.Id), UpdateGarmentSewingOutCommand.Unit.Code, UpdateGarmentSewingOutCommand.Unit.Name, new GarmentComodityId(UpdateGarmentSewingOutCommand.Comodity.Id), UpdateGarmentSewingOutCommand.Comodity.Code, UpdateGarmentSewingOutCommand.Comodity.Name, 1000 ); _mockComodityPriceRepository .Setup(s => s.Query) .Returns(new List <GarmentComodityPriceReadModel> { garmentComodity.GetReadModel() }.AsQueryable()); _mockSewingInItemRepository .Setup(s => s.Query) .Returns(new List <GarmentSewingInItemReadModel> { new GarmentSewingInItemReadModel(sewingInItemGuid) }.AsQueryable()); _mockSewingOutRepository .Setup(s => s.Update(It.IsAny <GarmentSewingOut>())) .Returns(Task.FromResult(It.IsAny <GarmentSewingOut>())); _mockSewingOutItemRepository .Setup(s => s.Update(It.IsAny <GarmentSewingOutItem>())) .Returns(Task.FromResult(It.IsAny <GarmentSewingOutItem>())); _mockSewingOutDetailRepository .Setup(s => s.Update(It.IsAny <GarmentSewingOutDetail>())) .Returns(Task.FromResult(It.IsAny <GarmentSewingOutDetail>())); _mockSewingInItemRepository .Setup(s => s.Update(It.IsAny <GarmentSewingInItem>())) .Returns(Task.FromResult(It.IsAny <GarmentSewingInItem>())); _MockStorage .Setup(x => x.Save()) .Verifiable(); // Act var result = await unitUnderTest.Handle(UpdateGarmentSewingOutCommand, cancellationToken); // Assert result.Should().NotBeNull(); }