Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("ID,BeerID,UserID,Rating,Description,LikesCount,IsDeleted,IsFlagged")] ReviewViewModel review)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await _service.CreateAsync(review.MapReviewViewToDTO());

                    return(RedirectToAction(nameof(Details), "Beers", new { id = review.BeerID }));
                }
                catch (Exception)
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            ViewData["BeerID"] = _beerService.GetAsync(review.BeerID);
            ViewData["UserID"] = _userService.GetUser(review.UserID);
            return(View(review));
        }
Ejemplo n.º 2
0
        public async Task CreateAsyncShouldCreateReviewSuccessfully()
        {
            await _reviewsService.CreateAsync("Very good pizza", "1234", "2345");

            Assert.Equal(1, _reviewsRepository.All().Count());
            Assert.Equal("Very good pizza", _reviewsRepository.All().First().Text);
            Assert.Equal("1234", _reviewsRepository.All().First().CreatorId);
            Assert.Equal("2345", _reviewsRepository.All().First().ProductId);
        }