public void GetAllComponentTypes_Successfull() { var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using (var memoryCtx = new FacilityContext(options)) { var ComponentTypeToUseInTest1 = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1En", "Name1Fr", "Name1Nl"), }; var ComponentTypeToUseInTest2 = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name2En", "Name2Fr", "Name2Nl"), }; var ComponentTypeToUseInTest3 = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name3En", "Name3Fr", "Name3Nl"), }; var componentTypeRepository = new ComponentTypeRepository(memoryCtx); componentTypeRepository.Add(ComponentTypeToUseInTest1); componentTypeRepository.Add(ComponentTypeToUseInTest2); componentTypeRepository.Add(ComponentTypeToUseInTest3); memoryCtx.SaveChanges(); Assert.AreEqual(3, componentTypeRepository.GetAll().Count()); } }
public void RemoveComponentTypeById_ThrowException_WhenDeletingANonExistantComponentType() { var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using (var memoryCtx = new FacilityContext(options)) { var ComponentTypeToUseInTest1 = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1En", "Name1Fr", "Name1Nl"), }; var ComponentTypeToUseInTest2 = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name2En", "Name2Fr", "Name2Nl"), }; var ComponentTypeToUseInTest3 = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name3En", "Name3Fr", "Name3Nl"), }; var componentTypeRepository = new ComponentTypeRepository(memoryCtx); componentTypeRepository.Add(ComponentTypeToUseInTest1); componentTypeRepository.Add(ComponentTypeToUseInTest2); memoryCtx.SaveChanges(); Assert.ThrowsException <LoggedException>(() => componentTypeRepository.Remove(3)); } }
public void GetComponentTypeById_Successfull() { var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using (var memoryCtx = new FacilityContext(options)) { var ComponentTypeToUseInTest = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1En", "Name1Fr", "Name1Nl"), }; var ComponentTypeToUseInTest2 = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name2En", "Name2Fr", "Name2Nl"), }; var componentTypeRepository = new ComponentTypeRepository(memoryCtx); componentTypeRepository.Add(ComponentTypeToUseInTest); componentTypeRepository.Add(ComponentTypeToUseInTest2); memoryCtx.SaveChanges(); var ComponentTypeToAssert = componentTypeRepository.GetById(2); Assert.AreEqual(2, ComponentTypeToAssert.Id); Assert.AreEqual("Name2Fr", ComponentTypeToAssert.Name.French); } }
public void UpdateComponentTypeByTransfertObject_Successfull() { var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using (var memoryCtx = new FacilityContext(options)) { var ComponentTypeToUseInTest = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1En", "Name1Fr", "Name1Nl"), }; var ComponentTypeToUseInTest2 = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name2En", "Name2Fr", "Name2Nl"), }; var componentTypeRepository = new ComponentTypeRepository(memoryCtx); var f1 = componentTypeRepository.Add(ComponentTypeToUseInTest); var f2 = componentTypeRepository.Add(ComponentTypeToUseInTest2); memoryCtx.SaveChanges(); f2.Name.French = "UpdatedFrenchName"; f2.Archived = true; componentTypeRepository.Update(f2); Assert.AreEqual(2, componentTypeRepository.GetAll().Count()); Assert.AreEqual("UpdatedFrenchName", f2.Name.French); Assert.AreEqual(true, f2.Archived); } }
public void RemoveComponentTypeByTransfertObject_Successfull() { var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using (var memoryCtx = new FacilityContext(options)) { var ComponentTypeToUseInTest1 = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1En", "Name1Fr", "Name1Nl"), }; var ComponentTypeToUseInTest2 = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name2En", "Name2Fr", "Name2Nl"), }; var componentTypeRepository = new ComponentTypeRepository(memoryCtx); var f1 = componentTypeRepository.Add(ComponentTypeToUseInTest1); var f2 = componentTypeRepository.Add(ComponentTypeToUseInTest2); memoryCtx.SaveChanges(); componentTypeRepository.Remove(f2); memoryCtx.SaveChanges(); var retrievedComponentTypes = componentTypeRepository.GetAll(); Assert.AreEqual(1, retrievedComponentTypes.Count()); Assert.IsFalse(retrievedComponentTypes.Any(x => x.Id == 2)); } }
public void GetComponentTypeByRoom_Successfull() { var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FacilityContext(options); IRoomRepository roomRepository = new RoomRepository(context); IFloorRepository floorRepository = new FloorRepository(context); IComponentTypeRepository componentTypeRepository = new ComponentTypeRepository(context); //Room(and it's floor) var floor = new FloorTO { Number = 2 }; var addedFloor1 = floorRepository.Add(floor); context.SaveChanges(); //Component var componentType1 = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1En", "Name1Fr", "Name1Nl") }; var componentType2 = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name2En", "Name2Fr", "Name2Nl") }; var addedComponentType1 = componentTypeRepository.Add(componentType1); var addedComponentType2 = componentTypeRepository.Add(componentType2); context.SaveChanges(); //Floor var componentTypes1 = new List <ComponentTypeTO>() { componentType1, componentType2 }; var componentTypes2 = new List <ComponentTypeTO>() { componentType1 }; RoomTO room1 = new RoomTO { Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor1, ComponentTypes = componentTypes1 }; RoomTO room2 = new RoomTO { Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor1, ComponentTypes = componentTypes2 }; var addedRoom1 = roomRepository.Add(room1); var addedRoom2 = roomRepository.Add(room2); context.SaveChanges(); //ACT var result = componentTypeRepository.GetComponentTypesByRoom(addedRoom1.Id); var result2 = componentTypeRepository.GetComponentTypesByRoom(addedRoom2.Id); //ASSERT Assert.AreEqual(2, result.Count()); Assert.AreEqual(1, result2.Count()); }
public void RemoveIssueByTransfertObject_Successfull() { var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var memoryCtx = new FacilityContext(options); var componentTypeRepository = new ComponentTypeRepository(memoryCtx); var componentType = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1En", "Name1Fr", "Name1Nl"), }; var componentType2 = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name2En", "Name2Fr", "Name2Nl"), }; var addedComponentType1 = componentTypeRepository.Add(componentType); var addedComponentType2 = componentTypeRepository.Add(componentType2); memoryCtx.SaveChanges(); var IssueToUseInTest = new IssueTO { Description = "prout", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = addedComponentType1, }; var IssueToUseInTest2 = new IssueTO { Description = "proutprout", Name = new MultiLanguageString("Issue2EN", "Issue2FR", "Issue2NL"), ComponentType = addedComponentType1, }; var IssueToUseInTest3 = new IssueTO { Description = "proutproutprout", Name = new MultiLanguageString("Issue3EN", "Issue3FR", "Issue3NL"), ComponentType = addedComponentType2, }; var issueRepository = new IssueRepository(memoryCtx); var f1 = issueRepository.Add(IssueToUseInTest); var f2 = issueRepository.Add(IssueToUseInTest2); memoryCtx.SaveChanges(); issueRepository.Remove(f2); memoryCtx.SaveChanges(); var retrievedIssues = issueRepository.GetAll(); Assert.AreEqual(1, retrievedIssues.Count()); Assert.IsFalse(retrievedIssues.Any(x => x.Id == 2)); }
public void GetIssuesByComponentTypeId_ReturnCorrectNumberOfCorrespondingIssues() { //ARRANGE var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FacilityContext(options); var issueRepository = new IssueRepository(context); var componentTypeRepository = new ComponentTypeRepository(context); var componentType = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1En", "Name1Fr", "Name1Nl"), }; var componentType2 = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name2En", "Name2Fr", "Name2Nl"), }; var addedComponentType1 = componentTypeRepository.Add(componentType); var addedComponentType2 = componentTypeRepository.Add(componentType2); context.SaveChanges(); IssueTO issue1 = new IssueTO { Name = new MultiLanguageString("Issue1", "Issue1", "Issue1"), ComponentType = addedComponentType1, Description = "prout", }; IssueTO issue2 = new IssueTO { Name = new MultiLanguageString("Issue2", "Issue2", "Issue2"), ComponentType = addedComponentType1, Description = "proutprout", }; IssueTO issue3 = new IssueTO { Name = new MultiLanguageString("Issue3", "Issue3", "Issue3"), ComponentType = addedComponentType2, Description = "proutproutprout", }; issueRepository.Add(issue1); issueRepository.Add(issue2); issueRepository.Add(issue3); context.SaveChanges(); var retrievedIssues = issueRepository.GetIssuesByComponentType(addedComponentType1.Id); Assert.IsNotNull(retrievedIssues); Assert.AreEqual(2, retrievedIssues.Count); }
public void RemoveIssueByTransfertObject_ThrowException_WhenDeletingANonExistantIssue() { var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var memoryCtx = new FacilityContext(options); var componentTypeRepository = new ComponentTypeRepository(memoryCtx); var componentType = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1En", "Name1Fr", "Name1Nl"), }; var componentType2 = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name2En", "Name2Fr", "Name2Nl"), }; var addedComponentType1 = componentTypeRepository.Add(componentType); var addedComponentType2 = componentTypeRepository.Add(componentType2); memoryCtx.SaveChanges(); var IssueToUseInTest = new IssueTO { Description = "prout", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = addedComponentType1, }; var IssueToUseInTest2 = new IssueTO { Description = "proutprout", Name = new MultiLanguageString("Issue2EN", "Issue2FR", "Issue2NL"), ComponentType = addedComponentType1, }; var IssueToUseInTest3 = new IssueTO { Description = "proutproutprout", Name = new MultiLanguageString("Issue3EN", "Issue3FR", "Issue3NL"), ComponentType = addedComponentType2, }; var issueRepository = new IssueRepository(memoryCtx); issueRepository.Add(IssueToUseInTest); issueRepository.Add(IssueToUseInTest2); memoryCtx.SaveChanges(); Assert.ThrowsException <KeyNotFoundException>(() => issueRepository.Remove(IssueToUseInTest3)); }
public void RemoveById_AddANewIncidentThenRemoveIt_ReturnTrue() { //ARRANGE var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FacilityContext(options); 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); //Room(and it's floor) var floor = new FloorTO { Number = 2 }; var addedFloor1 = floorRepository.Add(floor); context.SaveChanges(); RoomTO room = new RoomTO { Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor1 }; var addedRoom = roomRepository.Add(room); context.SaveChanges(); //Component var componentType = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1En", "Name1Fr", "Name1Nl") }; var addedComponentType = componentTypeRepository.Add(componentType); context.SaveChanges(); //Issue var issue = new IssueTO { Description = "prout", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = addedComponentType }; var addedIssue = issueRepository.Add(issue); context.SaveChanges(); //Incident var incident = new IncidentTO { Description = "No coffee", Issue = addedIssue, Status = IncidentStatus.Waiting, SubmitDate = DateTime.Now, UserId = 1, Room = addedRoom }; var addedIncident = incidentRepository.Add(incident); context.SaveChanges(); //ACT var result = incidentRepository.Remove(addedIncident.Id); context.SaveChanges(); //ASSERT Assert.IsTrue(result); }
public void AddComponentType_ThrowsException_WhenANonExistingIdIsProvided() { var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using (var memoryCtx = new FacilityContext(options)) { var ComponentTypeToUseInTest = new ComponentTypeTO { }; var componentTypeRepository = new ComponentTypeRepository(memoryCtx); Assert.ThrowsException <ArgumentNullException>(() => componentTypeRepository.Add(null)); } }
public void AddIssue_Successfull() { var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using (var memoryCtx = new FacilityContext(options)) { var componentTypeRepository = new ComponentTypeRepository(memoryCtx); var componentType = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1En", "Name1Fr", "Name1Nl"), }; var addedComponentType1 = componentTypeRepository.Add(componentType); memoryCtx.SaveChanges(); var IssueToUseInTest = new IssueTO { Description = "prout", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = addedComponentType1, }; var issueRepository = new IssueRepository(memoryCtx); issueRepository.Add(IssueToUseInTest); memoryCtx.SaveChanges(); Assert.AreEqual(1, issueRepository.GetAll().Count()); var IssueToAssert = issueRepository.GetById(1); Assert.AreEqual(1, IssueToAssert.Id); Assert.AreEqual("prout", IssueToAssert.Description); } }
public void GetAll_AddThreeIncidents_ReturnCorrectNumberOfIncidents() { //ARRANGE var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using var context = new FacilityContext(options); 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); //Room(and it's floor) var floor = new FloorTO { Number = 2 }; var addedFloor1 = floorRepository.Add(floor); context.SaveChanges(); RoomTO room = new RoomTO { Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor1 }; var addedRoom = roomRepository.Add(room); context.SaveChanges(); //Component var componentType = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1En", "Name1Fr", "Name1Nl") }; var addedComponentType = componentTypeRepository.Add(componentType); context.SaveChanges(); //Issue var issue = new IssueTO { Description = "prout", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = addedComponentType }; var addedIssue = issueRepository.Add(issue); context.SaveChanges(); //Incidents var incident1 = new IncidentTO { Description = "No coffee", Issue = addedIssue, Status = IncidentStatus.Waiting, SubmitDate = DateTime.Now, UserId = 1, Room = addedRoom }; var incident2 = new IncidentTO { Description = "Technical issue", Issue = addedIssue, Status = IncidentStatus.Waiting, SubmitDate = DateTime.Now, UserId = 2, Room = addedRoom }; var incident3 = new IncidentTO { Description = "No sugar", Issue = addedIssue, Status = IncidentStatus.Waiting, SubmitDate = DateTime.Now, UserId = 1, Room = addedRoom }; incidentRepository.Add(incident1); incidentRepository.Add(incident2); incidentRepository.Add(incident3); context.SaveChanges(); //ACT var result = incidentRepository.GetAll(); //ASSERT Assert.IsNotNull(result); Assert.AreEqual(3, result.Count()); }
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 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()); }
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)); }