Beispiel #1
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);
            }
        }
Beispiel #2
0
        public async Task ApproveNoneExistingPost()
        {
            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.ApprovePost(Guid.NewGuid().ToString());

                Assert.False(result);
            }
        }
        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);
            }
        }
        public async Task ApproveNoneExistingPost()
        {
            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.ApprovePost(Guid.NewGuid().ToString(), user);

                Assert.False(result);
            }
        }