public async Task <ActionResult> UpdateAvailability([FromBody] UpdateAvailabilityBody body, CancellationToken cancellationToken = default) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Update availability status UpdateAvailabilityCommand updateCommand = new UpdateAvailabilityCommand { AvailabilityStatusId = body.AvailabilityStatusId }; await _mediator.Send(updateCommand, cancellationToken); return(NoContent()); }
public async Task UpdateAvailabilityCommandHandler_ShouldUpdateAvailabilityStatus() { // Arrange UpdateAvailabilityCommand request = new UpdateAvailabilityCommand { AvailabilityStatusId = AvailabilityStatusId.Busy }; IEnumerable <Availability> databaseAvailabilities = new[] { new Availability { AvailabilityId = 1, UserId = 1 } }; IQueryable <Availability> queryableMock = databaseAvailabilities .AsQueryable() .BuildMock() .Object; _unitOfWorkMock .Setup(m => m.Availabilities.GetByUser(1)) .Returns(queryableMock); Availability passedAvailability = null; _unitOfWorkMock .Setup(m => m.Availabilities.Update(It.IsAny <Availability>())) .Callback <Availability>(a => passedAvailability = a); _unitOfWorkMock .Setup(m => m.CommitAsync(It.IsAny <CancellationToken>())) .ReturnsAsync(1); UpdateAvailabilityCommand.Handler handler = new UpdateAvailabilityCommand.Handler(_unitOfWorkMock.Object, _userProviderMock.Object, _dateProviderMock.Object); // Act await handler.Handle(request); // Assert _unitOfWorkMock.Verify(m => m.Availabilities.Update(It.IsAny <Availability>()), Times.Once); _unitOfWorkMock.Verify(m => m.CommitAsync(It.IsAny <CancellationToken>()), Times.AtLeastOnce); Assert.NotNull(passedAvailability); Assert.Equal(request.AvailabilityStatusId, passedAvailability.StatusId); }