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 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.º 3
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.º 4
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.º 5
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);
            }
        }