Exemplo n.º 1
0
        public async Task TopicTest()
        {
            RelatedDataSet dataSetA = new RelatedDataSet("JimmyJimerson", "ab10101010", "Theory");

            string outputTopicName;

            // Seed the test database
            using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                context.Topics.Add(dataSetA.Topic);
                context.SaveChanges();
            }

            using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions))
            {
                RepoLogic       repoLogic       = new RepoLogic(context);
                IForumLogic     forumLogic      = new ForumLogic(repoLogic);
                ForumController forumController = new ForumController(forumLogic);

                List <string> topicNames = (await forumController.GetTopics()).Value;
                outputTopicName = topicNames[0];
            }

            Assert.Equal(dataSetA.Topic.TopicName, outputTopicName);
        }
        public async Task FollowMovieTwiceTest()
        {
            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);
                await repoLogic.AddUser(dataSetA.User);

                await repoLogic.AddMovie(dataSetA.Movie.MovieId);

                await repoLogic.FollowMovie(dataSetA.FollowingMovie);
            }

            using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions))
            {
                RepoLogic repoLogic = new RepoLogic(context);

                // Test FollowMovie() a second time with same input
                result = await repoLogic.FollowMovie(dataSetA.FollowingMovie);
            }

            Assert.False(result);
        }
        public async Task NoUserUpdateUserTest()
        {
            bool result;

            Repository.Models.User updatedRepoUser = new Repository.Models.User();

            RelatedDataSet dataSetA = new RelatedDataSet("JimmyJimerson", "ab10101010", "Theory");

            updatedRepoUser.Username    = dataSetA.User.Username;
            updatedRepoUser.FirstName   = "Steve";
            updatedRepoUser.LastName    = dataSetA.User.LastName;
            updatedRepoUser.Email       = dataSetA.User.Email;
            updatedRepoUser.Permissions = dataSetA.User.Permissions;
            updatedRepoUser.Username    = dataSetA.User.Username;

            using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                RepoLogic repoLogic = new RepoLogic(context);

                // Test UpdateUser() without User dependency
                result = await repoLogic.UpdateUser(dataSetA.User.Username, updatedRepoUser);
            }

            Assert.False(result);
        }
        public async Task AddUserTwice()
        {
            bool           result;
            RelatedDataSet dataSetA = new RelatedDataSet("JimmyJimerson", "ab10101010", "Theory");

            // Seed the test database
            using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                GlobalModels.User inputGMUser = BusinessLogic.Mapper.RepoUserToUser(dataSetA.User);

                RepoLogic repoLogic = new RepoLogic(context);

                // Test CreateUser()
                IUserLogic     userLogic      = new UserLogic(repoLogic);
                UserController userController = new UserController(userLogic);
                await userController.CreateUser(inputGMUser);
            }

            using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions))
            {
                RepoLogic repoLogic = new RepoLogic(context);

                // Test AddUser()
                result = await repoLogic.AddUser(dataSetA.User);
            }

            Assert.False(result);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        public async Task UserTest()
        {
            GlobalModels.User updatedGMUser = new GlobalModels.User();

            RelatedDataSet dataSetA = new RelatedDataSet("JimmyJimerson", "ab10101010", "Theory");

            updatedGMUser.Username    = dataSetA.User.Username;
            updatedGMUser.Firstname   = "Steve";
            updatedGMUser.Lastname    = dataSetA.User.LastName;
            updatedGMUser.Email       = dataSetA.User.Email;
            updatedGMUser.Permissions = dataSetA.User.Permissions;
            updatedGMUser.Username    = dataSetA.User.Username;

            string inputFirstName = dataSetA.User.FirstName;
            string outputFirstName;

            // Seed the test database
            using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                RepoLogic repoLogic = new RepoLogic(context);

                // Test CreateUser & UpdateUser()
                IUserLogic     userLogic      = new UserLogic(repoLogic);
                UserController userController = new UserController(userLogic);
                await userController.CreateUser(BusinessLogic.Mapper.RepoUserToUser(dataSetA.User));

                await userController.UpdateUser(dataSetA.User.Username, updatedGMUser);
            }

            using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions))
            {
                RepoLogic repoLogic = new RepoLogic(context);

                // Test GetUser()
                IUserLogic     userLogic      = new UserLogic(repoLogic);
                UserController userController = new UserController(userLogic);
                outputFirstName = userController.GetUser(dataSetA.User.Username).Value.Firstname;
            }

            Assert.NotEqual(inputFirstName, outputFirstName);
        }
