public async Task Put_Dates_StateUnderTest_ExpectedBehavior_BadRequest() { // Arrange var unitUnderTest = CreateGarmentLoadingController(); Guid sewingOutGuid = Guid.NewGuid(); List <string> ids = new List <string>(); ids.Add(sewingOutGuid.ToString()); UpdateDatesGarmentLoadingCommand command = new UpdateDatesGarmentLoadingCommand(ids, DateTimeOffset.Now.AddDays(3)); // Act var result = await unitUnderTest.UpdateDates(command); // Assert Assert.Equal((int)HttpStatusCode.BadRequest, GetStatusCode(result)); UpdateDatesGarmentLoadingCommand command2 = new UpdateDatesGarmentLoadingCommand(ids, DateTimeOffset.MinValue); // Act var result1 = await unitUnderTest.UpdateDates(command2); // Assert Assert.Equal((int)HttpStatusCode.BadRequest, GetStatusCode(result1)); }
public async Task Handle_StateUnderTest_ExpectedBehavior() { // Arrange Guid guid = Guid.NewGuid(); List <string> Ids = new List <string>(); Ids.Add(guid.ToString()); UpdateDatesGarmentLoadingCommandHandler unitUnderTest = CreateUpdateDatesGarmentLoadingCommandHandler(); CancellationToken cancellationToken = CancellationToken.None; UpdateDatesGarmentLoadingCommand UpdateGarmentLoadingCommand = new UpdateDatesGarmentLoadingCommand( Ids, DateTimeOffset.Now); _mockLoadingRepository .Setup(s => s.Query) .Returns(new List <GarmentLoadingReadModel>() { new GarmentLoadingReadModel(guid) }.AsQueryable()); _mockLoadingRepository .Setup(s => s.Update(It.IsAny <GarmentLoading>())) .Returns(Task.FromResult(It.IsAny <GarmentLoading>())); _MockStorage .Setup(x => x.Save()) .Verifiable(); // Act var result = await unitUnderTest.Handle(UpdateGarmentLoadingCommand, cancellationToken); // Assert result.Should().BeGreaterThan(0); }
public async Task <IActionResult> UpdateDates([FromBody] UpdateDatesGarmentLoadingCommand 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 Put_Dates_StateUnderTest_ExpectedBehavior() { // Arrange var unitUnderTest = CreateGarmentLoadingController(); Guid sewingOutGuid = Guid.NewGuid(); List <string> ids = new List <string>(); ids.Add(sewingOutGuid.ToString()); UpdateDatesGarmentLoadingCommand command = new UpdateDatesGarmentLoadingCommand(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)); }