Esempio n. 1
0
        public async Task GetAverageRatingByBookIdShouldZeroWhenBookIdIsInvalid()
        {
            var options = new DbContextOptionsBuilder <AlexandriaDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var db = new AlexandriaDbContext(options);

            var ratings = new List <StarRating>();

            for (int i = 1; i <= 2; i++)
            {
                ratings.Add(
                    new StarRating
                {
                    Rate   = 5,
                    UserId = "userId",
                    BookId = 1,
                });
            }

            await db.StarRatings.AddRangeAsync(ratings);

            await db.SaveChangesAsync();

            var ratingsService = new StarRatingsService(db);
            var result         = await ratingsService.GetAverageRatingByBookIdAsync(5);

            Assert.Equal(0, result);
        }
Esempio n. 2
0
        public async Task GetAverageRatingByBookIdShouldZeroWhenRatingsIsEmpty()
        {
            var options = new DbContextOptionsBuilder <AlexandriaDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var db = new AlexandriaDbContext(options);

            var ratingsService = new StarRatingsService(db);
            var result         = await ratingsService.GetAverageRatingByBookIdAsync(1);

            Assert.Equal(0, result);
        }