예제 #1
0
        public async Task GetAllRatesByUserIdShouldReturnZeroWhenInvalidUserId()
        {
            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.GetAllRatesByUserIdAsync <RatingTestModel>("id");

            Assert.Empty(result);
        }
예제 #2
0
        public async Task GetAllRatesByUserIdShouldReturnCorrectCountWhenTakeAndSkipAreUsed()
        {
            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.GetAllRatesByUserIdAsync <RatingTestModel>("userId", 5, 5);

            Assert.Equal(5, result.Count());
        }
예제 #3
0
        public async Task GetAllRatesByUserIdShouldReturnZeroWhenRatingsAreEmpty()
        {
            var options = new DbContextOptionsBuilder <AlexandriaDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var db = new AlexandriaDbContext(options);

            var ratingsService = new StarRatingsService(db);

            var result = await ratingsService.GetAllRatesByUserIdAsync <RatingTestModel>("userId");

            Assert.Empty(result);
        }