예제 #1
0
        public void Test_DailyLogMgr_CreateDailyLog()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try {
                var options = new DbContextOptionsBuilder <HOSContext>()
                              .UseSqlite(connection)
                              .Options;

                using (var context = new HOSContext(options))
                {
                    context.Database.EnsureCreated();
                }

                using (var context = new HOSContext(options))
                {
                    HOSTestData.LoadStateProvinceCodeTable(context);
                    HOSTestData.LoadDutyStatusTable(context);
                    HOSTestData.LoadDutyStatusActivityTable(context);
                    HOSTestData.LoadCompanyTable(context);
                    HOSTestData.LoadAppUserTable(context);
                    HOSTestData.LoadDailyLogTable(context);
                    HOSTestData.LoadDailyLogDetailTable(context);
                }

                using (var context = new HOSContext(options))
                {
                    IDailyLogManager logMgr = new DailyLogManager(new Repository(context));

                    var dailyLogModel = new DailyLogModel
                    {
                        LogID            = 4,
                        LogDate          = new DateTime(2016, 9, 10),
                        BeginningMileage = 963000,
                        TruckNumber      = "3082",
                        TrailerNumber    = "9225",
                        IsSigned         = false,
                        Notes            = "Dropped trailer  9225 at Whirlpool and picked up loaded trailer 9159",
                        DriverID         = 4,
                        CreatedBy        = "sysadmin",
                        CreatedOn        = new DateTime(2016, 9, 10, 8, 0, 0),
                        UpdatedBy        = "sysadmin",
                        UpdatedOn        = new DateTime(2016, 9, 10, 8, 0, 0),
                    };

                    logMgr.Create(dailyLogModel);
                    logMgr.SaveChanges();

                    var test = logMgr.GetDailyLog(log => log.LogID == dailyLogModel.LogID);
                    Assert.NotNull(test);
                    Assert.Equal(new DateTime(2016, 9, 10), test.LogDate.Date);
                }
            } finally {
                connection.Close();
            }
        }
예제 #2
0
        public void Test_DailyLogMgr_UpdateDailyLog()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try {
                var options = new DbContextOptionsBuilder <HOSContext>()
                              .UseSqlite(connection)
                              .EnableSensitiveDataLogging()
                              .Options;

                using (var context = new HOSContext(options))
                {
                    context.Database.EnsureCreated();
                }

                using (var context = new HOSContext(options))
                {
                    HOSTestData.LoadStateProvinceCodeTable(context);
                    HOSTestData.LoadDutyStatusTable(context);
                    HOSTestData.LoadDutyStatusActivityTable(context);
                    HOSTestData.LoadCompanyTable(context);
                    HOSTestData.LoadAppUserTable(context);
                    HOSTestData.LoadDailyLogTable(context);
                    HOSTestData.LoadDailyLogDetailTable(context);
                }

                using (var context = new HOSContext(options))
                {
                    IDailyLogManager logMgr = new DailyLogManager(new Repository(context));

                    var dailyLogModel    = logMgr.GetDailyLog(log => log.LogID == 1);
                    var currentTimestamp = DateTime.Now;
                    dailyLogModel.UpdatedOn = currentTimestamp;

                    logMgr.Update(dailyLogModel);
                    logMgr.SaveChanges();

                    dailyLogModel = logMgr.GetDailyLog(log => log.LogID == 1);
                    Assert.Equal(currentTimestamp, dailyLogModel.UpdatedOn);
                }
            } finally {
                connection.Close();
            }
        }
