public void Place_HaveError() { // Arrange var validator = GetValidationRules(); var unitUnderTest = new UpdateGarmentComodityPriceCommand(); // Action var result = validator.TestValidate(unitUnderTest); // Assert result.ShouldHaveError(); }
public async Task <IActionResult> Put([FromBody] UpdateGarmentComodityPriceCommand command) { try { VerifyUser(); var order = await Mediator.Send(command); return(Ok(order)); } catch (Exception e) { throw e; } }
public void Place_NotHaveError() { // Arrange Guid id = Guid.NewGuid(); var unitUnderTest = new UpdateGarmentComodityPriceCommand() { Date = DateTimeOffset.Now, Unit = new UnitDepartment() { Id = 1, Code = "Code", Name = "Name" }, Items = new List <GarmentComodityPriceItemValueObject>() { new GarmentComodityPriceItemValueObject() { Comodity = new GarmentComodity() { Id = 1, Code = "Code", Name = "Name" }, IsValid = true, NewPrice = 1, Price = 1, Unit = new UnitDepartment() { Id = 1, Code = "Code", Name = "Name" }, Date = DateTimeOffset.Now.AddDays(-2), Id = id } } }; unitUnderTest.SetIdentity(id); var validator = GetValidationRules(); // Action var result = validator.TestValidate(unitUnderTest); // Assert result.ShouldNotHaveError(); }
public async Task Put_Throws_Exception() { // Arrange var id = Guid.NewGuid(); var unitUnderTest = CreateGarmentComodityPriceController(); _MockMediator .Setup(s => s.Send(It.IsAny <UpdateGarmentComodityPriceCommand>(), It.IsAny <CancellationToken>())) .Throws(new Exception()); // Act var command = new UpdateGarmentComodityPriceCommand() { Date = DateTimeOffset.Now }; await Assert.ThrowsAsync <Exception>(() => unitUnderTest.Put(command)); }
public async Task Put_Return_OK() { // Arrange var id = Guid.NewGuid(); var unitUnderTest = CreateGarmentComodityPriceController(); _MockMediator .Setup(s => s.Send(It.IsAny <UpdateGarmentComodityPriceCommand>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new List <GarmentComodityPrice>() { new GarmentComodityPrice(id, true, DateTimeOffset.Now, new UnitDepartmentId(1), "unitCode", "unitName", new GarmentComodityId(1), "comodityCode", "comodityName", 1) }); // Act var command = new UpdateGarmentComodityPriceCommand() { Date = DateTimeOffset.Now }; var result = await unitUnderTest.Put(command); // Assert Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(result)); }
public async Task <List <GarmentComodityPrice> > Handle(UpdateGarmentComodityPriceCommand request, CancellationToken cancellationToken) { List <GarmentComodityPrice> List = new List <GarmentComodityPrice>(); foreach (var item in request.Items) { var como = _garmentComodityPriceRepository.Query.Where(o => o.Identity == item.Id).Select(o => new GarmentComodityPrice(o)).Single(); if (como.Price != item.NewPrice) { como.setValid(false); GarmentComodityPrice garmentComodityPrice = new GarmentComodityPrice( Guid.NewGuid(), true, request.Date, new UnitDepartmentId(request.Unit.Id), request.Unit.Code, request.Unit.Name, new GarmentComodityId(item.Comodity.Id), item.Comodity.Code, item.Comodity.Name, item.NewPrice ); await _garmentComodityPriceRepository.Update(garmentComodityPrice); } como.Modify(); await _garmentComodityPriceRepository.Update(como); _storage.Save(); List.Add(como); } return(List); }
public async Task Handle_StateUnderTest_ExpectedBehavior() { // Arrange Guid id = Guid.NewGuid(); UpdateGarmentComodityPriceCommandHandler unitUnderTest = CreateUpdateGarmentComodityPriceCommandHandler(); CancellationToken cancellationToken = CancellationToken.None; UpdateGarmentComodityPriceCommand request = new UpdateGarmentComodityPriceCommand() { Unit = new UnitDepartment() { Id = 1, Code = "Code", Name = "Name" }, Date = DateTimeOffset.Now, Items = new List <GarmentComodityPriceItemValueObject>() { new GarmentComodityPriceItemValueObject() { Id = id, IsValid = true, Comodity = new GarmentComodity() { Id = 1, Code = "Code", Name = "Name" }, Date = DateTimeOffset.Now, NewPrice = 2, Price = 2, Unit = new UnitDepartment() { Id = 1, Code = "Code", Name = "Name" } } } }; request.SetIdentity(id); GarmentComodityPrice garmentComodityPrice = new GarmentComodityPrice(id, true, DateTimeOffset.Now, new UnitDepartmentId(1), "unitCode", "unitName", new GarmentComodityId(1), "comodityCode", "comodityName", 1); _mockComodityPriceRepository .Setup(s => s.Query) .Returns(new List <GarmentComodityPriceReadModel>() { garmentComodityPrice.GetReadModel() }.AsQueryable()); _mockComodityPriceRepository .Setup(s => s.Update(It.IsAny <GarmentComodityPrice>())) .Returns(Task.FromResult(It.IsAny <GarmentComodityPrice>())); _MockStorage .Setup(x => x.Save()) .Verifiable(); // Act var result = await unitUnderTest.Handle(request, cancellationToken); // Assert result.Should().NotBeNull(); result.Count().Should().BeGreaterThan(0); }