public void AddFormReturnsCorrectNumberOfForm() { var options = new DbContextOptionsBuilder <EvaluationContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using (var memoryContext = new EvaluationContext(options)) { //Arrange ICommentRepository commentRepository = new CommentRepository(memoryContext); IFormRepository formRepository = new FormRepository(memoryContext); IResponseRepository responseRepository = new ResponseRepository(memoryContext); IQuestionRepository questionRepository = new QuestionRepository(memoryContext); ISubmissionRepository submissionRepository = new SubmissionRepository(memoryContext); IQuestionPropositionRepository questionPropositionRepository = new QuestionPropositionRepository(memoryContext); #region Form var Form1 = new FormTO { Name = new MultiLanguageString ( "Daily evaluation form", "Formulaire d'évaluation journalier", "Dagelijks evaluatieformulier" ), }; var formAdded1 = formRepository.Add(Form1); memoryContext.SaveChanges(); #endregion #region Questions var Question1 = new QuestionTO { Form = formAdded1, Position = 1, Libelle = new MultiLanguageString ( "What is your general impression after this first day of training ?", "Quelle est votre impression générale après cette première journée de formation ?", "Wat is je algemene indruk na deze eerste dag van training ?" ), Type = QuestionType.SingleChoice, }; var Question2 = new QuestionTO { Form = formAdded1, Position = 2, Libelle = new MultiLanguageString ( "Is the pace right for you ?", "Est-ce que le rythme vous convient ?", "Is het tempo geschikt voor u ?" ), Type = QuestionType.SingleChoice, }; var Question3 = new QuestionTO { Form = formAdded1, Position = 3, Libelle = new MultiLanguageString ( "Do you have questions related to the subject studied today ?", "Avez-vous des questions relatives à la matière étudiée aujourd’hui ?", "Heb je vragen over het onderwerp dat vandaag is bestudeerd ?" ), Type = QuestionType.Open }; var Question4 = new QuestionTO { Form = formAdded1, Position = 4, Libelle = new MultiLanguageString ( "Do you have specific questions / particular topics that you would like deepen during this training ?", "Avez-vous des questions spécifiques/sujets particuliers que vous aimeriez approfondir durant cette formation ?", "Heeft u specifieke vragen / specifieke onderwerpen die u graag zou willen verdiepen tijdens deze training ?" ), Type = QuestionType.Open }; var Question5 = new QuestionTO { Form = formAdded1, Position = 5, Libelle = new MultiLanguageString ( "What objectives do you pursue by following this training ?", "Quels objectifs poursuivez-vous en suivant cette formation ?", "Welke doelstellingen streeft u na door deze training te volgen?" ), Type = QuestionType.Open }; var questionAdded1 = questionRepository.Add(Question1); var questionAdded2 = questionRepository.Add(Question2); var questionAdded3 = questionRepository.Add(Question3); var questionAdded4 = questionRepository.Add(Question4); var questionAdded5 = questionRepository.Add(Question5); memoryContext.SaveChanges(); #endregion #region QuestionProposition var QuestionProposition1 = new QuestionPropositionTO { Question = questionAdded1, Libelle = new MultiLanguageString("good", "bonne", "goed"), Position = 1 }; var QuestionProposition2 = new QuestionPropositionTO { Question = questionAdded1, Libelle = new MultiLanguageString("medium", "moyenne", "gemiddelde"), Position = 2 }; var QuestionProposition3 = new QuestionPropositionTO { Question = questionAdded1, Libelle = new MultiLanguageString("bad", "mauvaise", "slecht"), Position = 3 }; var QuestionProposition4 = new QuestionPropositionTO { Question = questionAdded2, Libelle = new MultiLanguageString("yes", "oui", "ja"), Position = 1 }; var QuestionProposition5 = new QuestionPropositionTO { Question = questionAdded2, Libelle = new MultiLanguageString("too fast", "trop rapide", "te snel"), Position = 2 }; var QuestionProposition6 = new QuestionPropositionTO { Question = questionAdded2, Libelle = new MultiLanguageString("too slow", "trop lent", "te langzaam"), Position = 3 }; var questionPropositionAdded1 = questionPropositionRepository.Add(QuestionProposition1); var questionPropositionAdded2 = questionPropositionRepository.Add(QuestionProposition2); var questionPropositionAdded3 = questionPropositionRepository.Add(QuestionProposition3); var questionPropositionAdded4 = questionPropositionRepository.Add(QuestionProposition4); var questionPropositionAdded5 = questionPropositionRepository.Add(QuestionProposition5); var questionPropositionAdded6 = questionPropositionRepository.Add(QuestionProposition6); memoryContext.SaveChanges(); #endregion #region Submission var submission1 = new SubmissionTO { SessionId = 30, AttendeeId = 1012, Date = DateTime.Today, }; var submission2 = new SubmissionTO { SessionId = 31, AttendeeId = 2607, Date = DateTime.Today, }; var submission3 = new SubmissionTO { SessionId = 2, AttendeeId = 1612, Date = DateTime.Today, }; var submissionAdded1 = submissionRepository.Add(submission1); var submissionAdded2 = submissionRepository.Add(submission2); var submissionAdded3 = submissionRepository.Add(submission3); memoryContext.SaveChanges(); #endregion #region Responses var response1 = new ResponseTO { Question = questionAdded1, Submission = submissionAdded1, QuestionProposition = questionPropositionAdded1, }; var response2 = new ResponseTO { Question = questionAdded2, Submission = submissionAdded2, QuestionProposition = questionPropositionAdded2, }; var response3 = new ResponseTO { Question = questionAdded3, Submission = submissionAdded3, Text = "Ceci est une réponse à une question ouverte", //QuestionProposition = QuestionProposition3, }; var response4 = new ResponseTO { Question = questionAdded4, Submission = submissionAdded1, Text = "Ceci est une réponse à une question ouverte", }; //Assert var responseAdded1 = responseRepository.Add(response1); var responseAdded2 = responseRepository.Add(response2); var responseAdded3 = responseRepository.Add(response3); var responseAdded4 = responseRepository.Add(response4); memoryContext.SaveChanges(); #endregion #region Comment var comment1 = new CommentTO { Response = responseAdded1, Content = "ceci est un commentaire" }; var comment2 = new CommentTO { Response = responseAdded2, Content = "ceci est un commentaire" }; var commentAdded1 = commentRepository.Add(comment1); var commentAdded2 = commentRepository.Add(comment2); memoryContext.SaveChanges(); #endregion //Act var result = commentRepository.GetById(commentAdded1.Id); //Assert Assert.AreEqual("ceci est un commentaire", result.Content); } }
public void GetCommentsByIncidentId_AddMultipleComments_ReturnRelevantComments() { // Arrange var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FacilityContext(options); ICommentRepository commentRepository = new CommentRepository(context); IIncidentRepository incidentRepository = new IncidentRepository(context); IRoomRepository roomRepository = new RoomRepository(context); IFloorRepository floorRepository = new FloorRepository(context); IComponentTypeRepository componentTypeRepository = new ComponentTypeRepository(context); IIssueRepository issueRepository = new IssueRepository(context); var floor = new FloorTO { Number = 2 }; var addedFloor = floorRepository.Add(floor); context.SaveChanges(); RoomTO room = new RoomTO { Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor }; var addedRoom = roomRepository.Add(room); context.SaveChanges(); var componentType = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1EN", "Name1FR", "Name1NL") }; var addedComponentType = componentTypeRepository.Add(componentType); context.SaveChanges(); var issue = new IssueTO { Description = "Broken thing", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = addedComponentType }; var addedIssue = issueRepository.Add(issue); context.SaveChanges(); var incident1 = new IncidentTO { Description = "This thing is broken!", Room = addedRoom, Issue = addedIssue, Status = IncidentStatus.Waiting, SubmitDate = DateTime.Now, UserId = 1, }; var incident2 = new IncidentTO { Description = "This thing is still broken after a week!", Room = addedRoom, Issue = addedIssue, Status = IncidentStatus.Waiting, SubmitDate = DateTime.Now.AddDays(7), UserId = 1, }; var addedIncident1 = incidentRepository.Add(incident1); var addedIncident2 = incidentRepository.Add(incident2); context.SaveChanges(); var comment1 = new CommentTO { Incident = addedIncident1, Message = "I got in touch with the right people, it'll get fixed soon!", SubmitDate = DateTime.Now, UserId = 2 }; var comment2 = new CommentTO { Incident = addedIncident1, Message = "New ETA is Monday morning.", SubmitDate = DateTime.Now.AddDays(1), UserId = 2 }; var comment3 = new CommentTO { Incident = addedIncident2, Message = "It should be fixed very soon, sorry for the inconvenience!", SubmitDate = DateTime.Now.AddDays(8), UserId = 2 }; commentRepository.Add(comment1); commentRepository.Add(comment2); commentRepository.Add(comment3); context.SaveChanges(); // Act var result1 = commentRepository.GetCommentsByIncident(addedIncident1.Id); var result2 = commentRepository.GetCommentsByIncident(addedIncident2.Id); // Assert Assert.IsNotNull(result1); Assert.IsNotNull(result2); Assert.AreEqual(2, result1.Count); Assert.AreEqual(1, result2.Count); }
public void UpdateComment_AddNewCommentThenUpdateIt_ReturnsUpdatedComment() { // Arrange var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FacilityContext(options); ICommentRepository commentRepository = new CommentRepository(context); IIncidentRepository incidentRepository = new IncidentRepository(context); IRoomRepository roomRepository = new RoomRepository(context); IFloorRepository floorRepository = new FloorRepository(context); IComponentTypeRepository componentTypeRepository = new ComponentTypeRepository(context); IIssueRepository issueRepository = new IssueRepository(context); var floor = new FloorTO { Number = 2 }; var addedFloor = floorRepository.Add(floor); context.SaveChanges(); RoomTO room = new RoomTO { Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor }; var addedRoom = roomRepository.Add(room); context.SaveChanges(); var componentType = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1EN", "Name1FR", "Name1NL") }; var addedComponentType = componentTypeRepository.Add(componentType); context.SaveChanges(); var issue = new IssueTO { Description = "Broken thing", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = addedComponentType }; var addedIssue = issueRepository.Add(issue); context.SaveChanges(); var incident = new IncidentTO { Description = "This thing is broken !", Room = addedRoom, Issue = addedIssue, Status = IncidentStatus.Waiting, SubmitDate = DateTime.Now, UserId = 1, }; var addedIncident = incidentRepository.Add(incident); context.SaveChanges(); var comment = new CommentTO { Incident = addedIncident, Message = "I got in touch with the right people, it'll get fixed soon!", SubmitDate = DateTime.Now, UserId = 1 }; var commentAdded = commentRepository.Add(comment); context.SaveChanges(); // Act var later = DateTime.Now.AddHours(2); commentAdded.Message = "Updated message"; commentAdded.SubmitDate = later; var result = commentRepository.Update(commentAdded); context.SaveChanges(); // Assert Assert.IsNotNull(result); Assert.AreEqual("Updated message", result.Message); Assert.AreEqual(later, result.SubmitDate); }
public void RemoveCommentById_AddNewCommentThenRemoveIt_ReturnsTrue() { // Arrange var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FacilityContext(options); ICommentRepository commentRepository = new CommentRepository(context); IIncidentRepository incidentRepository = new IncidentRepository(context); IRoomRepository roomRepository = new RoomRepository(context); IFloorRepository floorRepository = new FloorRepository(context); IComponentTypeRepository componentTypeRepository = new ComponentTypeRepository(context); IIssueRepository issueRepository = new IssueRepository(context); var floor = new FloorTO { Number = 2 }; var addedFloor = floorRepository.Add(floor); context.SaveChanges(); RoomTO room = new RoomTO { Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor }; var addedRoom = roomRepository.Add(room); context.SaveChanges(); var componentType = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1EN", "Name1FR", "Name1NL") }; var addedComponentType = componentTypeRepository.Add(componentType); context.SaveChanges(); var issue = new IssueTO { Description = "Broken thing", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = addedComponentType }; var addedIssue = issueRepository.Add(issue); context.SaveChanges(); var incident = new IncidentTO { Description = "This thing is broken !", Room = addedRoom, Issue = addedIssue, Status = IncidentStatus.Waiting, SubmitDate = DateTime.Now, UserId = 1, }; var addedIncident = incidentRepository.Add(incident); context.SaveChanges(); var comment = new CommentTO { Incident = addedIncident, Message = "I got in touch with the right people, it'll get fixed soon!", SubmitDate = DateTime.Now, UserId = 1 }; var addedComment = commentRepository.Add(comment); context.SaveChanges(); // Act var result = commentRepository.Remove(addedComment.Id); context.SaveChanges(); // Assert Assert.IsTrue(result); Assert.ThrowsException <KeyNotFoundException>(() => commentRepository.GetById(addedComment.Id)); }
public void GetAll_AddThreeComments_ReturnsCorrectNumberOfComments() { // Arrange var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FacilityContext(options); ICommentRepository commentRepository = new CommentRepository(context); IIncidentRepository incidentRepository = new IncidentRepository(context); IRoomRepository roomRepository = new RoomRepository(context); IFloorRepository floorRepository = new FloorRepository(context); IComponentTypeRepository componentTypeRepository = new ComponentTypeRepository(context); IIssueRepository issueRepository = new IssueRepository(context); var floor = new FloorTO { Number = 2 }; var addedFloor = floorRepository.Add(floor); context.SaveChanges(); RoomTO room = new RoomTO { Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor }; var addedRoom = roomRepository.Add(room); context.SaveChanges(); var componentType = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1EN", "Name1FR", "Name1NL") }; var addedComponentType = componentTypeRepository.Add(componentType); context.SaveChanges(); var issue = new IssueTO { Description = "Broken thing", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = addedComponentType }; var addedIssue = issueRepository.Add(issue); context.SaveChanges(); var incident = new IncidentTO { Description = "This thing is broken !", Room = addedRoom, Issue = addedIssue, Status = IncidentStatus.Waiting, SubmitDate = DateTime.Now, UserId = 1, }; var addedIncident = incidentRepository.Add(incident); context.SaveChanges(); var comment1 = new CommentTO { Incident = addedIncident, Message = "I got in touch with the right people, it'll get fixed soon!", SubmitDate = DateTime.Now, UserId = 2 }; var comment2 = new CommentTO { Incident = addedIncident, Message = "New ETA is Monday morning.", SubmitDate = DateTime.Now.AddDays(1), UserId = 2 }; var comment3 = new CommentTO { Incident = addedIncident, Message = "Postponed to Tuesday morning.", SubmitDate = DateTime.Now.AddDays(2), UserId = 2 }; commentRepository.Add(comment1); commentRepository.Add(comment2); commentRepository.Add(comment3); context.SaveChanges(); // Act var result = commentRepository.GetAll(); // Assert Assert.IsNotNull(result); Assert.AreEqual(3, result.Count()); }