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

            var db = new AlexandriaDbContext(options);

            var rates = new List <StarRating>();

            for (int i = 1; i <= 10; i++)
            {
                rates.Add(new StarRating
                {
                    Rate   = i,
                    UserId = i.ToString(),
                    BookId = 1,
                });
            }

            await db.AddRangeAsync(rates);

            await db.SaveChangesAsync();

            var ratingsService = new StarRatingsService(db);
            var result         = await ratingsService.GetRatesCountByBookIdAsync(3);

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

            var db = new AlexandriaDbContext(options);

            var ratingsService = new StarRatingsService(db);
            var result         = await ratingsService.GetRatesCountByUserIdAsync("userId");

            Assert.Equal(0, result);
        }