public void TestDuplicateInspectionInspectorLogic()
        {
            using (var context = InitAndGetDbContext())
            {
                //Arrange
                var repositori = new InspectionRepository(context);

                Inspector Inspector1 = new Inspector()
                {
                    Id = Guid.NewGuid(), Name = "Inspector 1", Created = DateTime.Today
                };
                Inspection Inspection1 = new Inspection()
                {
                    Id           = Guid.NewGuid(),
                    Customer     = "Customer 1",
                    Address      = "Address 1",
                    Observations = "Observation 1",
                    Status       = Status.Done,
                    Created      = DateTime.Today
                };
                InspectionInspector relation1 = new InspectionInspector()
                {
                    InspectionDate = DateTime.Today.AddDays(-1), InspectionId = Inspection1.Id, InspectorId = Inspector1.Id
                };
                Inspection1.InspectionInspector = new List <InspectionInspector>()
                {
                    relation1
                };

                repositori.Create(Inspection1);
                context.SaveChanges();

                InspectorDTO inspectorDTO = new InspectorDTO()
                {
                    Id = Inspector1.Id, Name = "Inspector 1"
                };
                InspectionDTO InspectionDTO = new InspectionDTO()
                {
                    Id             = Inspection1.Id,
                    Customer       = "Customer 1",
                    Address        = "Address 1",
                    Observations   = "Observation 1",
                    status         = Status.Done,
                    InspectionDate = relation1.InspectionDate,
                    Inspectors     = new List <InspectorDTO>()
                    {
                        inspectorDTO
                    }
                };


                //Act
                Inspection found = repositori.GetSingleEagerAsync(o => o.Id == InspectionDTO.Id &&
                                                                  o.InspectionInspector.Any(ii => ii.InspectionDate == InspectionDTO.InspectionDate) &&
                                                                  o.InspectionInspector.Any(ii => InspectionDTO.Inspectors.Any(i => i.Id == ii.InspectorId))).Result;

                //Assert
                Assert.NotNull(found);
            }
        }
Пример #2
0
        private void Save()
        {
            var iiList = new List <InspectionInspector>();

            foreach (var e in SelectedInspectors)
            {
                var ii = new InspectionInspector
                {
                    Employee    = _userRepository.Find(e.ID),
                    Inspection  = _inspectionRepository.Find(_inspection.ID),
                    LastUpdated = DateTime.Now
                };
                e.InspectionInspectors.Add(ii);
                _userRepository.Update(e);
                iiList.Add(ii);
            }
            _inspection.InspectionInspectors = iiList;

            _inspectionRepository.Update(_inspection);

            MessageBox.Show("De wijzigingen zijn opgeslagen!");
            _router.GoBack();
        }
Пример #3
0
        public void ShouldCreateWithInspectorInspector()
        {
            using (var context = InitAndGetDbContext())
            {
                //Arrange
                var repositori = new InspectorRepository(context);

                Inspector Inspector1 = new Inspector()
                {
                    Name = "Inspector 1", Created = DateTime.Today
                };
                Inspection Inspection1 = new Inspection()
                {
                    Customer     = "Customer 1",
                    Address      = "Address 1",
                    Observations = "Observation 1",
                    Status       = Status.Done,
                    Created      = DateTime.Today
                };
                InspectionInspector relation1 = new InspectionInspector()
                {
                    InspectionDate = DateTime.Today.AddDays(-1), InspectionId = Inspection1.Id, InspectorId = Inspector1.Id
                };
                Inspector1.InspectionInspector = new List <InspectionInspector>()
                {
                    relation1
                };

                //Act
                repositori.Create(Inspector1);
                Inspector result = repositori.Find(Inspector1.Id);

                //Assert
                Assert.NotNull(result);
            }
        }