예제 #3
0
        public void Test_DailyLogMgr_SelectAllDetailsForOneDay()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try {
                var options = new DbContextOptionsBuilder <HOSContext>()
                              .UseSqlite(connection)
                              .EnableSensitiveDataLogging()
                              .Options;

                using (var context = new HOSContext(options))
                {
                    context.Database.EnsureCreated();
                }

                using (var context = new HOSContext(options))
                {
                    HOSTestData.LoadStateProvinceCodeTable(context);
                    HOSTestData.LoadDutyStatusTable(context);
                    HOSTestData.LoadDutyStatusActivityTable(context);
                    HOSTestData.LoadCompanyTable(context);
                    HOSTestData.LoadAppUserTable(context);
                    HOSTestData.LoadDailyLogTable(context);
                    HOSTestData.LoadDailyLogDetailTable(context);
                }

                using (var context = new HOSContext(options))
                {
                    IDailyLogManager logMgr = new DailyLogManager(new Repository(context));

                    var dailyLogModel = logMgr.GetDailyLog(log => log.LogDate == new DateTime(2016, 9, 7));
                    Assert.NotNull(dailyLogModel);

                    var dailyLogDetailModel = logMgr.GetDailyLogDetails(details => details.LogID == dailyLogModel.LogID);
                    Assert.NotNull(dailyLogDetailModel);
                    Assert.Equal(8, dailyLogDetailModel.ToList().Count());
                }
            } finally {
                connection.Close();
            }
        }
예제 #4
0
        public void Test_DailyLogMgr_SelectDailyLog()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try {
                var options = new DbContextOptionsBuilder <HOSContext>()
                              .UseSqlite(connection)
                              .EnableSensitiveDataLogging()
                              .Options;

                using (var context = new HOSContext(options))
                {
                    context.Database.EnsureCreated();
                }

                using (var context = new HOSContext(options))
                {
                    HOSTestData.LoadStateProvinceCodeTable(context);
                    HOSTestData.LoadDutyStatusTable(context);
                    HOSTestData.LoadDutyStatusActivityTable(context);
                    HOSTestData.LoadCompanyTable(context);
                    HOSTestData.LoadAppUserTable(context);
                    HOSTestData.LoadDailyLogTable(context);
                    HOSTestData.LoadDailyLogDetailTable(context);
                }

                using (var context = new HOSContext(options))
                {
                    IDailyLogManager logMgr = new DailyLogManager(new Repository(context));

                    var allLogs       = logMgr.GetAll().ToList();
                    var allLogsForDrv = logMgr.GetDailyLogs(log => log.DriverID == 4);

                    Assert.Equal(3, allLogs.Count());
                    Assert.Equal(3, allLogsForDrv.Count());
                }
            } finally {
                connection.Close();
            }
        }
예제 #5
0
        public void Test_DailyLogDetailAllForUser()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try {
                var options = new DbContextOptionsBuilder <HOSContext>()
                              .UseSqlite(connection)
                              .Options;

                using (var context = new HOSContext(options))
                {
                    context.Database.EnsureCreated();
                }

                using (var context = new HOSContext(options))
                {
                    HOSTestData.LoadDutyStatusActivityTable(context);
                    HOSTestData.LoadDutyStatusTable(context);
                    HOSTestData.LoadStateProvinceCodeTable(context);
                    HOSTestData.LoadCompanyTable(context);
                    HOSTestData.LoadAppUserTable(context);
                    HOSTestData.LoadDailyLogTable(context);
                }

                using (var context = new HOSContext(options))
                {
                    IRepository repository = new Repository(context);

                    var user = repository.Find <AppUser>(u => u.UserName == "leadfoot");
                    Assert.NotNull(user);

                    var dailyLogs = repository.Filter <DailyLog>(dl => dl.DriverID == user.Id);
                    Assert.Equal(3, dailyLogs.ToList().Count());
                }
            } finally {
                connection.Close();
            }
        }
