public void UpdateIssueByTransfertObject_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();
                f2.Description = "PASProut";
                issueRepository.Update(f2);

                Assert.AreEqual(2, issueRepository.GetAll().Count());
                Assert.AreEqual("PASProut", f2.Description);
            }
        }
示例#2
0
        public IssueTO Add(IssueTO Entity)
        {
            if (Entity is null)
            {
                throw new ArgumentNullException(nameof(Entity));
            }

            var issue = Entity.ToEF();

            return(issuesContext.Issues.Add(issue).Entity.ToTransfertObject());
        }
示例#3
0
        public IssueTO Update(IssueTO Entity)
        {
            if (Entity is null)
            {
                throw new ArgumentNullException(nameof(Entity));
            }

            return(issuesContext
                   .Issues
                   .Update(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));
        }
示例#5
0
        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
            });
        }
示例#6
0
        public IssueTO Add(IssueTO Entity)
        {
            if (Entity is null)
            {
                throw new ArgumentNullException(nameof(Entity));
            }

            var issueEF = Entity.ToEF();

            issueEF.ComponentType = facilityContext.ComponentTypes.First(x => x.Id == Entity.ComponentType.Id);
            issueEF.ComponentType = issueEF.ComponentType.UpdateFromDetached(Entity.ComponentType.ToEF());

            return(facilityContext.Issues.Add(issueEF).Entity.ToTransfertObject());
        }
示例#7
0
        public IssueTO UpdateIssue(IssueTO issueToUpdate)
        {
            if (issueToUpdate is null)
            {
                throw new ArgumentNullException("The Issue object cannot be null !");
            }

            if (issueToUpdate.Id <= 0)
            {
                throw new LoggedException("The Issue object cannot be updated without it's ID");
            }

            return(unitOfWork.IssueRepository.Update(issueToUpdate));
        }
        public static IssueEF ToEF(this IssueTO Issue)
        {
            if (Issue is null)
            {
                throw new ArgumentNullException(nameof(Issue));
            }

            return(new IssueEF
            {
                Id = Issue.Id,
                NameEnglish = Issue.Name.English,
                NameFrench = Issue.Name.French,
                NameDutch = Issue.Name.Dutch
            });
        }
        public void UpdateIssueByTransfertObject_ThrowException_WhenUnexistingIssueIsSupplied()
        {
            //ARRANGE
            var options = new DbContextOptionsBuilder <FacilityContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var memoryCtx = new FacilityContext(options);
            var issueRepository = new IssueRepository(memoryCtx);
            var issue           = new IssueTO {
                Id = 999
            };

            //ACT & ASSERT
            Assert.ThrowsException <LoggedException>(() => issueRepository.Update(issue));
        }
示例#10
0
        public static Issue ToDomain(this IssueTO IssueTO)
        {
            if (IssueTO is null)
            {
                throw new NullIssueException(nameof(IssueTO));
            }

            return(new Issue(IssueTO.Name)
            {
                Id = IssueTO.Id,
                Description = IssueTO.Description,
                Archived = IssueTO.Archived,
                ComponentType = IssueTO.ComponentType.ToDomain(),
                Name = IssueTO.Name,
            });
        }
示例#11
0
        public IssueTO Update(IssueTO Entity)
        {
            if (!facilityContext.Issues.Any(x => x.Id == Entity.Id && x.Archived != true))
            {
                throw new LoggedException($"IssueRepository. Update(IssueTransfertObject) no record to update.");
            }

            var attachedIssues = facilityContext.Issues
                                 .FirstOrDefault(x => x.Id == Entity.Id && x.Archived != true);

            if (attachedIssues != default)
            {
                attachedIssues.UpdateFromDetached(Entity.ToEF());
            }

            return(facilityContext.Issues.Update(attachedIssues).Entity.ToTransfertObject());
        }
示例#12
0
        public static IssueEF ToEF(this IssueTO Issue)
        {
            if (Issue is null)
            {
                throw new NullIssueException(nameof(Issue));
            }

            return(new IssueEF
            {
                Id = Issue.Id,
                NameEnglish = Issue.Name.English,
                NameFrench = Issue.Name.French,
                NameDutch = Issue.Name.Dutch,
                ComponentType = Issue.ComponentType.ToEF(),
                Archived = Issue.Archived,
                Description = Issue.Description,
            });
        }
        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 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));
            }
        }
        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);
        }
示例#16
0
        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);
        }
示例#17
0
        public static IssueEF ToEF(this IssueTO issue)
        {
            if (issue is null)
            {
                throw new ArgumentNullException(nameof(issue));
            }

            return(new IssueEF
            {
                IssueId = issue.IssueId,
                Creator = issue.Creator,
                Resolver = issue.Resolver,
                Priority = issue.Priority,
                Name = issue.Name,
                DeadLine = issue.DeadLine,
                IsCompleted = issue.IsCompleted,
                IsSoftDeleted = issue.IsSoftDeleted,
                Location = issue.Location,
                Sector = issue.Sector,
                Description = issue.Description
            });
        }
        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);
            }
        }
示例#19
0
        public void CreateIncident_IncompleteIncident_ThrowsException()
        {
            // Arrange
            var incident1 = new IncidentTO(); // Missing Issue & Room

            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 incident2 = new IncidentTO {
                Issue = issue
            };                                                // Missing Room

            var floor = new FloorTO {
                Number = 2
            };
            var room = new RoomTO {
                Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = floor
            };
            var incident3 = new IncidentTO {
                Room = room
            };                                              // Missing Issue

            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(incident1));
            Assert.ThrowsException <LoggedException>(() => sut.CreateIncident(incident2));
            Assert.ThrowsException <LoggedException>(() => sut.CreateIncident(incident3));
            mockUnitOfWork.Verify(u => u.CommentRepository.Add(It.IsAny <CommentTO>()), Times.Never);
        }
示例#20
0
        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());
        }
示例#21
0
 public IssueTO Update(IssueTO Entity)
 {
     throw new System.NotImplementedException();
 }
示例#22
0
 public bool Remove(IssueTO entity)
 {
     throw new System.NotImplementedException();
 }
示例#23
0
        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());
        }
示例#24
0
        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());
        }
示例#25
0
        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 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);
        }
示例#27
0
        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 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);
        }
示例#29
0
文件: User.cs 项目: dkvz/Permackathon
 //Implementing Methods
 public IssueTO AddIssue(IssueTO Issue)
 => unitOfWork.IssuesRepository.Add(Issue);