public async Task Create__Admin_Or_Moderator_Can_Create_Public_Training() { string[] users = { "*****@*****.**", "*****@*****.**" }; int i = 1; foreach (var user in users) { await LogInAs(user); CreateTrainingRequest createRequest = Factory.Training.CreateTrainingRequest(); var response = await Client.PostAsJsonAsync(ApiRoutes.Training.CreatePublic, createRequest); response.StatusCode.Should().Be(HttpStatusCode.Created); var responseData = await response.Content.ReadAsAsync <TrainingMinifiedResponse>(); var dbTraining = await Context.Training.FirstOrDefaultAsync(x => x.Id == responseData.Id); dbTraining.Should().NotBeNull(); dbTraining.Name.Should().Be(responseData.Name); dbTraining.IsPublic.Should().Be(true); int trainingCount = await Context.Training.AsNoTracking().CountAsync(); trainingCount.Should().Be(i); int userTrainingCount = await Context.UserTraining.AsNoTracking().CountAsync(); userTrainingCount.Should().Be(0); i++; } }
public async Task Create__User_Can_Create_Private_Training() { AuthenticatedUser user = await LogInAs("*****@*****.**"); CreateTrainingRequest createRequest = Factory.Training.CreateTrainingRequest(); var response = await Client.PostAsJsonAsync(ApiRoutes.Training.Create, createRequest); response.StatusCode.Should().Be(HttpStatusCode.Created); var responseData = await response.Content.ReadAsAsync <TrainingMinifiedResponse>(); var dbTraining = await Context.Training.FirstOrDefaultAsync(x => x.Id == responseData.Id); var dbUserTraining = await Context.UserTraining .FirstOrDefaultAsync(x => x.TrainingId == responseData.Id && x.UserId == user.Id); dbTraining.Should().NotBeNull(); dbTraining.Name.Should().Be(responseData.Name); dbTraining.IsPublic.Should().Be(false); dbUserTraining.Should().NotBeNull(); int trainingCount = await Context.Training.AsNoTracking().CountAsync(); trainingCount.Should().Be(1); int userTrainingCount = await Context.UserTraining.AsNoTracking().CountAsync(); userTrainingCount.Should().Be(1); }
public async Task <IActionResult> CreatePublic([FromBody] CreateTrainingRequest request) { var newTraining = _mapper.Map <Training>(request); var createdTraining = await _trainingService.CreatePublicTrainingAsync(newTraining); if (createdTraining.Id == 0) { return(BadRequest(new ErrorResponse("Wystąpił błąd podczas dodawania"))); } return(CreatedAtAction(nameof(GetTrainingById), new { trainingId = createdTraining.Id }, _mapper.Map <TrainingMinifiedResponse>(createdTraining))); }
public async Task <IActionResult> Create([FromBody] CreateTrainingRequest request, CancellationToken cancellationToken = default) { return(Ok(await Mediator.Send(request, cancellationToken))); }