コード例 #1
0
        public async Task RatingRepo_GetById_ReturnsElementByGivenId(int id)
        {
            var repository = new RatingRepository(_context);
            var result     = await repository.GetByIdAsync(id);

            var expected = new Rating {
                RatingId = 1,
                ImageId  = 1,
                UserId   = "user"
            };

            Assert.Equal(expected.ImageId, result.ImageId);
            Assert.Equal(expected.RatingId, result.RatingId);
            Assert.Equal(expected.UserId, result.UserId);
        }
コード例 #2
0
        public async Task RatingRepo_Update_UpdatesOneRatingWhichIsTheFirstOne()
        {
            var repository = new RatingRepository(_context);
            var ratings    = await repository.GetAllAsync();

            var ratingToUpdate = ratings.First();

            ratingToUpdate.UserId = "user123";
            repository.Update(ratingToUpdate);
            _context.SaveChanges();

            var expectedUserId = "user123";
            var result         = await repository.GetByIdAsync(ratingToUpdate.RatingId);

            Assert.Equal(expectedUserId, result.UserId);
        }
コード例 #3
0
        public async Task RatingRepo_Remove_RemovesOneRatingWhichIsTheLastOne()
        {
            var repository = new RatingRepository(_context);

            var ratings = await repository.GetAllAsync();

            var ratingToRemove = ratings.Last();

            repository.Remove(ratingToRemove);
            _context.SaveChanges();

            int expected = ratings.Count() - 1;
            var result   = await repository.GetAllAsync();

            Assert.Equal(expected, result.Count());
            Assert.NotEqual(ratingToRemove.RatingId, result.Last().RatingId);
            Assert.Null(await repository.GetByIdAsync(ratingToRemove.RatingId));
        }