public FacilityController(FacilityContext facilityContext)
 {
     _db        = facilityContext;
     _converter = new ConverterEntityToView();
 }
Example #2
0
 public RoomRepository(FacilityContext facilityContext)
 {
     this.facilityContext = facilityContext;
 }
Example #3
0
 public FacilitiesAPIController(FacilityContext context)
 {
     _context = context;
 }
Example #4
0
 public AccommodationRepository(FacilityContext context, ISecurityContext securityContext)
 {
     this.context         = context;
     this.securityContext = securityContext;
 }
 public IncidentRepository(FacilityContext facilityContext)
 {
     this.facilityContext = facilityContext;
 }
Example #6
0
 public CommentRepository(FacilityContext facilityContext)
 {
     this.facilityContext = facilityContext;
 }
Example #7
0
 public IssueRepository(FacilityContext facilityContext)
 {
     this.facilityContext = facilityContext;
 }
        public void DefaultCTOR_Successful()
        {
            var context = new FacilityContext();

            Assert.IsNotNull(context);
        }
 public FacilityRepository(FacilityContext context, ISecurityContext securityContext)
 {
     this.context         = context;
     this.securityContext = securityContext;
 }
Example #10
0
 public FacilityController(FacilityContext context)
 {
     this._context = context;
 }
Example #11
0
 public FacilityQueryDataSource(FacilityContext context, ISecurityContext securityContext)
 {
     this.context         = context;
     this.securityContext = securityContext;
 }
        public void RemoveCommentByEntity_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);

            context.SaveChanges();

            // Assert
            Assert.IsTrue(result);
            Assert.ThrowsException <KeyNotFoundException>(() => commentRepository.GetById(addedComment.Id));
        }
        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());
        }
Example #14
0
 public AccommodationRepository(FacilityContext context)
 {
     this.context = context;
 }
Example #15
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());
        }
Example #16
0
        public void AddComment_ShouldInsertInDb_WhenValidCommentIsSupplied()
        {
            // 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
            };

            // Act
            var result = commentRepository.Add(comment);

            context.SaveChanges();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreNotEqual(0, result.Id);
        }
Example #17
0
 public SensorTypeController(FacilityContext context)
 {
     this._context = context;
     this._context.Categories.OfType <SensorType>().Load();
 }