public async Task CanUpdateClassroom() { var authorizedClient = SystemTestExtension.GetTokenAuthorizeHttpClient(_factory); var updateClassroomCommand = new UpdateClassroomCommand { Id = 1, TrainerUserId = 1, TrainingId = 1, Name = "test" }; var serializedUpdateCommand = JsonConvert.SerializeObject(updateClassroomCommand); // The endpoint or route of the controller action. var httpResponse = await authorizedClient.PutAsync(requestUri : "/Classroom", content : new StringContent(content: serializedUpdateCommand, encoding: Encoding.UTF8, mediaType: StringConstants.ApplicationJson)); //Must be successful httpResponse.EnsureSuccessStatusCode(); Assert.True(httpResponse.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.OK, httpResponse.StatusCode); }
public async Task <IActionResult> Put(int id, [FromBody] UpdateClassroomCommand command) { if (command == null) { return(GenerateResponse(StatusType.Fail, null, "Invalid Parameters" )); } return(GenerateResponse( StatusType.Success, await _mediator.Send(command) )); }
public async Task ShouldThrowErrorWhenInvalidInformation() { var updateClassroomCommand = new UpdateClassroomCommand { Id = _classroomId + 1, UpdatedBy = _adminUserId, TenantId = _tenantId, TrainerUserId = _trainerUserId, TrainingId = _trainingId, Name = "test" }; await Assert.ThrowsAsync <NotFoundException>(async() => await _commandHandler.Handle(updateClassroomCommand, CancellationToken.None)); }
public async Task ShouldGetModelForValidInformation() { var updateClassroomCommand = new UpdateClassroomCommand { UpdatedBy = _adminUserId, TenantId = _tenantId, Id = _classroomId, TrainerUserId = _trainerUserId, TrainingId = _trainingId, Name = "test", BeginDatetime = DateTimeOffset.Now, EndDatetime = DateTimeOffset.Now.AddDays(4), Location = "asdas" }; var classroomResponseModel = await _commandHandler.Handle(updateClassroomCommand, CancellationToken.None); Assert.Null(classroomResponseModel.Errors); Assert.Equal(expected: updateClassroomCommand.Name, actual: classroomResponseModel.Items.Single().Name, ignoreCase: true); }
public async Task <ActionResult <ResponseModel <UpdateClassroomModel> > > Put([FromBody] UpdateClassroomCommand command) { try { command.UpdatedBy = Claims[ClaimTypes.Sid].ToInt(); command.TenantId = Guid.Parse(Claims[ClaimTypes.UserData]); var updateClassroomModel = await Mediator.Send(command); return(Ok(updateClassroomModel)); } catch (NotFoundException) { return(NotFound()); } catch (ObjectAlreadyExistsException ex) { return(Conflict(new ResponseModel <UpdateClassroomModel>(new Error(HttpStatusCode.Conflict, ex)))); } catch { return(StatusCode(HttpStatusCode.InternalServerError.ToInt())); } }