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 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);
        }
Example #3
0
        private void ComponentTypeDropDown_SelectionChangeCommitted(object sender, EventArgs e)
        {
            if (ComponentTypeDropDown.SelectedValue.AsByte() > 0)
            {
                return;
            }

            if (Application.OpenForms.OfType <ComponentTypePopup>().Count() < 1)
            {
                using (ComponentTypePopup popup = new ComponentTypePopup(MainForm))
                {
                    var result = popup.ShowDialog();

                    if (popup.ComponentTypeID > 0)
                    {
                        using (var repository = new ComponentTypeRepository())
                        {
                            var dropDown = repository.GetComponentTypeForDropDown();
                            dropDown.Insert(0, new KeyValuePair <byte, string>(0, "<Vytvořit nový typ...>"));

                            ComponentTypeDropDown.DataSource    = dropDown;
                            ComponentTypeDropDown.SelectedValue = popup.ComponentTypeID;
                        }
                    }
                }
            }
        }
        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 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);
            }
        }
Example #6
0
        public ComponentTypePopup(Form main)
        {
            ComponentTypeRepository = new ComponentTypeRepository();
            MainForm = main as MainForm;

            InitializeComponent();
        }
Example #7
0
 public UnitOfWork(ApplicationDbContext context)
 {
     _context       = context;
     Components     = new ComponentRepository(_context);
     Categories     = new CategoryRepository(_context);
     ComponentTypes = new ComponentTypeRepository(_context);
 }
Example #8
0
        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));
            }
        }
Example #9
0
        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));
            }
        }
Example #10
0
 public UnitOfWork(EmbeddedStockContext context)
 {
     _context               = context;
     Categories             = new CategoryRepository(_context);
     ComponentTypes         = new ComponentTypeRepository(_context);
     Components             = new ComponentRepository(_context);
     CategoryComponentTypes = new CategoryComponentTypeRepository(_context);
 }
        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 SwtorcraftingService()
 {
     swtoreliteAPI = new SwtoreliteAPI();
     componentRankRepo = new ComponentRankRepository();
     componentTypeRepo = new ComponentTypeRepository();
     rarityRepo = new RarityRepository();
     itemAttributeRepo = new ItemAttributeRepository();
     componentRepo = new ComponentRepository();
 }
        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));
        }
Example #14
0
 public SwtorcraftingService()
 {
     swtoreliteAPI     = new SwtoreliteAPI();
     componentRankRepo = new ComponentRankRepository();
     componentTypeRepo = new ComponentTypeRepository();
     rarityRepo        = new RarityRepository();
     itemAttributeRepo = new ItemAttributeRepository();
     componentRepo     = new ComponentRepository();
 }
Example #15
0
        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 ComponentTypeRepositoryUnitTests()
 {
     _componentTypeRepository = new ComponentTypeRepository(DbContext);
     DbContext.ComponentTypes.Add(new ComponentType {
         Name = "CPU"
     });
     DbContext.ComponentTypes.Add(new ComponentType {
         Name = "GPU"
     });
     DbContext.SaveChanges();
 }
        public void UpdateComponentTypeByTransfertObject_ThrowException_WhenNullIsSupplied()
        {
            var options = new DbContextOptionsBuilder <FacilityContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using (var memoryCtx = new FacilityContext(options))
            {
                var componentTypeRepository = new ComponentTypeRepository(memoryCtx);
                Assert.ThrowsException <ArgumentNullException>(() => componentTypeRepository.Update(null));
            }
        }
        public void GetComponentTypeById_ThrowsException_WhenInvalidIdIsProvided()
        {
            var options = new DbContextOptionsBuilder <FacilityContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using (var memoryCtx = new FacilityContext(options))
            {
                var componentTypeRepository = new ComponentTypeRepository(memoryCtx);

                Assert.ThrowsException <NullComponentTypeException>(() => componentTypeRepository.GetById(100));
            }
        }
        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 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));
            }
        }
Example #22
0
        private void ViewComponentDetailTab(int id)
        {
            using (var repository = new ComponentTypeRepository())
            {
                var dropDown = repository.GetComponentTypeForDropDown();
                dropDown.Insert(0, new KeyValuePair <byte, string>(0, "<Vytvořit nový typ...>"));

                ComponentTypeDropDown.DataSource = dropDown;
            }

            if (id > 0)
            {
                IsWork     = false;
                RibbonMode = RibbonMode.Detail;

                ChangeControlsEnabled(DetailTab.Controls, false, false);

                var component = ComponentRepository.GetComponent(componentID);

                ComponentTypeDropDown.SelectedValue = component.ComponentTypeID;
                NameTextBox.Text = component.Name.ToString();

                ProductGrid.DataSource = ComponentRepository.GetProducts(componentID);

                ComponentTabControl.SelectedTab = DetailTab;

                ProductGrid.ClearSelection();
            }
            else
            {
                IsWork     = true;
                RibbonMode = RibbonMode.Edit;

                ChangeControlsEnabled(DetailTab.Controls, true, true);

                ComponentTabControl.SelectedTab = DetailTab;
            }
        }
Example #23
0
        private void ViewComponentListingTab()
        {
            IsWork = false;

            using (var repository = new ComponentTypeRepository())
            {
                var dropDown = repository.GetComponentTypeForDropDown();
                dropDown.Insert(0, new KeyValuePair <byte, string>());

                FilterComponentTypeDropDown.DataSource = dropDown;
            }
            using (var repository = new ProductRepository())
            {
                var dropDown = repository.GetProductsForDropDown();
                dropDown.Insert(0, new KeyValuePair <int, string>());

                FilterProductDropDown.DataSource = dropDown;
            }

            ChangeControlsEnabled(DetailTab.Controls, false, true);

            ComponentTabControl.SelectedTab = ListingTab;
        }
        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);
            }
        }
Example #25
0
        private void InventoryItemPopup_Load(object sender, EventArgs e)
        {
            Left = MainForm.Location.X + (MainForm.Width / 2 - Width / 2);
            Top  = MainForm.Location.Y + (MainForm.Height / 2 - Height / 2);

            using (var repository = new ComponentTypeRepository())
            {
                var dropDown = repository.GetComponentTypeForDropDown();
                dropDown.Insert(0, new KeyValuePair <byte, string>());

                FilterComponentTypeDropDown.DataSource = dropDown;
            }
            using (var repository = new ProductRepository())
            {
                var dropDown = repository.GetProductsForDropDown(inventoryID);
                dropDown.Insert(0, new KeyValuePair <int, string>());

                FilterProductDropDown.DataSource = dropDown;
            }

            FilterButton_Click(sender, e);

            ComponentGrid.ClearSelection();
        }
Example #26
0
 public ComponentTypeController()
 {
     _componentTypeRepository = new ComponentTypeRepository(@"C:\sqlite\PracticeToolDB.db");
 }
        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);
        }
Example #28
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 #29
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));
        }
Example #30
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);
        }
Example #31
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());
        }