public async Task ShouldGetModelForValidInformation() { var command = new CreateTraineeGroupCommand { CreatedBy = _adminUserId, TenantId = _tenantId, CreateTraineeGroupCommandModels = new List <CreateTraineeGroupCommandModel> { new CreateTraineeGroupCommandModel { Name = "aqwdasd" }, new CreateTraineeGroupCommandModel { Name = "basdasd" } } }; var traineeGroupModel = await _commandHandler.Handle(command, CancellationToken.None); Assert.Null(traineeGroupModel.Errors); Assert.True(traineeGroupModel.Items.Single().Count > 0); }
public async Task CanCreateTraineeGroup() { var authorizedClient = SystemTestExtension.GetTokenAuthorizeHttpClient(_factory); var createTraineeGroupCommand = new CreateTraineeGroupCommand { CreateTraineeGroupCommandModels = new List <CreateTraineeGroupCommandModel> { new CreateTraineeGroupCommandModel { Name = "traineeGroupSampleeee", } } }; var serializedTraineeGroupCommand = JsonConvert.SerializeObject(createTraineeGroupCommand); // The endpoint or route of the controller action. var httpResponse = await authorizedClient.PostAsync(requestUri : "/TraineeGroup", content : new StringContent(content: serializedTraineeGroupCommand, encoding: Encoding.UTF8, mediaType: StringConstants.ApplicationJson)); // Must be successful. httpResponse.EnsureSuccessStatusCode(); Assert.True(httpResponse.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Created, httpResponse.StatusCode); }
public async Task <ActionResult <ResponseModel <CreateTraineeGroupModel> > > Post([FromBody] CreateTraineeGroupCommand command) { try { var userId = Claims[ClaimTypes.Sid].ToInt(); var tenantId = Guid.Parse(Claims[ClaimTypes.UserData]); command.CreatedBy = userId; command.TenantId = tenantId; var createTraineeGroupModel = await Mediator.Send(command); return(Created($"api/traineeUser", createTraineeGroupModel)); } catch (NotFoundException) { return(NotFound()); } catch (ObjectAlreadyExistsException ex) { return(Conflict(new ResponseModel <CreateTraineeGroupModel>(new Error(HttpStatusCode.Conflict, ex)))); } catch { return(StatusCode(HttpStatusCode.InternalServerError.ToInt())); } }