Exemplo n.º 7
0
        public async Task ReviewsPageTest()
        {
            GlobalModels.Review inputGMReview;
            GlobalModels.Review outputGMReview;

            RelatedDataSet dataSetA = new RelatedDataSet("JimmyJimerson", "ab10101010", "Theory");

            // Seed the test database
            using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                inputGMReview = BusinessLogic.Mapper.RepoReviewToReview(dataSetA.Review);

                RepoLogic repoLogic = new RepoLogic(context);
                // Load Database entries for the object-under-test's foreign keys
                await repoLogic.AddUser(dataSetA.User);

                await repoLogic.AddMovie(dataSetA.Movie.MovieId);

                // Test CreateReview()
                IMovieLogic     movieLogic      = new MovieLogic(repoLogic);
                MovieController movieController = new MovieController(movieLogic);
                await movieController.CreateReview(inputGMReview);
            }

            using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions))
            {
                RepoLogic repoLogic = new RepoLogic(context);

                // Test GetReviews()
                IMovieLogic     movieLogic      = new MovieLogic(repoLogic);
                MovieController movieController = new MovieController(movieLogic);
                await movieController.SetReviewsPageSize(10);

                List <GlobalModels.Review> gmReviewList = (await movieController.GetReviewsPage(dataSetA.Movie.MovieId, 1, "ratingasc")).Value;
                outputGMReview = gmReviewList
                                 .FirstOrDefault <GlobalModels.Review>(r => r.Movieid == dataSetA.Movie.MovieId);
            }

            Assert.Equal(inputGMReview, outputGMReview);
        }
        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);
        }
        public async Task NoMovieGetMovieReviewsTest()
        {
            object 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 GetMovieReviews() without Movie dependency
                result = await repoLogic.GetMovieReviews(dataSetA.Movie.MovieId);
            }

            Assert.Null(result);
        }
        public void NoDiscGetDiscussionTopicTest()
        {
            object 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 GetDiscussionTopic() without Discussion dependency
                result = repoLogic.GetDiscussionTopic(dataSetA.DiscussionTopic.DiscussionId);
            }

            Assert.Null(result);
        }
        public async Task NoMovieAddReviewTest()
        {
            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);
                await repoLogic.AddUser(dataSetA.User);

                // Test AddReview() without Movie dependency
                result = await repoLogic.AddReview(dataSetA.Review);
            }

            Assert.False(result);
        }
Exemplo n.º 12
0
        public async Task GetDiscussionTest()
        {
            RelatedDataSet dataSetA = new RelatedDataSet("JimmyJimerson", "ab10101010", "Theory");

            GlobalModels.Discussion inputGMDiscussion = BusinessLogic.Mapper.RepoDiscussionToDiscussion(dataSetA.Discussion, dataSetA.Topic);
            GlobalModels.Discussion outputGMDiscussion;

            // Seed the test database
            using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                var newDiscussion = new GlobalModels.NewDiscussion(inputGMDiscussion);

                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.AddTopic(dataSetA.Topic);

                // Test CreateDiscussion()
                IForumLogic     forumLogic      = new ForumLogic(repoLogic);
                ForumController forumController = new ForumController(forumLogic);
                await forumController.CreateDiscussion(newDiscussion);
            }

            using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions))
            {
                RepoLogic repoLogic = new RepoLogic(context);

                // Test GetDiscussions()
                IForumLogic     forumLogic      = new ForumLogic(repoLogic);
                ForumController forumController = new ForumController(forumLogic);
                outputGMDiscussion = (await forumController.GetDiscussion(dataSetA.Discussion.DiscussionId)).Value;
            }

            Assert.Equal(inputGMDiscussion, outputGMDiscussion);
        }
Exemplo n.º 13
0
        public async Task UsersTest()
        {
            GlobalModels.User inputGMUser;
            GlobalModels.User outputGMUser;

            RelatedDataSet dataSetA = new RelatedDataSet("JimmyJimerson", "ab10101010", "Theory");

            // Seed the test database
            using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                inputGMUser = BusinessLogic.Mapper.RepoUserToUser(dataSetA.User);

                RepoLogic repoLogic = new RepoLogic(context);

                // Test CreateUser()
                IUserLogic     userLogic      = new UserLogic(repoLogic);
                UserController userController = new UserController(userLogic);
                await userController.CreateUser(inputGMUser);
            }

            using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions))
            {
                RepoLogic repoLogic = new RepoLogic(context);

                // Test GetUsers()
                IUserLogic               userLogic      = new UserLogic(repoLogic);
                UserController           userController = new UserController(userLogic);
                List <GlobalModels.User> gmUserList     = (await userController.Get()).Value;
                outputGMUser = gmUserList
                               .FirstOrDefault <GlobalModels.User>(u => u.Username == dataSetA.User.Username);
            }

            Assert.Equal(inputGMUser, outputGMUser);
        }
Exemplo n.º 14
0
        public async Task FollowMovieTest()
        {
            string outputFollowingMovieId;

            RelatedDataSet dataSetA = new RelatedDataSet("JimmyJimerson", "ab10101010", "Theory");

            // Seed the test database
            using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                RepoLogic repoLogic = new RepoLogic(context);
                // Load Database entries for the object-under-test's foreign keys
                await repoLogic.AddUser(dataSetA.User);

                await repoLogic.AddMovie(dataSetA.Movie.MovieId);

                // Test FollowMovie()
                IUserLogic     userLogic      = new UserLogic(repoLogic);
                UserController userController = new UserController(userLogic);
                await userController.FollowMovie(dataSetA.FollowingMovie.Username, dataSetA.FollowingMovie.MovieId);
            }

            using (var context = new Repository.Models.Cinephiliacs_DbContext(dbOptions))
            {
                RepoLogic repoLogic = new RepoLogic(context);

                // Test GetFollowingMovies()
                IUserLogic     userLogic          = new UserLogic(repoLogic);
                UserController userController     = new UserController(userLogic);
                List <string>  followingMovieList = (await userController.GetFollowingMovies(dataSetA.User.Username)).Value;
                outputFollowingMovieId = followingMovieList.FirstOrDefault <string>();
            }

            Assert.Equal(dataSetA.FollowingMovie.MovieId, outputFollowingMovieId);
        }