public async Task ShouldCreateTodoItem() { var userId = await RunAsDefaultUserAsync(); var listId = await SendAsync(new CreateMovieCommand { Name = "New List" }); var command = new CreateRatingCommand { ListId = listId, Title = "Tasks" }; var itemId = await SendAsync(command); var item = await FindAsync <Rating>(itemId); item.Should().NotBeNull(); item.MovieId.Should().Be(command.ListId); item.MovieName.Should().Be(command.Title); item.CreatedBy.Should().Be(userId); item.Created.Should().BeCloseTo(DateTime.Now, 10000); item.LastModifiedBy.Should().BeNull(); item.LastModified.Should().BeNull(); }
public void ShouldRequireMinimumFields() { var command = new CreateRatingCommand(); FluentActions.Invoking(() => SendAsync(command)).Should().Throw <ValidationException>(); }
public async Task <IActionResult> CreateProductRating( [FromRoute] int productId, [FromBody] CreateRatingRequest request) { var command = new CreateRatingCommand { ProductId = productId, UserId = HttpContext.GetUserId() }; mapper.Map(request, command); var result = await mediator.Send(command).ConfigureAwait(false); return(Created(uriService.GetRatingUri(result.Id), new Response <RatingResponse>(result))); }
public async Task <ActionResult <int> > Post([FromBody] CreateRatingCommand command) { try { var entity = new Rating { DateRated = DateTime.Now, Comment = command.Comment, Rate = command.Rate, UserId = command.UserId, UserSeenFilmId = command.UserSeenFilmId, UserSeenTvShowId = command.UserSeenTvShowId, }; _context.Ratings.Add(entity); await _context.SaveChangesAsync(); return(Ok(entity.Id)); } catch (Exception e) { throw e.InnerException; } }
public async Task <ActionResult <int> > Create(CreateRatingCommand command) { return(await Mediator.Send(command)); }
public async Task <int> InsertRatingAsync(CreateRatingCommand command) { var result = await client.PostAsync($"{baseUrl}/api/ratings/", RequestHelper.GetStringContentFromObject(command)); return(Convert.ToInt32(result.Content.ReadAsStringAsync().Result)); }
public async Task <IActionResult> CreateRating([FromBody] CreateRatingCommand command) => Ok(await _mediator.Send(command));