public async Task CanCreateTrainingSeriesAsync() { var authorizedClient = SystemTestExtension.GetTokenAuthorizeHttpClient(_factory); var createTrainingSeriesCommand = new CreateTrainingSeriesCommand { CreateTrainingSeriesModels = new List <CreateTrainingSeriesCommandModel> { new CreateTrainingSeriesCommandModel { Name = "trainingSeries1" } } }; var serializedTrainingSeriesCommand = JsonConvert.SerializeObject(createTrainingSeriesCommand); // The endpoint or route of the controller action. var httpResponse = await authorizedClient.PostAsync(requestUri : "/TrainingSeries", content : new StringContent(content: serializedTrainingSeriesCommand, encoding: Encoding.UTF8, mediaType: StringConstants.ApplicationJson)); // Must be successful. httpResponse.EnsureSuccessStatusCode(); Assert.True(httpResponse.IsSuccessStatusCode); Assert.Equal(HttpStatusCode.Created, httpResponse.StatusCode); }
public async Task ShouldGetModelForValidInformation() { var command = new CreateTrainingSeriesCommand { CreatedBy = _adminUserId, TenantId = _tenantId, CreateTrainingSeriesModels = new List <CreateTrainingSeriesCommandModel> { new CreateTrainingSeriesCommandModel { Name = "trainingSeriesSample" } } }; var trainingSeriesResponseModel = await _commandHandler.Handle(command, CancellationToken.None); Assert.Null(trainingSeriesResponseModel.Errors); Assert.True(trainingSeriesResponseModel.Items.Single().Count > 0); }
public async Task <ActionResult <ResponseModel <CreateTrainingSeriesModel> > > Post([FromBody] CreateTrainingSeriesCommand command) { try { command.CreatedBy = Claims[ClaimTypes.Sid].ToInt(); command.TenantId = Guid.Parse(Claims[ClaimTypes.UserData]); var createTrainingSeriesModel = await Mediator.Send(command); return(Created($"api/trainingSeries/{createTrainingSeriesModel.Items}", createTrainingSeriesModel)); } catch (ObjectAlreadyExistsException ex) { return(Conflict(new ResponseModel <CreateTrainingSeriesModel>(new Error(HttpStatusCode.Conflict, ex)))); } catch { return(StatusCode(HttpStatusCode.InternalServerError.ToInt())); } }