Example #1
0
        public Annotation EnsureTestAnnotationExistsThroughContext_ReturnsTestAnnotation(int userId)
        {
            SOVAContext databaseContext = new SOVAContext(_connectionString);

            string annotation   = "Test Annotation";
            int    submissionId = 19;

            Annotation testAnnotation = databaseContext.Annotations.FirstOrDefault(annotation => annotation.SubmissionId == submissionId && annotation.UserId == userId);

            if (testAnnotation != null)
            {
                return(testAnnotation);
            }

            databaseContext.Annotations.Add(new Annotation
            {
                AnnotationString = annotation,
                SubmissionId     = submissionId,
                UserId           = userId
            });

            databaseContext.SaveChanges();

            return(databaseContext.Annotations.FirstOrDefault(annotation => annotation.SubmissionId == submissionId && annotation.UserId == userId));
        }
Example #2
0
        public void GetBookmarkBySubmissionAndUserIds_ValidArguments()
        {
            // Arrange
            SOVAContext       databaseContext   = new SOVAContext(_connectionString);
            MarkingRepository markingRepository = new MarkingRepository(databaseContext);

            int submissionId = 19;

            User testUser = EnsureTestUserExistsThroughContext_ReturnsTestUser();

            Marking marking = databaseContext.Markings.Find(submissionId, testUser.Id);

            if (marking == null)
            {
                databaseContext.Markings.Add(new Marking
                {
                    SubmissionId = submissionId,
                    UserId       = testUser.Id
                });
            }

            databaseContext.SaveChanges();

            // Act
            bool bookmarked = markingRepository.IsMarked(submissionId, testUser.Id);

            // Assert
            Assert.True(bookmarked);

            // Clean-Up
            marking = databaseContext.Markings.FirstOrDefault(b => b.SubmissionId == submissionId && b.UserId == testUser.Id);
            databaseContext.Markings.Remove(marking);

            databaseContext.SaveChanges();
        }
Example #3
0
        //For RUC's database connection
        //private readonly string _connectionString = "host=rawdata.ruc.dk;db=raw4;uid=raw4;pwd=yzOrEFi)";
        public User EnsureTestUserExistsThroughContext_ReturnsTestUser()
        {
            SOVAContext databaseContext = new SOVAContext(_connectionString);

            string testUsername = "******";
            string testPassword = "******";
            string testSalt     = "testSalt";

            User testUser = databaseContext.Users.FirstOrDefault(u => u.Username == testUsername);

            if (testUser != null)
            {
                return(testUser);
            }

            databaseContext.Users.Add(new User
            {
                Username = testUsername,
                Password = testPassword,
                Salt     = testSalt
            });

            databaseContext.SaveChanges();

            return(databaseContext.Users.First(user => user.Username == testUsername));
        }
Example #4
0
        public void DeleteAnnotationOnSubmissionForUser_InvalidArguments(int submissionId, int userId)
        {
            // Arrange
            SOVAContext          databaseContext      = new SOVAContext(_connectionString);
            AnnotationRepository annotationRepository = new AnnotationRepository(databaseContext);

            // Act
            bool deleted = annotationRepository.Delete(submissionId, userId);

            // Assert
            Assert.False(deleted);
        }
Example #5
0
        public void GetAnswerById_InvalidArgument(int answerId)
        {
            // Arrange
            SOVAContext      databaseContext  = new SOVAContext(_connectionString);
            AnswerRepository answerRepository = new AnswerRepository(databaseContext);

            // Act
            Answer answer = answerRepository.GetAnswerById(answerId);

            // Assert
            Assert.Null(answer);
        }
Example #6
0
        public void GetUserById_InvalidArgument(int userId)
        {
            // Arrange
            SOVAContext    databaseContext = new SOVAContext(_connectionString);
            UserRepository userRepository  = new UserRepository(databaseContext);

            // Act
            User testUser = userRepository.GetUserById(userId);

            // Assert
            Assert.Null(testUser);
        }
