public async Task <bool> CreateDiscussion(NewDiscussion discussion) { var repoDiscussion = Mapper.NewDiscussionToNewRepoDiscussion(discussion); var repoTopic = new Repository.Models.Topic(); repoTopic.TopicName = discussion.Topic; return(await _repo.AddDiscussion(repoDiscussion, repoTopic)); }
public async Task CommentsPageTest() { RelatedDataSet dataSetA = new RelatedDataSet("JimmyJimerson", "ab10101010", "Theory"); GlobalModels.Comment inputGMComment = BusinessLogic.Mapper.RepoCommentToComment(dataSetA.Comment); GlobalModels.Comment outputGMComment; // Seed the test database using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var newComment = new GlobalModels.NewComment(inputGMComment); RepoLogic repoLogic = new RepoLogic(context); // Add Database entries for the object-under-test's foreign keys await repoLogic.AddUser(dataSetA.User); await repoLogic.AddMovie(dataSetA.Movie.MovieId); await repoLogic.AddDiscussion(dataSetA.Discussion, dataSetA.Topic); // Test CreateComment() IForumLogic forumLogic = new ForumLogic(repoLogic); ForumController forumController = new ForumController(forumLogic); await forumController.CreateComment(newComment); } using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions)) { RepoLogic repoLogic = new RepoLogic(context); // Test GetComments() IForumLogic forumLogic = new ForumLogic(repoLogic); ForumController forumController = new ForumController(forumLogic); await forumController.SetCommentsPageSize(10); List <GlobalModels.Comment> gmCommentList = (await forumController.GetCommentsPage(dataSetA.Comment.DiscussionId, 1)).Value; outputGMComment = gmCommentList .FirstOrDefault <GlobalModels.Comment>(c => c.Discussionid == dataSetA.Comment.DiscussionId); } Assert.Equal(inputGMComment, outputGMComment); }
public async Task NoUserAddDiscussionTest() { bool result; RelatedDataSet dataSetA = new RelatedDataSet("JimmyJimerson", "ab10101010", "Theory"); using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); RepoLogic repoLogic = new RepoLogic(context); // Test AddDiscussion() without User dependency result = await repoLogic.AddDiscussion(dataSetA.Discussion, dataSetA.Topic); } Assert.False(result); }