Example #1
0
        public async Task EditCommentWithWrongIdDoenstChangeTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            dbContext.Comments.Add(new Comment
            {
                Id        = 1,
                Content   = "Unedited",
                UserId    = Guid.NewGuid().ToString(),
                ProductId = 3,
            });
            await dbContext.SaveChangesAsync();

            var repository = new EfDeletableEntityRepository <Comment>(dbContext);
            var service    = new CommentsService(repository);
            await service.EditCommetAsync(new EditCommentViewModel
            {
                Id        = 2,
                Content   = "Edited",
                ProductId = 3,
            });

            var comment = service.GetCommentToChange(1);

            Assert.Equal("Unedited", comment.Content);
        }
Example #2
0
        public async Task GetCommentToEditRetutnsNullIfIdDoentExist(int id)
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            dbContext.Comments.Add(new Comment
            {
                Id        = 1,
                Content   = "Test",
                UserId    = Guid.NewGuid().ToString(),
                ProductId = 3,
            });
            await dbContext.SaveChangesAsync();

            var repository = new EfDeletableEntityRepository <Comment>(dbContext);
            var service    = new CommentsService(repository);
            var comment    = service.GetCommentToChange(id);

            Assert.Null(comment);
        }
Example #3
0
        public async Task GetCommentToEditTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            dbContext.Comments.Add(new Comment
            {
                Id        = 1,
                Content   = "Test",
                UserId    = Guid.NewGuid().ToString(),
                ProductId = 3,
            });
            await dbContext.SaveChangesAsync();

            var repository = new EfDeletableEntityRepository <Comment>(dbContext);
            var service    = new CommentsService(repository);
            var comment    = service.GetCommentToChange(1);

            Assert.Equal(1, comment.Id);
            Assert.Equal(typeof(EditCommentViewModel), comment.GetType());
        }