Пример #1
0
        public async Task CreateRatingMethodShouldNotChangeCountIfRatingExists()
        {
            var options = new DbContextOptionsBuilder <AlexandriaDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var db = new AlexandriaDbContext(options);

            await db.StarRatings.AddAsync(
                new StarRating
            {
                Rate   = 1,
                UserId = "userId",
                BookId = 1,
            });

            await db.SaveChangesAsync();

            var starRatingsService = new StarRatingsService(db);

            await starRatingsService.CreateRatingAsync(5, "userId", 1);

            var result = await db.StarRatings.CountAsync();

            Assert.Equal(1, result);
        }
Пример #2
0
        public async Task CreateRatingMethodShouldAddRatingInDatabase()
        {
            var options = new DbContextOptionsBuilder <AlexandriaDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var db = new AlexandriaDbContext(options);

            var starRatingsService = new StarRatingsService(db);

            await starRatingsService.CreateRatingAsync(5, "userId", 1);

            Assert.Equal(1, db.StarRatings.Count());
        }
Пример #3
0
        public async Task CreateRatingMethodShouldAddRightRating()
        {
            var options = new DbContextOptionsBuilder <AlexandriaDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var db = new AlexandriaDbContext(options);

            var starRatingsService = new StarRatingsService(db);

            await starRatingsService.CreateRatingAsync(5, "userId", 1);

            var result = await db.StarRatings.FirstOrDefaultAsync();

            Assert.Equal(5, result.Rate);
            Assert.Equal("userId", result.UserId);
            Assert.Equal(1, result.BookId);
        }