public void Updates_associated_batch_tblLot_records_Company_IA_column_as_expected()
            {
                //Arrange
                var customer = RVCUnitOfWork.CustomerRepository.Filter(c => true, c => c.Company).FirstOrDefault();

                if (customer == null)
                {
                    Assert.Inconclusive("No Customer records loaded.");
                }

                var packSchedule = RVCUnitOfWork.PackScheduleRepository
                                   .Filter(p => p.ProductionBatches.Count > 2 &&
                                           p.ProductionBatches.All(b => b.Production.PickedInventory.Items.Any()) &&
                                           p.CustomerId != customer.Id,
                                           p => p.ProductionBatches).FirstOrDefault();

                if (packSchedule == null)
                {
                    Assert.Inconclusive("No valid test PackSchedule found.");
                }

                var parameters = new UpdatePackScheduleParameters
                {
                    UserToken       = TestUser.UserName,
                    PackScheduleKey = new PackScheduleKey(packSchedule),

                    WorkTypeKey             = new WorkTypeKey(packSchedule),
                    ChileProductKey         = new ChileProductKey(packSchedule),
                    PackagingProductKey     = new PackagingProductKey(packSchedule),
                    ScheduledProductionDate = packSchedule.ScheduledProductionDate,
                    ProductionDeadline      = packSchedule.ProductionDeadline,
                    ProductionLineKey       = new LocationKey(packSchedule),
                    SummaryOfWork           = packSchedule.SummaryOfWork,
                    CustomerKey             = new CompanyKey(customer),
                    OrderNumber             = packSchedule.OrderNumber,
                    BatchTargetWeight       = packSchedule.DefaultBatchTargetParameters.BatchTargetWeight,
                    BatchTargetAsta         = packSchedule.DefaultBatchTargetParameters.BatchTargetAsta,
                    BatchTargetScan         = packSchedule.DefaultBatchTargetParameters.BatchTargetScan,
                    BatchTargetScoville     = packSchedule.DefaultBatchTargetParameters.BatchTargetScoville,
                };

                //Act
                var result = Service.UpdatePackSchedule(parameters);

                //Assert
                result.AssertSuccess();

                var packSchId = SynchronizePackScheduleHelper.ToPackSchId(GetKeyFromConsoleString(ConsoleOutput.UpdatedPackSchedule)).Value;

                using (var oldContext = new RioAccessSQLEntities())
                {
                    var tblLots = oldContext.tblLots.Where(l => l.PackSchID == packSchId).ToList();
                    Assert.Greater(tblLots.Count, 2);
                    foreach (var lot in tblLots)
                    {
                        Assert.AreEqual(customer.Company.Name, lot.Company_IA);
                    }
                }
            }
            public void Removes_tblPackSch_record_and_KillSwitch_will_not_have_been_engaged_if_service_method_and_synchronization_were_successful()
            {
                //Arrange
                var packSchedules = RVCUnitOfWork.PackScheduleRepository.Filter(p =>
                                                                                p.ScheduledItems.Any() &&
                                                                                (!p.ProductionBatches.Any() ||
                                                                                 p.ProductionBatches.All(b =>
                                                                                                         !b.ProductionHasBeenCompleted &&
                                                                                                         b.Production.Results == null &&
                                                                                                         b.Production.ResultingChileLot.Lot.ProductionStatus == LotProductionStatus.Batched &&
                                                                                                         !b.Production.ResultingChileLot.Lot.Inventory.Any() &&
                                                                                                         (
                                                                                                             !b.Production.PickedInventory.Items.Any() ||
                                                                                                             b.Production.PickedInventory.Items.All(i => i.CurrentLocationId == i.FromLocationId)
                                                                                                         ))))
                                    .ToList();

                Console.WriteLine("Valid test PackSchedules: {0}", packSchedules.Count);
                if (!packSchedules.Any())
                {
                    throw new Exception("No valid test PackSchedules found.");
                }
                var packSchedule = packSchedules.First();
                var packSchId    = packSchedule.PackSchID.ToPackSchIdString();

                Console.WriteLine("Expecting to remove tblPackSch[{0}]", packSchId);

                TestHelper.ResetContext();

                //Act
                var result = Service.RemovePackSchedule(new RemovePackScheduleParameters
                {
                    UserToken       = TestUser.UserName,
                    PackScheduleKey = new PackScheduleKey(packSchedule)
                });
                var packSchString = GetKeyFromConsoleString(ConsoleOutput.RemovedPackSchedule);

                //Assert
                result.AssertSuccess();
                MockKillSwitch.Verify(k => k.Engage(), Times.Never());

                var packSchIdKey = SynchronizePackScheduleHelper.ToPackSchId(packSchString).Value;

                using (var oldContext = new RioAccessSQLEntities())
                {
                    Assert.IsNull(oldContext.tblPackSches.FirstOrDefault(p => p.PackSchID == packSchIdKey));
                    Assert.AreEqual(0, oldContext.tblBatchItems.Count(b => b.PackSchID == packSchIdKey));
                }
            }
            public void Updates_tblPackSch_record_and_KillSwitch_will_not_have_been_engaged_if_service_method_and_syncrhonization_were_successful()
            {
                //Arrange


                const string expectedSummary = "UpdatePackScheduleSynchTest";
                var          packSchedule    = RVCUnitOfWork.PackScheduleRepository.All().FirstOrDefault(p => p.SummaryOfWork != expectedSummary);

                if (packSchedule == null)
                {
                    throw new Exception("No valid test PackSchedule found.");
                }

                var parameters = new UpdatePackScheduleParameters
                {
                    PackScheduleKey         = new PackScheduleKey(packSchedule),
                    UserToken               = TestUser.UserName,
                    ScheduledProductionDate = packSchedule.ScheduledProductionDate,
                    ProductionDeadline      = packSchedule.ProductionDeadline,
                    ProductionLineKey       = new LocationKey(packSchedule),
                    SummaryOfWork           = expectedSummary,
                    ChileProductKey         = new ChileProductKey(packSchedule),
                    PackagingProductKey     = new PackagingProductKey(packSchedule),
                    WorkTypeKey             = new WorkTypeKey(packSchedule),
                };

                parameters.SetBatchTargetParameters(packSchedule.DefaultBatchTargetParameters);

                TestHelper.ResetContext();

                //Act
                var result        = Service.UpdatePackSchedule(parameters);
                var packSchString = GetKeyFromConsoleString(ConsoleOutput.UpdatedPackSchedule);

                //Assert
                result.AssertSuccess();
                MockKillSwitch.Verify(k => k.Engage(), Times.Never());

                var packSchId = SynchronizePackScheduleHelper.ToPackSchId(packSchString).Value;

                Assert.AreEqual(expectedSummary, new RioAccessSQLEntities().tblPackSches.FirstOrDefault(p => p.PackSchID == packSchId).PackSchDesc);
            }
            public void Creates_new_tblPackSch_record_and_KillSwitch_will_not_have_been_engaged_if_service_method_and_synchronization_were_successful()
            {
                //Arrange
                var workType = RVCUnitOfWork.WorkTypeRepository.All().FirstOrDefault();

                if (workType == null)
                {
                    throw new Exception("No WorkType record found.");
                }

                var chileProduct = RVCUnitOfWork.ChileProductRepository.All().FirstOrDefault();

                if (chileProduct == null)
                {
                    throw new Exception("No ChileProduct record found.");
                }

                var packagingProduct = RVCUnitOfWork.PackagingProductRepository.All().FirstOrDefault(p => p.Weight > 0.0f);

                if (packagingProduct == null)
                {
                    throw new Exception("No PackagingProduct record found.");
                }

                var productionLine = RVCUnitOfWork.LocationRepository.All().FirstOrDefault(l => l.LocationType == LocationType.ProductionLine);

                if (productionLine == null)
                {
                    throw new Exception("No ProductionLocation of Line type found.");
                }

                var parameters = new CreatePackScheduleParameters
                {
                    UserToken               = TestUser.UserName,
                    WorkTypeKey             = new WorkTypeKey(workType),
                    ChileProductKey         = new ChileProductKey(chileProduct),
                    PackagingProductKey     = new PackagingProductKey(packagingProduct),
                    ProductionLineKey       = new LocationKey(productionLine),
                    SummaryOfWork           = "SynchTest",
                    ProductionDeadline      = new DateTime(2020, 2, 20),
                    ScheduledProductionDate = DateTime.UtcNow,
                    BatchTargetWeight       = 1000,
                    BatchTargetAsta         = 1,
                    BatchTargetScan         = 2,
                    BatchTargetScoville     = 3
                };

                TestHelper.ResetContext();

                //Act
                var result        = Service.CreatePackSchedule(parameters);
                var packSchString = GetKeyFromConsoleString(ConsoleOutput.AddedPackSchedule);

                //Assert
                result.AssertSuccess();
                MockKillSwitch.Verify(k => k.Engage(), Times.Never());

                var packSchId = SynchronizePackScheduleHelper.ToPackSchId(packSchString).Value;

                Assert.IsNotNull(new RioAccessSQLEntities().tblPackSches.FirstOrDefault(p => p.PackSchID == packSchId));
            }