コード例 #1
0
        public async Task DeleteCommentTest()
        {
            var options           = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString());
            var commentRepository = new EfDeletableEntityRepository <Comment>(new ApplicationDbContext(options.Options));
            var commentService    = new CommentService(commentRepository);
            var userId            = "userId";
            var carId             = "carId";
            var comment           = new CarCommentsInputModel
            {
                UserId  = userId,
                CarId   = carId,
                Content = "test comment",
                Title   = "test",
            };
            var secComment = new CarCommentsInputModel
            {
                UserId  = userId,
                CarId   = carId,
                Content = "secTest comment",
                Title   = "secTest",
            };
            await commentService.CreateAsync(comment);

            await commentService.CreateAsync(secComment);

            Assert.Equal(2, await commentRepository.All().CountAsync());
            var commentShouldBeDeleted = await commentRepository.All().FirstAsync();

            var commentId = commentShouldBeDeleted.Id;
            await commentService.DeleteCommentAsync(commentId);

            Assert.Equal(1, await commentRepository.All().CountAsync());
        }
コード例 #2
0
        public async Task CreateAsync(CarCommentsInputModel input)
        {
            var comment = new Comment
            {
                UserId  = input.UserId,
                Content = input.Content,
                CarId   = input.CarId,
                Title   = input.Title,
            };

            await this.commentRepository.AddAsync(comment);

            await this.commentRepository.SaveChangesAsync();
        }
コード例 #3
0
        public async Task CreateCommentTest()
        {
            var options           = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString());
            var commentRepository = new EfDeletableEntityRepository <Comment>(new ApplicationDbContext(options.Options));
            var commentService    = new CommentService(commentRepository);
            var userId            = "userId";
            var carId             = "carId";
            var comment           = new CarCommentsInputModel
            {
                UserId  = userId,
                CarId   = carId,
                Content = "test comment",
                Title   = "test",
            };
            await commentService.CreateAsync(comment);

            var createdComment = await commentRepository.All().FirstOrDefaultAsync(x => x.UserId == userId && x.CarId == carId && x.Title == "test");

            Assert.NotNull(createdComment);
        }
コード例 #4
0
        public async Task GetComments()
        {
            var options           = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString());
            var carRepository     = new EfDeletableEntityRepository <Car>(new ApplicationDbContext(options.Options));
            var commentRepository = new EfDeletableEntityRepository <Comment>(new ApplicationDbContext(options.Options));
            var commentService    = new CommentService(commentRepository);
            var userId            = "userId";
            var car = new Car
            {
                ImgsPaths = "asd",
            };
            await carRepository.AddAsync(car);

            await carRepository.SaveChangesAsync();

            var addedCar = await carRepository.All().FirstAsync();

            var carId   = addedCar.Id;
            var comment = new CarCommentsInputModel
            {
                UserId  = userId,
                CarId   = carId,
                Content = "test comment",
                Title   = "test",
            };
            var secComment = new CarCommentsInputModel
            {
                UserId  = userId,
                CarId   = carId,
                Content = "Second comment",
                Title   = "SecCom",
            };
            await commentService.CreateAsync(comment);

            await commentService.CreateAsync(secComment);

            AutoMapperConfig.RegisterMappings(typeof(CarCommentViewModel).Assembly);
            var addedComment = await commentService.GetComments <CarCommentViewModel>(carId);

            Assert.Equal(2, addedComment.Count);
        }