コード例 #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);
        }