Example #7
0
        public void CreateAnnotationOnSubmissionForUser_InvalidArguments(string annotation, int submissionId, int userId)
        {
            // Arrange
            SOVAContext          databaseContext      = new SOVAContext(_connectionString);
            AnnotationRepository annotationRepository = new AnnotationRepository(databaseContext);

            // Act
            Annotation actualAnnotation = annotationRepository.Create(annotation, submissionId, userId);

            // Assert
            Assert.Null(actualAnnotation);
        }
Example #8
0
        public void GetSoMemberbyId_InvalidArgument(int soMemberId)
        {
            // Arrange
            SOVAContext        databaseContext    = new SOVAContext(_connectionString);
            SoMemberRepository soMemberRepository = new SoMemberRepository(databaseContext);

            // Act
            SoMember soMember = soMemberRepository.GetSoMemberById(soMemberId);

            // Assert
            Assert.Null(soMember);
        }
Example #9
0
        public void GetNumberOfCommentsOnSubmission_InvalidArgument(int submissionId)
        {
            // Arrange
            SOVAContext       databaseContext   = new SOVAContext(_connectionString);
            CommentRepository commentRepository = new CommentRepository(databaseContext);

            // Act
            int numberOfComments = commentRepository.NoOfComments(submissionId);

            // Assert
            Assert.Equal(0, numberOfComments);
        }
Example #10
0
        public void GetAnswersByQuestionId_InvalidArguments(int questionId)
        {
            // Arrange
            SOVAContext      databaseContext  = new SOVAContext(_connectionString);
            AnswerRepository answerRepository = new AnswerRepository(databaseContext);

            // Act
            IEnumerable <Answer> answers = answerRepository.GetAnswersForQuestionById(questionId);

            // Assert
            Assert.Null(answers);
        }
Example #11
0
        public void GetQuestionById_InvalidArgument(int questionId)
        {
            // Arrange
            SOVAContext        databaseContext    = new SOVAContext(_connectionString);
            QuestionRepository questionRepository = new QuestionRepository(databaseContext);

            // Act
            Question question = questionRepository.GetById(questionId);

            // Assert
            Assert.Null(question);
        }
Example #12
0
        public void GetLinkPostByQuestionAndLinkedPostIds_InvalidArgument(int questionId)
        {
            // Arrange
            SOVAContext        databaseContext    = new SOVAContext(_connectionString);
            LinkPostRepository linkPostRepository = new LinkPostRepository(databaseContext);

            // Act
            var linkPosts = linkPostRepository.GetLinkedPostByQuestionId(questionId);

            // Assert
            Assert.All(linkPosts, Assert.Null);
        }
Example #13
0
        public void GetNumberOfBookmarkedSubmissions_InvalidArgument(int userId)
        {
            // Arrange
            SOVAContext       databaseContext   = new SOVAContext(_connectionString);
            MarkingRepository markingRepository = new MarkingRepository(databaseContext);

            // Act
            int bookmarkedSubmissions = markingRepository.NoOfMarkings(userId);

            // Assert
            Assert.Equal(0, bookmarkedSubmissions);
        }
Example #14
0
        public void DeleteBookmarkOnSubmissionForUser_InvalidArguments(int submissionId, int userId)
        {
            // Assert
            SOVAContext       databaseContext   = new SOVAContext(_connectionString);
            MarkingRepository markingRepository = new MarkingRepository(databaseContext);

            // Act
            bool bookmarked = markingRepository.RemoveBookmark(submissionId, userId);

            // Assert
            Assert.False(bookmarked);
        }
Example #15
0
        public void GetUserHistoryCountByUserId_InvalidArgument(int userId)
        {
            // Arrange
            SOVAContext           databaseContext       = new SOVAContext(_connectionString);
            UserHistoryRepository userHistoryRepository = new UserHistoryRepository(databaseContext);

            // Act
            int count = userHistoryRepository.NoOfUserHistory(userId);

            // Assert
            Assert.Equal(0, count);
        }