Пример #4
0
        public static void Initialize(CotecnaEFContext context)
        {
            if (!context.Inspection.Any() && !context.Inspector.Any())
            {
                #region Inspector
                Inspector Inspector1 = new Inspector()
                {
                    Name = "Inspector 1", Created = DateTime.Today
                };
                Inspector Inspector2 = new Inspector()
                {
                    Name = "Inspector 2", Created = DateTime.Today
                };
                Inspector Inspector3 = new Inspector()
                {
                    Name = "Inspector 3", Created = DateTime.Today
                };

                context.Inspector.AddRange(
                    Inspector1,
                    Inspector2,
                    Inspector3
                    );
                #endregion Inspector

                #region Inspection
                Inspection Inspection1 = new Inspection()
                {
                    Customer     = "Customer 1",
                    Address      = "Address 1",
                    Observations = "Observation 1",
                    Status       = Status.Done,
                    Created      = DateTime.Today
                };
                InspectionInspector relation1 = new InspectionInspector()
                {
                    InspectionDate = DateTime.Today.AddDays(-1), InspectionId = Inspection1.Id, InspectorId = Inspector1.Id
                };
                InspectionInspector relation2 = new InspectionInspector()
                {
                    InspectionDate = DateTime.Today.AddDays(-1), InspectionId = Inspection1.Id, InspectorId = Inspector2.Id
                };
                Inspection1.InspectionInspector = new List <InspectionInspector>()
                {
                    relation1,
                    relation2
                };

                Inspection Inspection2 = new Inspection()
                {
                    Customer     = "Customer 2",
                    Address      = "Address 2",
                    Observations = "Observation 2",
                    Status       = Status.InProgress,
                    Created      = DateTime.Today
                };
                InspectionInspector relation3 = new InspectionInspector()
                {
                    InspectionDate = DateTime.Today, InspectionId = Inspection2.Id, InspectorId = Inspector2.Id
                };
                InspectionInspector relation4 = new InspectionInspector()
                {
                    InspectionDate = DateTime.Today, InspectionId = Inspection2.Id, InspectorId = Inspector3.Id
                };
                Inspection2.InspectionInspector = new List <InspectionInspector>()
                {
                    relation3,
                    relation4
                };

                Inspection Inspection3 = new Inspection()
                {
                    Customer     = "Customer 3",
                    Address      = "Address 3",
                    Observations = "Observation 3",
                    Status       = Status.New,
                    Created      = DateTime.Today
                };
                InspectionInspector relation5 = new InspectionInspector()
                {
                    InspectionDate = DateTime.Today.AddDays(2), InspectionId = Inspection3.Id, InspectorId = Inspector1.Id
                };
                InspectionInspector relation6 = new InspectionInspector()
                {
                    InspectionDate = DateTime.Today.AddDays(2), InspectionId = Inspection3.Id, InspectorId = Inspector3.Id
                };
                Inspection3.InspectionInspector = new List <InspectionInspector>()
                {
                    relation5,
                    relation6
                };

                Inspection Inspection4 = new Inspection()
                {
                    Customer     = "Customer 4",
                    Address      = "Address 4",
                    Observations = "Observation 4",
                    Status       = Status.New,
                    Created      = DateTime.Today
                };
                InspectionInspector relation7 = new InspectionInspector()
                {
                    InspectionDate = DateTime.Today.AddDays(2), InspectionId = Inspection4.Id, InspectorId = Inspector2.Id
                };
                InspectionInspector relation8 = new InspectionInspector()
                {
                    InspectionDate = DateTime.Today.AddDays(2), InspectionId = Inspection4.Id, InspectorId = Inspector3.Id
                };
                Inspection4.InspectionInspector = new List <InspectionInspector>()
                {
                    relation7,
                    relation8
                };

                Inspection Inspection5 = new Inspection()
                {
                    Customer     = "Customer 5",
                    Address      = "Address 5",
                    Observations = "Observation 5",
                    Status       = Status.New,
                    Created      = DateTime.Today
                };
                InspectionInspector relation9 = new InspectionInspector()
                {
                    InspectionDate = DateTime.Today.AddDays(2), InspectionId = Inspection5.Id, InspectorId = Inspector2.Id
                };
                InspectionInspector relation0 = new InspectionInspector()
                {
                    InspectionDate = DateTime.Today.AddDays(2), InspectionId = Inspection5.Id, InspectorId = Inspector3.Id
                };
                Inspection5.InspectionInspector = new List <InspectionInspector>()
                {
                    relation9,
                    relation0
                };

                context.Inspection.AddRange(
                    Inspection1,
                    Inspection2,
                    Inspection3,
                    Inspection4,
                    Inspection5
                    );
                #endregion Inspection

                context.SaveChanges();
            }
        }
Пример #5
0
        public IEnumerable <Inspection> GetInspectionsWithInspectors()
        {
            IEnumerable <Inspector> inspectors = GetInspectors();

            Inspection Inspection1 = new Inspection()
            {
                Customer     = "Customer 1",
                Address      = "Address 1",
                Observations = "Observation 1",
                Status       = Status.Done,
                Created      = DateTime.Today
            };
            InspectionInspector relation1 = new InspectionInspector()
            {
                InspectionDate = DateTime.Today.AddDays(-1), InspectionId = Inspection1.Id, InspectorId = inspectors.ElementAt(0).Id
            };
            InspectionInspector relation2 = new InspectionInspector()
            {
                InspectionDate = DateTime.Today.AddDays(-1), InspectionId = Inspection1.Id, InspectorId = inspectors.ElementAt(1).Id
            };

            Inspection1.InspectionInspector = new List <InspectionInspector>()
            {
                relation1,
                relation2
            };

            Inspection Inspection2 = new Inspection()
            {
                Customer     = "Customer 2",
                Address      = "Address 2",
                Observations = "Observation 2",
                Status       = Status.InProgress,
                Created      = DateTime.Today
            };
            InspectionInspector relation3 = new InspectionInspector()
            {
                InspectionDate = DateTime.Today, InspectionId = Inspection2.Id, InspectorId = inspectors.ElementAt(1).Id
            };
            InspectionInspector relation4 = new InspectionInspector()
            {
                InspectionDate = DateTime.Today, InspectionId = Inspection2.Id, InspectorId = inspectors.ElementAt(2).Id
            };

            Inspection2.InspectionInspector = new List <InspectionInspector>()
            {
                relation3,
                relation4
            };

            Inspection Inspection3 = new Inspection()
            {
                Customer     = "Customer 3",
                Address      = "Address 3",
                Observations = "Observation 3",
                Status       = Status.New,
                Created      = DateTime.Today
            };
            InspectionInspector relation5 = new InspectionInspector()
            {
                InspectionDate = DateTime.Today.AddDays(2), InspectionId = Inspection3.Id, InspectorId = inspectors.ElementAt(0).Id
            };
            InspectionInspector relation6 = new InspectionInspector()
            {
                InspectionDate = DateTime.Today.AddDays(2), InspectionId = Inspection3.Id, InspectorId = inspectors.ElementAt(2).Id
            };

            Inspection3.InspectionInspector = new List <InspectionInspector>()
            {
                relation5,
                relation6
            };


            return(new List <Inspection>()
            {
                Inspection1, Inspection2, Inspection3
            });
        }