Beispiel #1
0
        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();
        }
Beispiel #2
0
        public void ShouldRequireMinimumFields()
        {
            var command = new CreateRatingCommand();

            FluentActions.Invoking(() =>
                                   SendAsync(command)).Should().Throw <ValidationException>();
        }
Beispiel #3
0
        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;
            }
        }
Beispiel #5
0
 public async Task <ActionResult <int> > Create(CreateRatingCommand command)
 {
     return(await Mediator.Send(command));
 }
Beispiel #6
0
        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));
        }
Beispiel #7
0
 public async Task <IActionResult> CreateRating([FromBody] CreateRatingCommand command)
 => Ok(await _mediator.Send(command));