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 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 AddIssue_CorrectIssueGiven_ReturnReturnIssueNotNull() { //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") }; //Issue var issue1 = new IssueTO { Description = "Plus de café", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = componentType1 }; var issue2 = new IssueTO { Description = "Fuite d'eau", Name = new MultiLanguageString("Issue2EN", "Issue2FR", "Issue2NL"), ComponentType = componentType2 }; var issue3 = new IssueTO { Description = "Plus de PQ", Name = new MultiLanguageString("Issue3EN", "Issue3FR", "Issue3NL"), ComponentType = componentType2 }; //ARRANGE var mockUnitOfWork = new Mock <IFSUnitOfWork>(); mockUnitOfWork.Setup(u => u.IssueRepository.Add(It.IsAny <IssueTO>())) .Returns(issue1); var sut = new FSAssistantRole(mockUnitOfWork.Object); var addedissue = sut.AddIssue(issue1); //ASSERT mockUnitOfWork.Verify(u => u.IssueRepository.Add(It.IsAny <IssueTO>()), Times.Once); Assert.IsNotNull(addedissue); }
public void AddComponentType_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 componentTypeRepository = new ComponentTypeRepository(memoryCtx); componentTypeRepository.Add(ComponentTypeToUseInTest); memoryCtx.SaveChanges(); Assert.AreEqual(1, componentTypeRepository.GetAll().Count()); var ComponentTypeToAssert = componentTypeRepository.GetById(1); Assert.AreEqual(1, ComponentTypeToAssert.Id); Assert.AreEqual("Name1En", ComponentTypeToAssert.Name.English); } }
public void CreateIncident_InvalidStatus_ThrowsException() { // Arrange 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 incident = new IncidentTO { Description = "This thing is broken !", Room = room, Issue = issue, Status = IncidentStatus.Accepted, SubmitDate = DateTime.Now, UserId = 1, }; var mockUnitOfWork = new Mock <IFSUnitOfWork>(); mockUnitOfWork.Setup(uow => uow.IncidentRepository.Add(It.IsAny <IncidentTO>())); var sut = new FSAttendeeRole(mockUnitOfWork.Object); // Act & Assert Assert.ThrowsException <LoggedException>(() => sut.CreateIncident(incident)); mockUnitOfWork.Verify(u => u.CommentRepository.Add(It.IsAny <CommentTO>()), Times.Never); }
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 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 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 GetIssuesByComponentType_ReturnIssues() { var componentType1 = new ComponentTypeTO { Id = 1, Archived = false, Name = new MultiLanguageString("Name1En", "Name1Fr", "Name1Nl") }; var componentType2 = new ComponentTypeTO { Id = 2, Archived = false, Name = new MultiLanguageString("Name2En", "Name2Fr", "Name2Nl") }; //Issue var issues = new List <IssueTO> { new IssueTO { Id = 1, Archived = false, Description = "Plus de café", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = componentType1 }, new IssueTO { Id = 2, Archived = false, Description = "Fuite d'eau", Name = new MultiLanguageString("Issue2EN", "Issue2FR", "Issue2NL"), ComponentType = componentType2 }, new IssueTO { Id = 3, Archived = false, Description = "Plus de PQ", Name = new MultiLanguageString("Issue3EN", "Issue3FR", "Issue3NL"), ComponentType = componentType2 }, }; var mockUnitOfWork = new Mock <IFSUnitOfWork>(); mockUnitOfWork.Setup(u => u.IssueRepository.GetIssuesByComponentType(It.IsAny <int>())).Returns(issues); var sut = new FSAttendeeRole(mockUnitOfWork.Object); //ACT var listOfIssues = sut.GetIssuesByComponentType(1); //ASSERT mockUnitOfWork.Verify(u => u.IssueRepository.GetIssuesByComponentType(It.IsAny <int>()), Times.Once); Assert.AreEqual(3, listOfIssues.Count); }
public void RemoveComponentTypeById_ReturnTrue() { //ARRANGE var mockUnitOfWork = new Mock <IFSUnitOfWork>(); var componentTypes = new List <ComponentTypeTO> { new ComponentTypeTO { Id = 1, Archived = false, Name = new MultiLanguageString("Coffee machin", "Machine à café", "en deutch") }, new ComponentTypeTO { Id = 2, Archived = false, Name = new MultiLanguageString("PC", "Ordinanteur", "en deutch") } }; mockUnitOfWork.Setup(u => u.ComponentTypeRepository.Update(It.IsAny <ComponentTypeTO>())) .Returns(new ComponentTypeTO { Id = 1, Archived = false, Name = new MultiLanguageString("Coffee machin", "Machine à café", "en deutch") }); mockUnitOfWork.Setup(u => u.ComponentTypeRepository.GetAll()).Returns(componentTypes); var sut = new FSAssistantRole(mockUnitOfWork.Object); var componentType = new ComponentTypeTO { Id = 1, Archived = false, Name = new MultiLanguageString("Coffee machin", "Machine à café", "en deutch") }; //ACT var result = sut.RemoveComponentType(1); //ASSERT mockUnitOfWork.Verify(u => u.ComponentTypeRepository.Update(It.IsAny <ComponentTypeTO>()), Times.Once); Assert.IsTrue(result); }
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 ComponentTypeTO AddComponentType(ComponentTypeTO componentTypeToAdd) { if (componentTypeToAdd is null) { throw new ArgumentNullException(nameof(componentTypeToAdd)); } return(unitOfWork.ComponentTypeRepository.Add(componentTypeToAdd)); }
public bool Remove(ComponentTypeTO entity) { if (entity is null) { throw new ArgumentNullException(nameof(entity)); } return(Remove(entity.Id)); }
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 ComponentTypeTO Add(ComponentTypeTO Entity) { if (Entity is null) { throw new ArgumentNullException(nameof(Entity)); } return(facilityContext.ComponentTypes .Add(Entity.ToEF()) .Entity .ToTransfertObject()); }
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 List <IncidentTO> GetTestsListOfIncidents() { //Floor var floor1 = new FloorTO { Number = 2 }; var floor2 = new FloorTO { Number = -1 }; //Room RoomTO room1 = new RoomTO { Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = floor1 }; RoomTO room2 = new RoomTO { Name = new MultiLanguageString("Room2", "Room2", "Room2"), Floor = floor1 }; RoomTO room3 = new RoomTO { Name = new MultiLanguageString("Room3", "Room3", "Room3"), Floor = floor2 }; //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") }; //Issue var issue1 = new IssueTO { Description = "Plus de café", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = componentType1 }; var issue2 = new IssueTO { Description = "Fuite d'eau", Name = new MultiLanguageString("Issue2EN", "Issue2FR", "Issue2NL"), ComponentType = componentType2 }; var issue3 = new IssueTO { Description = "Plus de PQ", Name = new MultiLanguageString("Issue3EN", "Issue3FR", "Issue3NL"), ComponentType = componentType2 }; //Incidents var incident1 = new IncidentTO { Room = room1, Issue = issue1, Status = IncidentStatus.Accepted }; var incident2 = new IncidentTO { Room = room2, Issue = issue2, Status = IncidentStatus.Resolved }; var incident3 = new IncidentTO { Room = room3, Issue = issue2, Status = IncidentStatus.Accepted }; return(new List <IncidentTO> { incident1, incident2, incident3 }); }
public ComponentTypeTO UpdateComponentType(ComponentTypeTO componentTypeToUpdate) { if (componentTypeToUpdate is null) { throw new ArgumentNullException("The ComponentType object cannot be null !"); } if (componentTypeToUpdate.Id <= 0) { throw new LoggedException("The ComponentType object cannot be updated without it's ID"); } return(unitOfWork.ComponentTypeRepository.Update(componentTypeToUpdate)); }
public static ComponentType ToDomain(this ComponentTypeTO ComponentTypeTO) { if (ComponentTypeTO is null) { throw new NullComponentTypeException(nameof(ComponentTypeTO)); } return(new ComponentType() { Id = ComponentTypeTO.Id, Archived = ComponentTypeTO.Archived, Name = ComponentTypeTO.Name, }); }
public void GetComponentTypesByRoom_ReturnRooms() { //Floor var floor1 = new FloorTO { Number = 2 }; var floor2 = new FloorTO { Number = -1 }; //Room var rooms = new List <RoomTO> { new RoomTO { Id = 1, Archived = false, Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = floor1 }, new RoomTO { Id = 2, Archived = false, Name = new MultiLanguageString("Room2", "Room2", "Room2"), Floor = floor1 }, new RoomTO { Id = 3, Archived = false, Name = new MultiLanguageString("Room3", "Room3", "Room3"), Floor = floor2 } }; var componentTypes = new List <ComponentTypeTO> { new ComponentTypeTO { Id = 1, Archived = false, Name = new MultiLanguageString("Name1", "Name1", "Name1") }, new ComponentTypeTO { Id = 2, Archived = false, Name = new MultiLanguageString("Name2", "Name2", "Name2") }, new ComponentTypeTO { Id = 3, Archived = false, Name = new MultiLanguageString("Name3", "Name3", "Name3") }, }; //ARRANGE var mockUnitOfWork = new Mock <IFSUnitOfWork>(); mockUnitOfWork.Setup(u => u.ComponentTypeRepository.GetComponentTypesByRoom(It.IsAny <int>())) .Returns(componentTypes); var sut = new FSAttendeeRole(mockUnitOfWork.Object); var room = new ComponentTypeTO { Id = 1, Archived = false, Name = new MultiLanguageString("Name1", "Name1", "Name1") }; //ACT var result = sut.GetComponentTypesByRoom(room.Id); //ASSERT mockUnitOfWork.Verify(u => u.ComponentTypeRepository.GetComponentTypesByRoom(It.IsAny <int>()), Times.Once); Assert.IsNotNull(result); }
public void UpdateComponentTypeByTransfertObject_ThrowException_WhenUnexistingComponentTypeIsSupplied() { var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using (var memoryCtx = new FacilityContext(options)) { var componentTypeRepository = new ComponentTypeRepository(memoryCtx); var componentTypeTO = new ComponentTypeTO { Id = 999 }; Assert.ThrowsException <LoggedException>(() => componentTypeRepository.Update(componentTypeTO)); } }
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 static ComponentTypeEF ToEF(this ComponentTypeTO componentType) { if (componentType is null) { throw new NullComponentTypeException(nameof(componentType)); } var componentTypeEf = new ComponentTypeEF { Id = componentType.Id, NameEnglish = componentType.Name.English, NameFrench = componentType.Name.French, NameDutch = componentType.Name.Dutch, Archived = componentType.Archived, }; return(componentTypeEf); }
public void AddComment_ValidComment_ReturnsCommentNotNull() { // Arrange 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 incident = new IncidentTO { Description = "This thing is broken !", Room = room, Issue = issue, Status = IncidentStatus.Waiting, SubmitDate = DateTime.Now, UserId = 1, }; var comment = new CommentTO { Incident = incident, Message = "I got in touch with the right people, it'll get fixed soon!", SubmitDate = DateTime.Now, UserId = 1 }; var mockUnitOfWork = new Mock <IFSUnitOfWork>(); mockUnitOfWork.Setup(uow => uow.CommentRepository.Add(It.IsAny <CommentTO>())).Returns(comment); var sut = new FSAssistantRole(mockUnitOfWork.Object); // Act var addedComment = sut.AddComment(comment); // Assert Assert.IsNotNull(addedComment); mockUnitOfWork.Verify(u => u.CommentRepository.Add(It.IsAny <CommentTO>()), Times.Once); }
public void RemoveIssue_ReturnTrue() { //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") }; //Issue var issues = new List <IssueTO> { new IssueTO { Id = 1, Archived = false, Description = "Plus de café", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = componentType1 }, new IssueTO { Id = 2, Archived = false, Description = "Fuite d'eau", Name = new MultiLanguageString("Issue2EN", "Issue2FR", "Issue2NL"), ComponentType = componentType2 }, new IssueTO { Id = 3, Archived = false, Description = "Plus de PQ", Name = new MultiLanguageString("Issue3EN", "Issue3FR", "Issue3NL"), ComponentType = componentType2 }, }; var mockUnitOfWork = new Mock <IFSUnitOfWork>(); mockUnitOfWork.Setup(u => u.IssueRepository.Update(It.IsAny <IssueTO>())) .Returns(new IssueTO { Id = 1, Description = "Plus de café", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = componentType1 }); mockUnitOfWork.Setup(u => u.IssueRepository.GetAll()).Returns(issues); var sut = new FSAssistantRole(mockUnitOfWork.Object); var issue = new IssueTO { Id = 1, Description = "Plus de café", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = componentType1 }; //ACT var result = sut.RemoveIssue(1); //ASSERT mockUnitOfWork.Verify(u => u.IssueRepository.Update(It.IsAny <IssueTO>()), Times.Once); mockUnitOfWork.Verify(u => u.IssueRepository.GetById(It.IsAny <int>()), Times.Once); Assert.IsTrue(result); }
public void UpdateComponentType_ChangeComponentTypeArchivedProp_ReturnUpdatedComponentType() { //ARRANGE var mockUnitOfWork = new Mock <IFSUnitOfWork>(); mockUnitOfWork.Setup(u => u.ComponentTypeRepository.Update(It.IsAny <ComponentTypeTO>())) .Returns(new ComponentTypeTO { Id = 1, Archived = false, Name = new MultiLanguageString("Coffee machin", "Machine à café", "en deutch") }); var sut = new FSAssistantRole(mockUnitOfWork.Object); var componentType = new ComponentTypeTO { Id = 1, Archived = false, Name = new MultiLanguageString("Coffee machin", "Machine à café", "en deutch") }; //ACT var updatedComponentType = sut.UpdateComponentType(componentType); //ASSERT mockUnitOfWork.Verify(u => u.ComponentTypeRepository.Update(It.IsAny <ComponentTypeTO>()), Times.Once); Assert.IsNotNull(updatedComponentType); }
public void CreateIncident_ValidIncident_ReturnsIncidentNotNull() { // Arrange 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 incident = new IncidentTO { Description = "This thing is broken !", Room = room, Issue = issue, Status = IncidentStatus.Waiting, SubmitDate = DateTime.Now, UserId = 1, }; var mockUnitOfWork = new Mock <IFSUnitOfWork>(); mockUnitOfWork.Setup(uow => uow.IncidentRepository.Add(It.IsAny <IncidentTO>())).Returns((IncidentTO incident) => { incident.Id = 1; return(incident); }); var sut = new FSAttendeeRole(mockUnitOfWork.Object); // Act var result = sut.CreateIncident(incident); // Assert Assert.IsTrue(result); mockUnitOfWork.Verify(u => u.IncidentRepository.Add(It.IsAny <IncidentTO>()), Times.Once); }
public void AddComponentType_CorrectComponentType_ReturnComponentTypeNotNull() { //ARRANGE var mockUnitOfWork = new Mock <IFSUnitOfWork>(); mockUnitOfWork.Setup(u => u.ComponentTypeRepository.Add(It.IsAny <ComponentTypeTO>())) .Returns(new ComponentTypeTO { Id = 1, Archived = false, Name = new MultiLanguageString("Coffee machin", "Machine à café", "en deutch") }); var sut = new FSAssistantRole(mockUnitOfWork.Object); var componentType = new ComponentTypeTO { Archived = false, Name = new MultiLanguageString("Coffee machin", "Machine à café", "en deutch") }; //ACT var addedComponentType = sut.AddComponentType(componentType); //ASSERT mockUnitOfWork.Verify(u => u.ComponentTypeRepository.Add(It.IsAny <ComponentTypeTO>()), Times.Once); Assert.IsNotNull(addedComponentType); Assert.AreNotEqual(0, addedComponentType.Id); }
public ComponentTypeTO Update(ComponentTypeTO Entity) { if (Entity is null) { throw new ArgumentNullException(nameof(Entity)); } if (!facilityContext.ComponentTypes.Any(x => x.Id == Entity.Id && x.Archived != true)) { throw new LoggedException($"ComponentTypeRepository. Update(ComponentTypeTransfertObject) no record to update."); } var attachedComponentTypes = facilityContext.ComponentTypes .FirstOrDefault(x => x.Id == Entity.Id && x.Archived != true); if (attachedComponentTypes != default) { attachedComponentTypes.UpdateFromDetached(Entity.ToEF()); } return(facilityContext.ComponentTypes.Update(attachedComponentTypes).Entity.ToTransfertObject()); }