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); }
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); }