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); }
// "id" is project ID public object Post(int id, AddIssueArgs args, IFile attachment = null) { return(ExecuteInUnitOfWork(() => { Project p = ProjectRepository.Get(id); Issue i = new Issue(p, args.Title, args.Description, args.Severity); IssueRepository.Add(i); if (args.Attachment != null && attachment != null) { using (Stream s = attachment.OpenStream()) { byte[] content = s.ReadAllBytes(); Attachment att = new Attachment(i, args.Attachment.Title, args.Attachment.Description, content, attachment.ContentType.MediaType); AttachmentRepository.Add(att); } } Uri issueUrl = typeof(IssueResource).CreateUri(new { id = i.Id }); return new OperationResult.Created { RedirectLocation = issueUrl }; })); }
public void AddReturnsId() { var repository = new IssueRepository(dbFactory, personRepository); var response = repository.Add(new Issue()); Assert.IsNotNull(response); Assert.AreEqual(response.Id, 1); }
public Issue PostIssue([FromBody] Issue issue, int workItemId) { try { var newIssue = _issueRepository.Add(issue); newIssue.WorkItem = _workItemRepository.AddIssue(newIssue.Id, workItemId); return(newIssue); } catch (Exception e) { throw new Exception(e.Message); } }
public void AddPersists() { var repository = new IssueRepository(dbFactory, personRepository); repository.Add(new Issue { Title = "Test Item" }); dbFactory.Run(db => { var response = db.Select<Issue>(); Assert.AreEqual(response.Count, 1); Assert.AreEqual(response[0].Title, "Test Item"); }); }
private int Create() { // Arrange Issue issue = new Issue() { ShortDescription = DESCRIPTION, LongDescription = DESCRIPTION, Title = TITLE, IsStateIssue = ISSTATEISSUE }; // Act _repo.Add(issue); // Assert Assert.IsNotNull(issue.Id, "Issue ID is Null"); return(issue.Id); }
public void AddIssues_ThrowsException_WhenANonExistingIdIsProvided() { var options = new DbContextOptionsBuilder <FacilityContext>() .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name) .Options; using (var memoryCtx = new FacilityContext(options)) { var IssueToUseInTest = new IssueTO { Description = "prout", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL") }; var issueRepository = new IssueRepository(memoryCtx); Assert.ThrowsException <ArgumentNullException>(() => issueRepository.Add(null)); } }
private void AddNewIssue(object sender, EventArgs e) { var newPriority = (Priority)NewPriority.SelectedValue; var newAssignee = (Account)NewAssignee.SelectedValue; if (newPriority == null) { MessageBox.Show("Należy wybrać priorytet zadania.", "Priorytet", MessageBoxButton.OK, MessageBoxImage.Error); } else if (newAssignee == null) { MessageBox.Show("Należy wybrać osobę przypisaną do zadania.", "Przypisanie", MessageBoxButton.OK, MessageBoxImage.Error); } else if (NewDescription.Text.Length < 3 || NewDescription.Text == null) { MessageBox.Show("Opis musi mieć przynajmniej 3 znaki.", "Opis", MessageBoxButton.OK, MessageBoxImage.Error); } else if (NewTitle.Text.Length < 3 || NewTitle.Text == null) { MessageBox.Show("Tytuł musi mieć przynajmniej 3 znaki.", "Tytuł", MessageBoxButton.OK, MessageBoxImage.Error); } else { var newIssue = new Issue { GroupID = group.GroupID, AssigneeID = newAssignee.AccountID, Description = NewDescription.Text, Title = NewTitle.Text, PriorityID = newPriority.PriorityID, StatusID = 1, }; issueRepository.Add(newIssue); RefreshGroupOwner(); NewTitle.Text = ""; NewDescription.Text = ""; MessageBox.Show("Pomyślnie dodano zadanie", "Dodawanie zadania", MessageBoxButton.OK, MessageBoxImage.Information); } }
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 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_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); }