public async Task Handle_StateUnderTest_ExpectedBehavior_LOADING() { // Arrange Guid sewingDOItemGuid = Guid.NewGuid(); Guid sewingDOGuid = Guid.NewGuid(); PlaceGarmentAdjustmentCommandHandler unitUnderTest = CreatePlaceGarmentAdjustmentCommandHandler(); CancellationToken cancellationToken = CancellationToken.None; PlaceGarmentAdjustmentCommand placeGarmentAdjustmentCommand = new PlaceGarmentAdjustmentCommand() { RONo = "RONo", Unit = new UnitDepartment(1, "UnitCode", "UnitName"), AdjustmentType = "LOADING", AdjustmentDate = DateTimeOffset.Now, Article = "Article", Comodity = new GarmentComodity(1, "ComoCode", "ComoName"), Items = new List <GarmentAdjustmentItemValueObject> { new GarmentAdjustmentItemValueObject { IsSave = true, SewingDOItemId = sewingDOItemGuid, Size = new SizeValueObject(1, "Size"), Quantity = 1, RemainingQuantity = 2, Product = new Product(1, "ProdCode", "ProdName"), Uom = new Uom(1, "Uom"), } }, }; _mockAdjustmentRepository .Setup(s => s.Query) .Returns(new List <GarmentAdjustmentReadModel>().AsQueryable()); _mockSewingDOItemRepository .Setup(s => s.Query) .Returns(new List <GarmentSewingDOItemReadModel> { new GarmentSewingDOItemReadModel(sewingDOItemGuid) }.AsQueryable()); _mockAdjustmentRepository .Setup(s => s.Update(It.IsAny <GarmentAdjustment>())) .Returns(Task.FromResult(It.IsAny <GarmentAdjustment>())); _mockAdjustmentItemRepository .Setup(s => s.Update(It.IsAny <GarmentAdjustmentItem>())) .Returns(Task.FromResult(It.IsAny <GarmentAdjustmentItem>())); _mockSewingDOItemRepository .Setup(s => s.Update(It.IsAny <GarmentSewingDOItem>())) .Returns(Task.FromResult(It.IsAny <GarmentSewingDOItem>())); _MockStorage .Setup(x => x.Save()) .Verifiable(); // Act var result = await unitUnderTest.Handle(placeGarmentAdjustmentCommand, cancellationToken); // Assert result.Should().NotBeNull(); }
public async Task <IActionResult> Post([FromBody] PlaceGarmentAdjustmentCommand command) { try { VerifyUser(); var order = await Mediator.Send(command); return(Ok(order.Identity)); } catch (Exception e) { throw e; } }
public void Place_HaveError() { // Arrange var unitUnderTest = new PlaceGarmentAdjustmentCommand(); unitUnderTest.Items = new List <GarmentAdjustmentItemValueObject>() { new GarmentAdjustmentItemValueObject() { Quantity = 1, RemainingQuantity = 0 } }; var validator = GetValidationRules(); // Action var result = validator.TestValidate(unitUnderTest); // Assert result.ShouldHaveError(); }
public async Task Handle_StateUnderTest_ExpectedBehavior_BARANGJADI() { // Arrange Guid finishedGoodStockId = Guid.NewGuid(); Guid sewingDOGuid = Guid.NewGuid(); PlaceGarmentAdjustmentCommandHandler unitUnderTest = CreatePlaceGarmentAdjustmentCommandHandler(); CancellationToken cancellationToken = CancellationToken.None; PlaceGarmentAdjustmentCommand placeGarmentAdjustmentCommand = new PlaceGarmentAdjustmentCommand() { RONo = "RONo", Unit = new UnitDepartment(1, "UnitCode", "UnitName"), AdjustmentType = "BARANG JADI", AdjustmentDate = DateTimeOffset.Now, Article = "Article", Comodity = new GarmentComodity(1, "ComoCode", "ComoName"), Items = new List <GarmentAdjustmentItemValueObject> { new GarmentAdjustmentItemValueObject { IsSave = true, FinishingInItemId = Guid.Empty, FinishedGoodStockId = finishedGoodStockId, Size = new SizeValueObject(1, "Size"), Quantity = 1, RemainingQuantity = 2, Product = new Product(1, "ProdCode", "ProdName"), Uom = new Uom(1, "Uom"), Color = "www" } }, }; _mockFinishedGoodStockRepository .Setup(s => s.Query) .Returns(new List <GarmentFinishedGoodStockReadModel> { new GarmentFinishedGoodStock(finishedGoodStockId, "", "RONo", "article", new UnitDepartmentId(1), "code", "name", new GarmentComodityId(1), "", "", new SizeId(1), "", new UomId(1), "", 10, 100, 100).GetReadModel() }.AsQueryable()); _mockAdjustmentRepository .Setup(s => s.Query) .Returns(new List <GarmentAdjustmentReadModel>().AsQueryable()); GarmentComodityPrice garmentComodity = new GarmentComodityPrice( Guid.NewGuid(), true, DateTimeOffset.Now, new UnitDepartmentId(placeGarmentAdjustmentCommand.Unit.Id), placeGarmentAdjustmentCommand.Unit.Code, placeGarmentAdjustmentCommand.Unit.Name, new GarmentComodityId(placeGarmentAdjustmentCommand.Comodity.Id), placeGarmentAdjustmentCommand.Comodity.Code, placeGarmentAdjustmentCommand.Comodity.Name, 1000 ); _mockComodityPriceRepository .Setup(s => s.Query) .Returns(new List <GarmentComodityPriceReadModel> { garmentComodity.GetReadModel() }.AsQueryable()); _mockAdjustmentRepository .Setup(s => s.Update(It.IsAny <GarmentAdjustment>())) .Returns(Task.FromResult(It.IsAny <GarmentAdjustment>())); _mockAdjustmentItemRepository .Setup(s => s.Update(It.IsAny <GarmentAdjustmentItem>())) .Returns(Task.FromResult(It.IsAny <GarmentAdjustmentItem>())); _mockFinishedGoodStockRepository .Setup(s => s.Update(It.IsAny <GarmentFinishedGoodStock>())) .Returns(Task.FromResult(It.IsAny <GarmentFinishedGoodStock>())); _mockFinishedGoodStockHistoryRepository .Setup(s => s.Update(It.IsAny <GarmentFinishedGoodStockHistory>())) .Returns(Task.FromResult(It.IsAny <GarmentFinishedGoodStockHistory>())); _MockStorage .Setup(x => x.Save()) .Verifiable(); // Act var result = await unitUnderTest.Handle(placeGarmentAdjustmentCommand, cancellationToken); // Assert result.Should().NotBeNull(); }
public void Place_NotHaveError() { // Arrange var unitUnderTest = new PlaceGarmentAdjustmentCommand(); Guid id = Guid.NewGuid(); unitUnderTest.AdjustmentDate = DateTimeOffset.Now.AddDays(-1); unitUnderTest.AdjustmentDesc = "AdjustmentDesc"; unitUnderTest.AdjustmentNo = "AdjustmentNo"; unitUnderTest.AdjustmentType = "BARANG JADI"; unitUnderTest.Article = "Article"; unitUnderTest.Comodity = new GarmentComodity() { Id = 1, Code = "Code", Name = "Name" }; unitUnderTest.Price = 1; unitUnderTest.RONo = "RONo"; unitUnderTest.Unit = new UnitDepartment() { Id = 1, Code = "Code", Name = "Name" }; unitUnderTest.Items = new List <GarmentAdjustmentItemValueObject>() { new GarmentAdjustmentItemValueObject() { AdjustmentType = "BARANG JADI", BasicPrice = 1, Color = "Color", DesignColor = "DesignColor", IsSave = true, Price = 1, Product = new Product() { Id = 1, Code = "Code", Name = "Name" }, Quantity = 1, Size = new SizeValueObject() { Id = 1, Size = "Size" }, Uom = new Uom() { Id = 1, Unit = "Unit" }, RemainingQuantity = 2, AdjustmentId = id } }; var validator = GetValidationRules(); // Action var result = validator.TestValidate(unitUnderTest); // Assert result.ShouldNotHaveError(); }