Example #16
0
        public void GetBookmarkBySubmissionAndUserIds_InvalidArguments(int submissionId, int userId)
        {
            // Arrange
            SOVAContext       databaseContext   = new SOVAContext(_connectionString);
            MarkingRepository markingRepository = new MarkingRepository(databaseContext);

            // Act
            bool bookmarked = markingRepository.IsMarked(submissionId, userId);

            // Assert
            Assert.False(bookmarked);
        }
Example #17
0
        public void GetNumberOfQuestionSearchResults_InvalidArguments_InvalidUser(string query, int?userId)
        {
            // Arrange
            SOVAContext        databaseContext    = new SOVAContext(_connectionString);
            QuestionRepository questionRepository = new QuestionRepository(databaseContext);

            // Act
            int resultCount = questionRepository.NoOfResults(query, userId);

            // Assert
            Assert.Equal(0, resultCount);
        }
Example #18
0
        public void GetAnnotationBySubmissionAndUserIds_InvalidArguments(int submissionId, int userId)
        {
            // Arrange
            SOVAContext          databaseContext      = new SOVAContext(_connectionString);
            AnnotationRepository annotationRepository = new AnnotationRepository(databaseContext);

            // Act
            Annotation actualAnnotation = annotationRepository.GetBySubmissionAndUserIds(submissionId, userId);

            // Assert
            Assert.Null(actualAnnotation);
        }
Example #19
0
        public void GetCommentsBySubmissionId_InvalidArguments(int submissionId)
        {
            // Arrange
            SOVAContext       databaseContext   = new SOVAContext(_connectionString);
            CommentRepository commentRepository = new CommentRepository(databaseContext);

            // Act
            IEnumerable <Comment> comments = commentRepository.GetAllCommentsBySubmissionId(submissionId);

            // Assert
            Assert.Empty(comments);
        }
Example #20
0
        public void GetNumberOfQuestionSearchResults_InvalidArguments_ValidUser(string query)
        {
            // Arrange
            SOVAContext        databaseContext    = new SOVAContext(_connectionString);
            QuestionRepository questionRepository = new QuestionRepository(databaseContext);
            var userId = EnsureTestUserExistsThroughContext_ReturnsTestUser().Id;

            // Act
            int resultCount = questionRepository.NoOfResults(query, userId);

            // Assert
            Assert.Equal(0, resultCount);
        }
Example #21
0
        public void GetUserHistoryCountByUserId_ValidArgument()
        {
            // Arrange
            SOVAContext           databaseContext       = new SOVAContext(_connectionString);
            UserHistoryRepository userHistoryRepository = new UserHistoryRepository(databaseContext);

            User testUser = EnsureTestUserExistsThroughContext_ReturnsTestUser();

            // Act
            int count = userHistoryRepository.NoOfUserHistory(testUser.Id);

            // Assert
            Assert.True(count > -1);
        }
Example #22
0
        public void GetQuestionById_ValidArgument()
        {
            // Arrange
            SOVAContext        databaseContext    = new SOVAContext(_connectionString);
            QuestionRepository questionRepository = new QuestionRepository(databaseContext);

            int questionId = 19;

            // Act
            Question question = questionRepository.GetById(questionId);

            // Assert
            Assert.Equal(questionId, question.SubmissionId);
        }
Example #23
0
        public void GetAnswersByQuestionId_ValidArguments()
        {
            // Arrange
            SOVAContext      databaseContext  = new SOVAContext(_connectionString);
            AnswerRepository answerRepository = new AnswerRepository(databaseContext);

            int questionId = 19;

            // Act
            IEnumerable <Answer> answers = answerRepository.GetAnswersForQuestionById(questionId);

            // Assert
            Assert.All(answers, (answer) => Assert.Equal(questionId, answer.ParentId));
        }
