コード例 #1
0
        public void Delete_Topic_Deleted_If_Topic_Starter()
        {
            var postRepository = Substitute.For<IPostRepository>();
            var topicRepository = Substitute.For<ITopicRepository>();
            var roleService = Substitute.For<IRoleService>();
            var membershipUserPointsService = Substitute.For<IMembershipUserPointsService>();
            var settingsService = Substitute.For<ISettingsService>();
            var localisationService = Substitute.For<ILocalizationService>();
            var postService = new PostService(membershipUserPointsService, settingsService, roleService, postRepository, topicRepository, localisationService, _api);

            var tags = new List<TopicTag>
                           {
                               new TopicTag{Tag = "Thor"},
                               new TopicTag{Tag = "Gambit"}
                           };
            var topic = new Topic { Name = "Captain America", Tags = tags };
            var post = new Post { Id = Guid.NewGuid(), Topic = topic, IsTopicStarter = true};
            topic.LastPost = post;
            topic.Posts = new List<Post>();
            post.IsTopicStarter = true;
            topic.Posts.Add(post);

            // Save
            var deleteTopic = postService.Delete(post);

            Assert.IsTrue(deleteTopic);
        }
コード例 #2
0
        public void Delete_Post_Removed_From_TopicList_And_Last_Post()
        {
            var postRepository = Substitute.For<IPostRepository>();
            var topicRepository = Substitute.For<ITopicRepository>();
            var roleService = Substitute.For<IRoleService>();
            var membershipUserPointsService = Substitute.For<IMembershipUserPointsService>();
            var settingsService = Substitute.For<ISettingsService>();
            var localisationService = Substitute.For<ILocalizationService>();
            var postService = new PostService(membershipUserPointsService, settingsService, roleService, postRepository, topicRepository, localisationService, _api);
            
            // Create topic
            var topic = new Topic { Name = "Captain America"};

            // Create some posts with one to delete
            var postToDelete = new Post { Id = Guid.NewGuid(), Topic = topic, IsTopicStarter = false, DateCreated = DateTime.UtcNow};
            var postToStay = new Post { Id = Guid.NewGuid(), Topic = topic, IsTopicStarter = false, DateCreated = DateTime.UtcNow.Subtract(TimeSpan.FromDays(2)) };
            var postToStayTwo = new Post { Id = Guid.NewGuid(), Topic = topic, IsTopicStarter = false, DateCreated = DateTime.UtcNow.Subtract(TimeSpan.FromDays(3)) };

            // set last post
            topic.LastPost = postToDelete;

            // Set the post list to the topic
            var posts = new List<Post> {postToDelete, postToStay, postToStayTwo};
            topic.Posts = posts;

            // Save
            postService.Delete(postToDelete);

            // Test that settings is no longer in cache
            Assert.IsTrue(topic.LastPost == postToStay);
            Assert.IsTrue(topic.Posts.Count == 2);         
        }
コード例 #3
0
ファイル: PostServiceTests.cs プロジェクト: kangjh0815/test
        public void AddPost()
        {
            var postRepository = Substitute.For<IPostRepository>();
            var topicRepository = Substitute.For<ITopicRepository>();
            var roleService = Substitute.For<IRoleService>();
            var membershipUserPointsService = Substitute.For<IMembershipUserPointsService>();
            var settingsService = Substitute.For<ISettingsService>();
            settingsService.GetSettings().Returns(new Settings { PointsAddedPerPost = 20 });
            var localisationService = Substitute.For<ILocalizationService>();
            var postService = new PostService(membershipUserPointsService, settingsService, roleService, postRepository, topicRepository, localisationService, _api);

            var category = new Category();
            var role = new MembershipRole{RoleName = "TestRole"};

            var categoryPermissionForRoleSet = new List<CategoryPermissionForRole>
                                                   {
                                                       new CategoryPermissionForRole { Permission = new Permission { Name = AppConstants.PermissionEditPosts }, IsTicked = true},
                                                       new CategoryPermissionForRole { Permission = new Permission { Name = AppConstants.PermissionDenyAccess }, IsTicked = false},
                                                       new CategoryPermissionForRole { Permission = new Permission { Name = AppConstants.PermissionReadOnly  }, IsTicked = false}
                                                   };

            var permissionSet = new PermissionSet(categoryPermissionForRoleSet);
            roleService.GetPermissions(category, role).Returns(permissionSet);

            var topic = new Topic { Name = "Captain America", Category = category};
            var user = new MembershipUser {
                UserName = "******",
                Roles = new List<MembershipRole>{role}
            };

            var newPost = postService.AddNewPost("A test post", topic, user, out permissionSet);

            Assert.AreEqual(newPost.User, user);
            Assert.AreEqual(newPost.Topic, topic);
        }
コード例 #4
0
        public void BeforePostMadeCancel()
        {
            var postRepository = Substitute.For<IPostRepository>();
            var topicRepository = Substitute.For<ITopicRepository>();
            var roleService = Substitute.For<IRoleService>();
            var membershipUserPointsService = Substitute.For<IMembershipUserPointsService>();
            var settingsService = Substitute.For<ISettingsService>();

            var localisationService = Substitute.For<ILocalizationService>();
            var postService = new PostService(membershipUserPointsService, settingsService, roleService, postRepository, topicRepository, localisationService, _api);

            var category = new Category();
            var role = new MembershipRole { RoleName = "TestRole" };

            var categoryPermissionForRoleSet = new List<CategoryPermissionForRole>
                                                   {
                                                       new CategoryPermissionForRole { Permission = new Permission { Name = AppConstants.PermissionEditPosts }, IsTicked = true},
                                                       new CategoryPermissionForRole { Permission = new Permission { Name = AppConstants.PermissionDenyAccess }, IsTicked = false},
                                                       new CategoryPermissionForRole { Permission = new Permission { Name = AppConstants.PermissionReadOnly  }, IsTicked = false}
                                                   };

            var permissionSet = new PermissionSet(categoryPermissionForRoleSet);
            roleService.GetPermissions(category, role).Returns(permissionSet);

            var topic = new Topic { Name = "Captain America", Category = category };
            var user = new MembershipUser
            {
                UserName = "******",
                Roles = new List<MembershipRole>() { role }
            };

            EventManager.Instance.BeforePostMade += eventsService_BeforePostMadeCancel;
            postService.AddNewPost("A test post", topic, user, out permissionSet);

            membershipUserPointsService.DidNotReceive().Add(Arg.Is<MembershipUserPoints>(x => x.User == user));
            EventManager.Instance.BeforePostMade -= eventsService_BeforePostMadeCancel;
        }