public void Place_HaveError() { // Arrange var unitUnderTest = new PlaceGarmentExpenditureGoodReturnCommand(); // Action var validator = GetValidationRules(); var result = validator.TestValidate(unitUnderTest); // Assert result.ShouldHaveError(); }
public async Task <IActionResult> Post([FromBody] PlaceGarmentExpenditureGoodReturnCommand command) { try { VerifyUser(); var order = await Mediator.Send(command); return(Ok(order.Identity)); } catch (Exception e) { throw e; } }
public void Place_HaveError_Date() { // Arrange var validator = GetValidationRules(); var unitUnderTest = new PlaceGarmentExpenditureGoodReturnCommand(); unitUnderTest.ReturDate = DateTimeOffset.Now.AddDays(-7); unitUnderTest.ExpenditureDate = DateTimeOffset.Now; // Action var result = validator.TestValidate(unitUnderTest); // Assert result.ShouldHaveError(); }
public async Task Post_Throws_Exception() { // Arrange var unitUnderTest = CreateGarmentExpenditureGoodReturnController(); Guid id = Guid.NewGuid(); _MockMediator .Setup(s => s.Send(It.IsAny <PlaceGarmentExpenditureGoodReturnCommand>(), It.IsAny <CancellationToken>())) .Throws(new Exception()); // Act var command = new PlaceGarmentExpenditureGoodReturnCommand(); // Assert await Assert.ThrowsAsync <Exception>(() => unitUnderTest.Post(command)); }
public async Task Post_Return_OK() { // Arrange var unitUnderTest = CreateGarmentExpenditureGoodReturnController(); Guid id = Guid.NewGuid(); _MockMediator .Setup(s => s.Send(It.IsAny <PlaceGarmentExpenditureGoodReturnCommand>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new GarmentExpenditureGoodReturn(id, "returNo", "returType", new UnitDepartmentId(1), "unitCode", "unitName", "roNo", "article", new GarmentComodityId(1), "comodityCode", "comodityName", new BuyerId(1), "buyerCode", "buyerName", DateTimeOffset.Now, "invoice", "returDesc")); // Act var command = new PlaceGarmentExpenditureGoodReturnCommand(); var result = await unitUnderTest.Post(command); // Assert Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(result)); }
public void Place_NotHaveError() { // Arrange Guid id = Guid.NewGuid(); var unitUnderTest = new PlaceGarmentExpenditureGoodReturnCommand() { Article = "Article", Buyer = new Buyer() { Id = 1, Code = "Code", Name = "Name" }, Comodity = new GarmentComodity() { Id = 1, Code = "Code", Name = "Name" }, Invoice = "Invoice", Price = 1, ReturDate = DateTimeOffset.Now, ExpenditureDate = DateTimeOffset.Now, ReturDesc = "ReturDesc", ReturGoodNo = "ReturGoodNo", ReturType = "ReturType", RONo = "RONo", Unit = new UnitDepartment() { Id = 1, Code = "Code", Name = "Name" }, Items = new List <GarmentExpenditureGoodReturnItemValueObject>() { new GarmentExpenditureGoodReturnItemValueObject() { BasicPrice = 1, Description = "Description", ExpenditureGoodId = id, ExpenditureGoodItemId = id, FinishedGoodStockId = id, isSave = true, Price = 1, Quantity = 1, ReturId = id, Size = new SizeValueObject() { Id = 1, Size = "Size" }, Id = id, StockQuantity = 1, 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 finStockGuid = Guid.NewGuid(); Guid exGoodGuid = Guid.NewGuid(); Guid exGoodItemGuid = Guid.NewGuid(); PlaceGarmentExpenditureGoodReturnCommandHandler unitUnderTest = CreatePlaceGarmentExpenditureGoodReturnCommandHandler(); CancellationToken cancellationToken = CancellationToken.None; PlaceGarmentExpenditureGoodReturnCommand placeGarmentExpenditureGoodReturnCommand = new PlaceGarmentExpenditureGoodReturnCommand() { RONo = "RONo", Unit = new UnitDepartment(1, "UnitCode", "UnitName"), Article = "Article", Comodity = new GarmentComodity(1, "ComoCode", "ComoName"), Buyer = new Buyer(1, "buyerCode", "buyerName"), ReturDate = DateTimeOffset.Now, Items = new List <GarmentExpenditureGoodReturnItemValueObject> { new GarmentExpenditureGoodReturnItemValueObject { Uom = new Uom(1, "UomUnit"), FinishedGoodStockId = finStockGuid, ExpenditureGoodId = exGoodGuid, ExpenditureGoodItemId = exGoodItemGuid, Description = "Color", Size = new SizeValueObject(1, "Size"), isSave = true, Quantity = 1, } }, }; _mockExpenditureGoodReturnRepository .Setup(s => s.Query) .Returns(new List <GarmentExpenditureGoodReturnReadModel>().AsQueryable()); _mockFinishedGoodStockRepository .Setup(s => s.Query) .Returns(new List <GarmentFinishedGoodStockReadModel>() { new GarmentFinishedGoodStockReadModel(finStockGuid) }.AsQueryable()); GarmentExpenditureGood garmentExpenditureGood = new GarmentExpenditureGood(exGoodGuid, "no", null, new UnitDepartmentId(placeGarmentExpenditureGoodReturnCommand.Unit.Id), null, null, placeGarmentExpenditureGoodReturnCommand.RONo, null, new GarmentComodityId(1), null, null, new BuyerId(1), null, null, DateTimeOffset.Now, null, null, 0, null, false); GarmentExpenditureGoodItem garmentExpenditureGoodItem = new GarmentExpenditureGoodItem( exGoodItemGuid, exGoodGuid, finStockGuid, new SizeId(1), null, 1, 0, new UomId(1), null, "Color", 1, 1); _mockExpenditureGoodRepository .Setup(s => s.Query) .Returns(new List <GarmentExpenditureGoodReadModel> { garmentExpenditureGood.GetReadModel() }.AsQueryable()); _mockExpenditureGoodItemRepository .Setup(s => s.Query) .Returns(new List <GarmentExpenditureGoodItemReadModel> { garmentExpenditureGoodItem.GetReadModel() }.AsQueryable()); GarmentComodityPrice garmentComodity = new GarmentComodityPrice( Guid.NewGuid(), true, DateTimeOffset.Now, new UnitDepartmentId(placeGarmentExpenditureGoodReturnCommand.Unit.Id), placeGarmentExpenditureGoodReturnCommand.Unit.Code, placeGarmentExpenditureGoodReturnCommand.Unit.Name, new GarmentComodityId(placeGarmentExpenditureGoodReturnCommand.Comodity.Id), placeGarmentExpenditureGoodReturnCommand.Comodity.Code, placeGarmentExpenditureGoodReturnCommand.Comodity.Name, 1000 ); _mockComodityPriceRepository .Setup(s => s.Query) .Returns(new List <GarmentComodityPriceReadModel> { garmentComodity.GetReadModel() }.AsQueryable()); _mockExpenditureGoodReturnRepository .Setup(s => s.Update(It.IsAny <GarmentExpenditureGoodReturn>())) .Returns(Task.FromResult(It.IsAny <GarmentExpenditureGoodReturn>())); _mockExpenditureGoodReturnItemRepository .Setup(s => s.Update(It.IsAny <GarmentExpenditureGoodReturnItem>())) .Returns(Task.FromResult(It.IsAny <GarmentExpenditureGoodReturnItem>())); _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>())); _mockExpenditureGoodItemRepository .Setup(s => s.Update(It.IsAny <GarmentExpenditureGoodItem>())) .Returns(Task.FromResult(It.IsAny <GarmentExpenditureGoodItem>())); //_mockExpenditureGoodRepository // .Setup(s => s.Update(It.IsAny<GarmentExpenditureGood>())) // .Returns(Task.FromResult(It.IsAny<GarmentExpenditureGood>())); _MockStorage .Setup(x => x.Save()) .Verifiable(); // Act var result = await unitUnderTest.Handle(placeGarmentExpenditureGoodReturnCommand, cancellationToken); // Assert result.Should().NotBeNull(); }