public void GetCommentById_AddNewCommentThenRetrieveIt_ReturnsCommentNotNull() { // 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 now = DateTime.Now; var comment = new CommentTO { Incident = addedIncident, Message = "I got in touch with the right people, it'll get fixed soon!", SubmitDate = now, UserId = 1 }; var addedComment = commentRepository.Add(comment); context.SaveChanges(); // Act var result = commentRepository.GetById(addedComment.Id); // Assert Assert.IsNotNull(result); Assert.AreEqual("I got in touch with the right people, it'll get fixed soon!", result.Message); Assert.AreEqual(now, result.SubmitDate); }
public List <RoomTO> GetRoomsByFloors(FloorTO Floor) { throw new System.NotImplementedException(); }
public void Update_AddANewIncidentThenChangeStatusAndDescription_ReturnUpdatedIncident() { //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", Room = addedRoom, Issue = addedIssue, Status = IncidentStatus.Waiting, SubmitDate = DateTime.Now, UserId = 1, }; var addedIncident = incidentRepository.Add(incident); context.SaveChanges(); //Change Incident's Status and Description addedIncident.Status = IncidentStatus.Resolved; addedIncident.Description = "No coffee, nor water !"; //ACT var updatedIncident = incidentRepository.Update(addedIncident); //ASSERT Assert.IsNotNull(updatedIncident); Assert.AreEqual("No coffee, nor water !", updatedIncident.Description); Assert.AreEqual(IncidentStatus.Resolved, updatedIncident.Status); }
public FloorTO Update(FloorTO Entity) { throw new System.NotImplementedException(); }
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 bool Remove(FloorTO entity) { throw new System.NotImplementedException(); }
public void GetUserIncidents_AddThreeIncidentsWithSameUserId_ThenRetrieveThem_ReturnsCorrectNumberOfIncidents() { // Arrange var userId = 1; var floor = new FloorTO { Number = 2 }; var room = new RoomTO { Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = floor }; var componentType = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Name1EN", "Name1FR", "Name1NL") }; var issue = new IssueTO { Description = "Broken thing", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = componentType }; var incident1 = new IncidentTO { Description = "This thing is broken !", Room = room, Issue = issue, Status = IncidentStatus.Waiting, SubmitDate = DateTime.Now, UserId = userId, }; var incident2 = new IncidentTO { Description = "This thing is still broken !", Room = room, Issue = issue, Status = IncidentStatus.Waiting, SubmitDate = DateTime.Now.AddDays(7), UserId = userId, }; var incident3 = new IncidentTO { Description = "This hasn't been fixed yet ?!", Room = room, Issue = issue, Status = IncidentStatus.Waiting, SubmitDate = DateTime.Now.AddDays(14), UserId = userId, }; var incidents = new List <IncidentTO> { incident1, incident2, incident3 }; var mockUnitOfWork = new Mock <IFSUnitOfWork>(); mockUnitOfWork.Setup(uow => uow.IncidentRepository.Add(It.IsAny <IncidentTO>())).Returns(new IncidentTO()); mockUnitOfWork.Setup(uow => uow.IncidentRepository.GetIncidentsByUserId(It.Is <int>(i => i > 0))).Returns(incidents); var sut = new FSAttendeeRole(mockUnitOfWork.Object); // Act sut.CreateIncident(incident1); sut.CreateIncident(incident2); sut.CreateIncident(incident3); var userIncidents = sut.GetUserIncidents(userId); // Assert mockUnitOfWork.Verify(u => u.IncidentRepository.Add(It.IsAny <IncidentTO>()), Times.Exactly(3)); Assert.AreEqual(3, userIncidents.Count()); }
public bool Remove(FloorTO entity) => Remove(entity.Id);
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); }