public UpdateWorkOrderCommand Map(UpdateWorkOrderRequest request) { var id = new Guid(request.RouteId); var valuePairs = _jsonProvider.ToDictionary(request.BodyPatch); Optional <string> operant = valuePairs.GetOptional <string>("operant"); Optional <string> status = valuePairs.GetOptional <string>("status"); Optional <string> startedOn = valuePairs.GetOptional <string>("startedOn"); Optional <IEnumerable <HandledUnitDto> > handledUnits = valuePairs.GetOptional <IEnumerable <HandledUnitDto> >("handledUnits"); Optional <IEnumerable <RemarkDto> > remarks = valuePairs.GetOptional <IEnumerable <RemarkDto> >("remarks"); Optional <IEnumerable <PictureDto> > pictures = valuePairs.GetOptional <IEnumerable <PictureDto> >("pictures"); Optional <IEnumerable <InputDto> > inputs = valuePairs.GetOptional <IEnumerable <InputDto> >("inputs"); var version = ToVersion(request.HeaderIfMatch); var result = new UpdateWorkOrderCommand(id, operant, status, startedOn, handledUnits, remarks, pictures, inputs, version); return(result); }
public async Task <IActionResult> Update([FromRoute] string id, [FromBody] UpdateWorkOrderCommand command) { command.ObjectNumber = id; var result = await _mediator.Send(command); return(result.Success ? (IActionResult)Ok(result) : NotFound()); }
public async Task <IActionResult> UpdateWorkOrder([FromBody] UpdateWorkOrderCommand command) { if (command == null) { throw new ArgumentNullException(nameof(command)); } if (!ModelState.IsValid) { return(BadRequest(400)); } var order = await _mediator.Send(command); return(Ok(order)); }
public async Task ShouldUpdateWorkOrderTest() { // Arrange var createWorkOrderCommand = new CreateWorkOrderCommand { Address = "Address 123", Description = "Description 123", ObjectNumber = $"B{NextObjectNumber()}", StartDate = DateTimeOffset.Now.AddDays(1), EndDate = DateTimeOffset.Now.AddDays(5), Status = WorkOrderStatus.NotStarted, }; var createWorkOrderCommandResult = await SendRequestAsync(createWorkOrderCommand); // Act var updateWorkOrderCommand = new UpdateWorkOrderCommand( createWorkOrderCommandResult.Data.ObjectNumber, "Address 123 UPDATED", "Description 123 UPDATED", DateTimeOffset.Now.AddDays(1), DateTimeOffset.Now.AddDays(5), WorkOrderStatus.Started); var result = await SendRequestAsync(updateWorkOrderCommand); var workOrder = await FindAsync <WorkOrder>(result.Data.ObjectNumber); // Assert result.Success.ShouldBeTrue(); result.Message.ShouldBeEmpty(); workOrder.ObjectNumber.ShouldBe(updateWorkOrderCommand.ObjectNumber); workOrder.Address.ShouldBe(updateWorkOrderCommand.Address); workOrder.Description.ShouldBe(updateWorkOrderCommand.Description); workOrder.StartDate.ShouldBe(updateWorkOrderCommand.StartDate); workOrder.EndDate.ShouldBe(updateWorkOrderCommand.EndDate); workOrder.Status.ShouldBe(updateWorkOrderCommand.Status); }
public async Task HandleShouldReturnOk() { // Arrange var id = Guid.NewGuid(); var startCreatedOn = new CreatedOn(DateTime.Now.AddHours(-5).ToUniversalTime()); var stopCreatedOn = new CreatedOn(DateTime.Now.AddHours(-3).ToUniversalTime()); var isEditable = true; Order order = new Order(); Operational operational = new Operational(Status.Busy); string userCreated = "any"; DateTime createdOn = DateTime.UtcNow; var version = 1; var logAsMock = new Mock <ILogAs>(); logAsMock.Setup(x => x.Error(It.IsAny <string>(), It.IsAny <Exception>())); var logAs = logAsMock.Object; var workOrderWriteRepositoryMock = new Mock <IWorkOrderWriteRepository>(); workOrderWriteRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny <WorkOrder>())).Returns(Task.CompletedTask); var workOrderWriteRepository = workOrderWriteRepositoryMock.Object; var workOrderReadRepositoryMock = new Mock <IWorkOrderReadRepository>(); workOrderReadRepositoryMock.Setup(x => x.GetAsync(id)).Returns(Task.FromResult(new WorkOrder(id, isEditable, order, operational, userCreated, startCreatedOn) { Version = 1 })); var workOrderReadRepository = workOrderReadRepositoryMock.Object; var versionProviderMock = new Mock <IVersionProvider>(); versionProviderMock.Setup(x => x.Generate()).Returns(version); var versionProvider = versionProviderMock.Object; var dateTimeProviderMock = new Mock <IDateTimeProvider>(); dateTimeProviderMock.Setup(x => x.Parse(It.IsAny <string>())).Returns(DateTime.UtcNow); var dateTimeProvider = dateTimeProviderMock.Object; var typeConverterProviderMock = new Mock <ITypeConverterProvider>(); typeConverterProviderMock.Setup(x => x.ToFloat(It.IsAny <string>())).Returns(12); var typeConverterProvider = typeConverterProviderMock.Object; var command = new UpdateWorkOrderCommand( id, new Optional <string>("AnyOperant"), new Optional <string>(Status.Busy.Name), new Optional <string>(DateTime.UtcNow.ToString()), new Optional <IEnumerable <HandledUnitDto> >(), new Optional <IEnumerable <RemarkDto> >(), new Optional <IEnumerable <PictureDto> >(), new Optional <IEnumerable <InputDto> >(), 1 ); var handler = new UpdateWorkOrderCommandHandler(logAs, workOrderReadRepository, workOrderWriteRepository, versionProvider, dateTimeProvider, typeConverterProvider); // Act var result = await handler.Handle(command, CancellationToken.None); // Assert result.IsFailure.Should().BeFalse(); result.Should().BeOfType(typeof(Result)); }