예제 #6
0
        public void Test_DailyLogDetailDelete()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try {
                var options = new DbContextOptionsBuilder <HOSContext>()
                              .UseSqlite(connection)
                              .Options;

                using (var context = new HOSContext(options))
                {
                    context.Database.EnsureCreated();
                }

                using (var context = new HOSContext(options))
                {
                    HOSTestData.LoadDutyStatusActivityTable(context);
                    HOSTestData.LoadDutyStatusTable(context);
                    HOSTestData.LoadStateProvinceCodeTable(context);
                    HOSTestData.LoadCompanyTable(context);
                    HOSTestData.LoadAppUserTable(context);
                }

                using (var context = new HOSContext(options))
                {
                    IRepository repository = new Repository(context);

                    var dailyLog = new DailyLog
                    {
                        LogID            = 1,
                        LogDate          = new DateTime(2016, 9, 7),
                        BeginningMileage = 899201,
                        EndingMileage    = 899423,
                        TruckNumber      = "3082",
                        TrailerNumber    = "9225",
                        IsSigned         = true,
                        Notes            = "Dropped trailer  9225 at Whirlpool and picked up loaded trailer 9159",
                        DriverID         = 4
                    };

                    var logDetail = new DailyLogDetail
                    {
                        LogDetailID          = 1,
                        DutyStatusID         = 4,
                        StartTime            = new DateTime(2016, 9, 7, 12, 45, 0),
                        StopTime             = new DateTime(2016, 9, 7, 13, 0, 0),
                        LocationCity         = "Ft Worth",
                        StateProvinceId      = 45,
                        DutyStatusActivityID = 1,
                        LogID = 1
                    };

                    dailyLog.DailyLogDetails.Add(logDetail);
                    repository.Create <DailyLog>(dailyLog);
                    repository.Save();

                    var test          = repository.Find <DailyLog>(log => log.LogID == dailyLog.LogID);
                    var logDetailTest = test.DailyLogDetails.FirstOrDefault();

                    Assert.NotNull(logDetailTest);
                    test.DailyLogDetails.Remove(logDetailTest);
                    repository.Save();
                    logDetailTest = test.DailyLogDetails.FirstOrDefault();

                    Assert.Null(logDetailTest);
                }
            } finally {
                connection.Close();
            }
        }
예제 #7
0
        public void Test_DailyLogMgr_CreateDailyLogDetail()
        {
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            try {
                var options = new DbContextOptionsBuilder <HOSContext>()
                              .UseSqlite(connection)
                              .EnableSensitiveDataLogging()
                              .Options;

                using (var context = new HOSContext(options))
                {
                    context.Database.EnsureCreated();
                }

                using (var context = new HOSContext(options))
                {
                    HOSTestData.LoadStateProvinceCodeTable(context);
                    HOSTestData.LoadDutyStatusTable(context);
                    HOSTestData.LoadDutyStatusActivityTable(context);
                    HOSTestData.LoadCompanyTable(context);
                    HOSTestData.LoadAppUserTable(context);
                    HOSTestData.LoadDailyLogTable(context);
                    HOSTestData.LoadDailyLogDetailTable(context);
                }

                using (var context = new HOSContext(options))
                {
                    IDailyLogManager logMgr = new DailyLogManager(new Repository(context));
                    var dailyLog            = logMgr.GetDailyLog(log => log.LogID == 3);

                    // Retrieve the last pre-trip entry for this driver
                    var mostRecentPreTrip = logMgr.GetLastPreTripInspection(drv => drv.DriverID == dailyLog.DriverID);

                    // Determine hours available on 14
                    // Determine hours available on 11
                    // Determine if in violation of 30 min break rule
                    // Determine current duty status
                    // Determine duty status driver is attempting to move to

                    var dailyLogDetailModel = new DailyLogDetailModel
                    {
                        LogDetailID          = 23,
                        LogID                = dailyLog.LogID,
                        DutyStatusID         = 4,
                        StartTime            = new DateTime(2016, 9, 9, 8, 0, 0),
                        LocationCity         = "Fort Worth",
                        StateProvinceId      = 45,
                        DutyStatusActivityID = 1
                    };

                    logMgr.CreateLogDetail(dailyLogDetailModel);
                    logMgr.SaveChanges();

                    dailyLogDetailModel = logMgr.GetDailyLogDetail(details => details.LogID == dailyLog.LogID);
                    Assert.NotNull(dailyLogDetailModel);
                }
            } finally {
                connection.Close();
            }
        }