Esempio n. 1
0
        public async Task GetReviewsWithGreaterRatingReturnsReviews()
        {
            var options = new DbContextOptionsBuilder <ReviewsContext>()
                          .UseInMemoryDatabase(databaseName: $"ItemsDatabase{Guid.NewGuid()}")
                          .Options;

            using (var context = new ReviewsContext(options))
            {
                context.Items.Add(new Item {
                    Name = "item", Reviews = new List <Review>()
                    {
                        new Review {
                            Feedback = "smth", Rating = 3
                        }
                    }
                });
                context.SaveChanges();
            }

            using (var context = new ReviewsContext(options))
            {
                ItemRepository repo        = new ItemRepository(context);
                var            _controller = new ReviewsController(repo, _mockLogger.Object, _mapper.Object);
                var            okResult    = await _controller.GetReviewByAverageRatingGreaterThan(2) as OkObjectResult;

                Assert.Equal(200, okResult.StatusCode);
            }
        }