Example #1
0
        public void FindEngineersAvailableOn_WEEK_SCAN_PERIOD_Error()
        {
            string contextName = "FindEngineersAvailableOn_WEEK_SCAN_PERIOD_Error";

            _contextNames.Add(contextName);
            DbContextOptions <BAUDbContext> options = DbContextUtils.GetContextOptions(contextName);

            using (var context = new BAUDbContext(options))
            {
                try
                {
                    new ShiftRepository(context, ConfigurationTestBuilder.GetConfiguration("WEEK_SCAN_PERIOD"));
                }
                catch (ArgumentNullException ex)
                {
                    Assert.Equal("App:WEEK_SCAN_PERIOD", ex.ParamName);
                }
            }
        }
Example #2
0
        public void FindEngineersAvailableOn_MAX_SHIFT_SUM_HOURS_DURATION_Error()
        {
            string contextName = "FindEngineersAvailableOn_MAX_SHIFT_SUM_HOURS_DURATION_Error";

            _contextNames.Add(contextName);
            DbContextOptions <BAUDbContext> options = DbContextUtils.GetContextOptions(contextName);

            using (var context = new BAUDbContext(options))
            {
                try
                {
                    new ShiftRepository(context, ConfigurationTestBuilder.GetConfiguration("MAX_SHIFT_SUM_HOURS_DURATION"));
                }
                catch (ArgumentNullException ex)
                {
                    Assert.Equal("App:MAX_SHIFT_SUM_HOURS_DURATION", ex.ParamName);
                }
            }
        }
Example #3
0
        public void FindEngineersAvailableOn_Check_Consecutive_Days(DateTime date, int nEngineers)
        {
            string contextName = $"FindEngineersAvailableOn_Check_Consecutive_Days";

            _contextNames.Add(contextName);
            DbContextOptions <BAUDbContext> options = DbContextUtils.GetContextOptions(contextName);
            IShiftRepository repository             = null;
            const int        shiftDuration          = 4;

            // fake data
            using (BAUDbContext context = new BAUDbContext(options))
            {
                var engineer1 = new Engineer {
                    Name = "1"
                };
                var engineer2 = new Engineer {
                    Name = "2"
                };
                var engineer3 = new Engineer {
                    Name = "3"
                };
                var engineer4 = new Engineer {
                    Name = "4"
                };
                var engineer5 = new Engineer {
                    Name = "5"
                };
                var engineer6 = new Engineer {
                    Name = "6"
                };
                var engineer7 = new Engineer {
                    Name = "7"
                };
                var engineer8 = new Engineer {
                    Name = "8"
                };
                var engineer9 = new Engineer {
                    Name = "9"
                };
                var engineer10 = new Engineer {
                    Name = "10"
                };
                var engineersList = new List <Engineer>
                {
                    engineer1, engineer2, engineer3, engineer4,
                    engineer5, engineer6, engineer7, engineer8,
                    engineer9, engineer10,
                };

                context.Engineers.AddRange(engineersList);

                var today  = new DateTime(2017, 12, 11);
                var shifts = new List <EngineerShift>
                {
                    //first week
                    new EngineerShift {
                        Date = today.Date, Duration = shiftDuration, Engineer = engineer1
                    },
                    new EngineerShift {
                        Date = today.Date, Duration = shiftDuration, Engineer = engineer2
                    },
                    new EngineerShift {
                        Date = today.Date.AddDays(1), Duration = shiftDuration, Engineer = engineer7
                    },
                    new EngineerShift {
                        Date = today.Date.AddDays(2), Duration = shiftDuration, Engineer = engineer3
                    },
                    new EngineerShift {
                        Date = today.Date.AddDays(2), Duration = shiftDuration, Engineer = engineer4
                    },
                    new EngineerShift {
                        Date = today.Date.AddDays(4), Duration = shiftDuration, Engineer = engineer5
                    },
                    new EngineerShift {
                        Date = today.Date.AddDays(4), Duration = shiftDuration, Engineer = engineer6
                    },
                };

                context.EngineersShifts.AddRange(shifts);
                context.SaveChanges();
            }

            // test
            using (var context = new BAUDbContext(options))
            {
                repository = new ShiftRepository(context, ConfigurationTestBuilder.GetConfiguration());
                IList <Engineer> availableEngineers = repository.FindEngineersAvailableOn(date);
                Assert.Equal(nEngineers, availableEngineers.Count);
            }
        }