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); }
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()); }
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); }