public async Task Put_Dates_StateUnderTest_ExpectedBehavior_BadRequest() { // Arrange var unitUnderTest = CreateGarmentSewingOutController(); Guid sewingOutGuid = Guid.NewGuid(); List <string> ids = new List <string>(); ids.Add(sewingOutGuid.ToString()); UpdateDatesGarmentSewingOutCommand command = new UpdateDatesGarmentSewingOutCommand(ids, DateTimeOffset.Now.AddDays(3)); // Act var result = await unitUnderTest.UpdateDates(command); // Assert Assert.Equal((int)HttpStatusCode.BadRequest, GetStatusCode(result)); UpdateDatesGarmentSewingOutCommand command2 = new UpdateDatesGarmentSewingOutCommand(ids, DateTimeOffset.MinValue); // Act var result1 = await unitUnderTest.UpdateDates(command2); // Assert Assert.Equal((int)HttpStatusCode.BadRequest, GetStatusCode(result1)); }
public async Task <IActionResult> UpdateDates([FromBody] UpdateDatesGarmentSewingOutCommand command) { VerifyUser(); if (command.Date == null || command.Date == DateTimeOffset.MinValue) { return(BadRequest(new { code = HttpStatusCode.BadRequest, error = "Tanggal harus diisi" })); } else if (command.Date.Date > DateTimeOffset.Now.Date) { return(BadRequest(new { code = HttpStatusCode.BadRequest, error = "Tanggal tidak boleh lebih dari hari ini" })); } var order = await Mediator.Send(command); return(Ok()); }
public async Task Handle_StateUnderTest_ExpectedBehavior() { // Arrange Guid sewingOutGuid = Guid.NewGuid(); List <string> Ids = new List <string>(); Ids.Add(sewingOutGuid.ToString()); UpdateDatesGarmentSewingOutCommandHandler unitUnderTest = CreateUpdateDatesGarmentSewingOutCommandHandler(); CancellationToken cancellationToken = CancellationToken.None; UpdateDatesGarmentSewingOutCommand UpdateGarmentSewingOutCommand = new UpdateDatesGarmentSewingOutCommand( Ids, DateTimeOffset.Now); _mockSewingOutRepository .Setup(s => s.Query) .Returns(new List <GarmentSewingOutReadModel>() { new GarmentSewingOutReadModel(sewingOutGuid) }.AsQueryable()); _mockSewingOutRepository .Setup(s => s.Update(It.IsAny <GarmentSewingOut>())) .Returns(Task.FromResult(It.IsAny <GarmentSewingOut>())); _MockStorage .Setup(x => x.Save()) .Verifiable(); // Act var result = await unitUnderTest.Handle(UpdateGarmentSewingOutCommand, cancellationToken); // Assert result.Should().BeGreaterThan(0); }
public async Task Put_Dates_StateUnderTest_ExpectedBehavior() { // Arrange var unitUnderTest = CreateGarmentSewingOutController(); Guid sewingOutGuid = Guid.NewGuid(); List <string> ids = new List <string>(); ids.Add(sewingOutGuid.ToString()); UpdateDatesGarmentSewingOutCommand command = new UpdateDatesGarmentSewingOutCommand(ids, DateTimeOffset.Now); _MockMediator .Setup(s => s.Send(command, It.IsAny <CancellationToken>())) .ReturnsAsync(1); // Act var result = await unitUnderTest.UpdateDates(command); // Assert Assert.Equal((int)HttpStatusCode.OK, GetStatusCode(result)); }