Example #24
0
        public void GetAnswerById_ValidArgument()
        {
            // Arrange
            SOVAContext      databaseContext  = new SOVAContext(_connectionString);
            AnswerRepository answerRepository = new AnswerRepository(databaseContext);

            int answerId = 106266;

            // Act
            Answer answer = answerRepository.GetAnswerById(answerId);

            // Assert
            Assert.Equal(answerId, answer.SubmissionId);
        }
Example #25
0
        public void GetCommentsBySubmissionId_ValidArguments(int submissionId, int pageNumber, int pageSize)
        {
            // Arrange
            SOVAContext       databaseContext   = new SOVAContext(_connectionString);
            CommentRepository commentRepository = new CommentRepository(databaseContext);

            IEnumerable <Comment> expectedComments = databaseContext.Comments.Where(comment => comment.SubmissionId == submissionId);

            // Act
            IEnumerable <Comment> actualComments = commentRepository.GetAllCommentsBySubmissionId(submissionId);

            // Assert
            Assert.Equal(expectedComments, actualComments);
        }
Example #26
0
        public void GetCommentsBySubmissionId_IncludeSubmissions()
        {
            // Arrange
            SOVAContext       databaseContext   = new SOVAContext(_connectionString);
            CommentRepository commentRepository = new CommentRepository(databaseContext);

            int submissionId = 19;

            // Act
            IEnumerable <Comment> comments = commentRepository.GetAllCommentsBySubmissionId(submissionId);

            // Arrange
            Assert.All(comments, (comment) => Assert.NotNull(comment.Submission));
        }
Example #27
0
        public void GetAnswerById_IncludesSubmissions()
        {
            // Arrange
            SOVAContext      databaseContext  = new SOVAContext(_connectionString);
            AnswerRepository answerRepository = new AnswerRepository(databaseContext);

            int answerId = 106266;

            // Act
            Answer answer = answerRepository.GetAnswerById(answerId);

            // Assert
            Assert.NotNull(answer.Submission);
        }
Example #28
0
        public void GetSoMemberById_ValidArgument()
        {
            // Arrange
            SOVAContext        databaseContext    = new SOVAContext(_connectionString);
            SoMemberRepository soMemberRepository = new SoMemberRepository(databaseContext);

            int    soMemberId   = 1;
            string soMemberName = "Jeff Atwood";

            // Act
            SoMember soMember = soMemberRepository.GetSoMemberById(soMemberId);

            // Assert
            Assert.Equal(soMemberName, soMember.DisplayName);
        }
Example #29
0
        public void GetNumberOfCommentsOnSubmission_ValidArgument()
        {
            // Arrange
            SOVAContext       databaseContext   = new SOVAContext(_connectionString);
            CommentRepository commentRepository = new CommentRepository(databaseContext);

            int submissionId             = 19;
            int expectedNumberOfComments = databaseContext.Comments.Count(comment => comment.SubmissionId == submissionId);

            // Act
            int actualNumberOfComments = commentRepository.NoOfComments(submissionId);

            // Assert
            Assert.Equal(expectedNumberOfComments, actualNumberOfComments);
        }
Example #30
0
        public void CheckAtMostOneAnnotationOnSubmissionForUser_CreateAnnotation(string annotation, int submissionId, int userId)
        {
            // Arrange
            SOVAContext          databaseContext      = new SOVAContext(_connectionString);
            AnnotationRepository annotationRepository = new AnnotationRepository(databaseContext);

            // Act
            annotationRepository.Create(annotation, submissionId, userId);

            // Assert
            annotationRepository.Delete(submissionId, userId);
            int annotationCount = databaseContext.Annotations.Where(annotation => annotation.UserId == userId && annotation.SubmissionId == submissionId).Count();

            Assert.True(annotationCount <= 1);
        }