public async Task CanCreateTrainingAsync() { var authorizedClient = SystemTestExtension.GetTokenAuthorizeHttpClient(_factory); var createTrainingCommand = new CreateTrainingCommand { CreateTrainingModels = new List <CreateTrainingCommandModel> { new CreateTrainingCommandModel { TrainingSeriesId = 1, Name = "trainingSample", Description = "sampleDescription", TrainingCategoryId = 1, BeginDateTime = DateTimeOffset.Now, EndDateTime = DateTimeOffset.Now.AddDays(5) } } }; var serializedTrainingCommand = JsonConvert.SerializeObject(createTrainingCommand); // The endpoint or route of the controller action. var httpResponse = await authorizedClient.PostAsync(requestUri : "/Training", content : new StringContent(content: serializedTrainingCommand, 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 CreateTrainingCommand { CreatedBy = _adminUserId, TenantId = _tenantId, CreateTrainingModels = new List <CreateTrainingCommandModel> { new CreateTrainingCommandModel { TrainingSeriesId = _trainingSeriesId, TrainingCategoryId = _trainingCategoryId, Name = "trainingSample", Description = "sampleDescription", EndDateTime = DateTimeOffset.Now.AddDays(5), BeginDateTime = DateTimeOffset.Now } } }; var trainingResponseModel = await _commandHandler.Handle(command, CancellationToken.None); Assert.Null(trainingResponseModel.Errors); Assert.True(trainingResponseModel.Items.Single().Count > 0); }
public async Task <IActionResult> CreateTrening([FromBody] NewTrainingReqest reqest) { var command = new CreateTrainingCommand( runnerId: reqest.RunnerId, timeToDo: reqest.TimeToDo, details: reqest.Details, comments: reqest.Comments ); await commandSender.SendAsync(command); return(Ok()); }
public async Task Handler_SuccessfullyPersistsTraining() { var command = new CreateTrainingCommand { Description = "Learning to do stuff", Location = "The learning place", Start = DateTime.Now, End = DateTime.Now.AddHours(5) }; var handler = new CreateTrainingCommandHandler(mockRepo.Object); await handler.Handle(command, CancellationToken.None); mockRepo.Verify(x => x.Add(It.Is <Training>( t => t.Description == command.Description && t.Location == command.Location && t.TrainingPeriod.Start == command.Start && t.TrainingPeriod.End == command.End )), Times.Once()); }
public async Task <ActionResult <ResponseModel <CreateTrainingModel> > > Post([FromBody] CreateTrainingCommand command) { try { command.CreatedBy = Claims[ClaimTypes.Sid].ToInt(); command.TenantId = Guid.Parse(Claims[ClaimTypes.UserData]); var createTrainingModel = await Mediator.Send(command); return(Created($"api/training/{createTrainingModel.Items}", createTrainingModel)); } catch (ObjectAlreadyExistsException ex) { return(Conflict(new ResponseModel <CreateTrainingModel>(new Error(HttpStatusCode.Conflict, ex)))); } catch { return(StatusCode(HttpStatusCode.InternalServerError.ToInt())); } }
public async Task <IActionResult> Create([FromBody] CreateTrainingCommand command) { var id = await Mediator.Send(command); return(CreatedAtAction(nameof(Get), new { id }, new { id })); }