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