示例#1
0
        public async Task GetRatesCountByUserShouldReturnZeroWhenInvalidUserId()
        {
            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 = "userId",
                    BookId = i,
                });
            }

            await db.StarRatings.AddRangeAsync(rates);

            await db.SaveChangesAsync();

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

            Assert.Equal(0, result);
        }
示例#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);
        }