Exemplo n.º 1
0
        public async Task BannBannedPost()
        {
            Post post = new Post
            {
                Id                = Guid.NewGuid().ToString(),
                Title             = "Test",
                ApplicationUserId = Guid.NewGuid().ToString(),
            };

            BlockedPost blockedPost = new BlockedPost
            {
                PostId            = post.Id,
                ApplicationUserId = post.ApplicationUserId,
                IsBlocked         = true,
            };

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using (var db = new ApplicationDbContext(options))
            {
                IEditorPostService commentService = new EditorPostService(db);
                db.Posts.Add(post);
                db.BlockedPosts.Add(blockedPost);
                await db.SaveChangesAsync();

                var result = await commentService.BannPost(post.Id);

                Assert.False(result);
            }
        }
Exemplo n.º 2
0
        public async Task UnbannPost()
        {
            var post = new Post
            {
                Id = Guid.NewGuid().ToString(),
                ApplicationUserId = Guid.NewGuid().ToString(),
                Title             = "Test",
                PostStatus        = PostStatus.Approved,
            };

            var blockPost = new BlockedPost
            {
                PostId            = post.Id,
                ApplicationUserId = post.ApplicationUserId,
                IsBlocked         = true,
            };
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using (var db = new ApplicationDbContext(options))
            {
                IEditorPostService commentService = new EditorPostService(db);
                db.Posts.Add(post);
                db.BlockedPosts.Add(blockPost);
                await db.SaveChangesAsync();

                var result = await commentService.UnbannPost(post.Id);

                Assert.True(result);
                Assert.False(db.BlockedPosts.FirstOrDefault(x => x.PostId == post.Id).IsBlocked);
            }
        }
Exemplo n.º 3
0
        public async Task PostIsApproved()
        {
            var post = new Post
            {
                Id                = Guid.NewGuid().ToString(),
                Content           = "Test1",
                PostStatus        = PostStatus.Approved,
                ApplicationUserId = Guid.NewGuid().ToString(),
            };

            var pendingPost = new PendingPost
            {
                PostId            = post.Id,
                IsPending         = false,
                ApplicationUserId = post.ApplicationUserId,
            };

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using (var db = new ApplicationDbContext(options))
            {
                IEditorPostService commentService = new EditorPostService(db);
                db.Posts.AddRange(post);
                db.PendingPosts.Add(pendingPost);
                await db.SaveChangesAsync();

                var result = await commentService.ApprovePost(post.Id);

                Assert.False(result);
                Assert.False(db.PendingPosts.FirstOrDefault(x => x.PostId == post.Id).IsPending);
            }
        }
Exemplo n.º 4
0
        public async Task BannPost()
        {
            Post post = new Post
            {
                Id                = Guid.NewGuid().ToString(),
                Title             = "Test",
                ApplicationUserId = Guid.NewGuid().ToString(),
            };

            BlockedPost blockedPost = new BlockedPost
            {
                PostId            = post.Id,
                ApplicationUserId = post.ApplicationUserId,
                IsBlocked         = false,
            };

            FavouritePost favouritePost = new FavouritePost
            {
                ApplicationUserId = post.ApplicationUserId,
                IsFavourite       = true,
                PostId            = post.Id,
            };

            UserAction userAction = new UserAction
            {
                Action = UserActionsType.CreatePost,
                PostId = post.Id,
            };

            PostLike postLike = new PostLike
            {
                PostId  = post.Id,
                UserId  = post.ApplicationUserId,
                IsLiked = true,
            };

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using (var db = new ApplicationDbContext(options))
            {
                IEditorPostService commentService = new EditorPostService(db);
                db.Posts.Add(post);
                db.BlockedPosts.Add(blockedPost);
                db.FavouritePosts.Add(favouritePost);
                db.UserActions.Add(userAction);
                db.PostsLikes.Add(postLike);
                await db.SaveChangesAsync();

                var result = await commentService.BannPost(post.Id);

                Assert.True(result);
                Assert.Equal(1, db.BlockedPosts.Count());
                Assert.Equal(PostStatus.Banned, db.Posts.FirstOrDefault(x => x.Id == post.Id).PostStatus);
                Assert.Equal(0, db.UserActions.Count());
            }
        }
Exemplo n.º 5
0
        public async Task BannNoneExistingPost()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            using (var db = new ApplicationDbContext(options))
            {
                IEditorPostService commentService = new EditorPostService(db);
                var result = await commentService.BannPost(Guid.NewGuid().ToString());

                Assert.False(result);
            }
        }
Exemplo n.º 6
0
        public async Task BannNoneExistingPost()
        {
            var user = new ApplicationUser { Id = Guid.NewGuid().ToString(), UserName = "******" };
            var options = new DbContextOptionsBuilder<ApplicationDbContext>()
                .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var mockService = new Mock<INotificationService>();

            var mockHub = new Mock<IHubContext<NotificationHub>>();

            using (var db = new ApplicationDbContext(options))
            {
                IEditorPostService commentService = new EditorPostService(db, mockService.Object, mockHub.Object);
                var result = await commentService.BannPost(Guid.NewGuid().ToString(), user);

                Assert.False(result);
            }
        }
Exemplo n.º 7
0
        public async Task ApprovePost()
        {
            var user = new ApplicationUser {
                Id = Guid.NewGuid().ToString(), UserName = "******"
            };
            var targetUser = new ApplicationUser {
                Id = Guid.NewGuid().ToString(), UserName = "******"
            };
            var post = new Post
            {
                Id                = Guid.NewGuid().ToString(),
                Content           = "Test1",
                PostStatus        = PostStatus.Pending,
                ApplicationUserId = targetUser.Id,
                ShortContent      = "short content",
            };

            var pendingPost = new PendingPost
            {
                PostId            = post.Id,
                IsPending         = true,
                ApplicationUserId = post.ApplicationUserId,
            };

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var mockService = new Mock <INotificationService>();

            var mockHub = new Mock <IHubContext <NotificationHub> >();

            using (var db = new ApplicationDbContext(options))
            {
                IEditorPostService commentService = new EditorPostService(db, mockService.Object, mockHub.Object);
                db.Posts.AddRange(post);
                db.Users.AddRange(user, targetUser);
                db.PendingPosts.Add(pendingPost);
                await db.SaveChangesAsync();

                var result = await commentService.ApprovePost(post.Id, user);

                Assert.True(result);
                Assert.False(db.PendingPosts.FirstOrDefault(x => x.PostId == post.Id).IsPending);
            }
        }
Exemplo n.º 8
0
        public async Task BannBannedPost()
        {
            var user = new ApplicationUser {
                Id = Guid.NewGuid().ToString(), UserName = "******"
            };

            Post post = new Post
            {
                Id                = Guid.NewGuid().ToString(),
                Title             = "Test",
                ApplicationUserId = Guid.NewGuid().ToString(),
            };

            BlockedPost blockedPost = new BlockedPost
            {
                PostId            = post.Id,
                ApplicationUserId = post.ApplicationUserId,
                IsBlocked         = true,
            };

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;

            var mockService = new Mock <INotificationService>();

            var mockHub = new Mock <IHubContext <NotificationHub> >();

            using (var db = new ApplicationDbContext(options))
            {
                IEditorPostService commentService = new EditorPostService(db, mockService.Object, mockHub.Object);
                db.Posts.Add(post);
                db.BlockedPosts.Add(blockedPost);
                await db.SaveChangesAsync();

                var result = await commentService.BannPost(post.Id, user);

                Assert.False(result);
            }
        }