Beispiel #1
0
        public override void Synchronize(Func <PackScheduleKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }
            var packScheduleKey = getInput();

            var newPackSchedule = UnitOfWork.PackScheduleRepository.SelectPackScheduleForSynch(packScheduleKey);
            var oldPackSchedule = OldContext.tblPackSches.Select(p => new
            {
                packSchedule = p,
                lots         = p.tblLots
            }).FirstOrDefault(p => p.packSchedule.PackSchID == newPackSchedule.PackSchID);

            if (oldPackSchedule == null)
            {
                throw new Exception(string.Format("Could not find tblPackSch[{0}] record.", newPackSchedule.PackSchID));
            }
            SynchronizePackScheduleHelper.SynchronizeOldContextPackSchedule(oldPackSchedule.packSchedule, newPackSchedule);

            OldContext.SaveChanges();

            Console.Write(ConsoleOutput.UpdatedPackSchedule, oldPackSchedule.packSchedule.PackSchID.ToPackSchIdString());
        }
            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));
                }
            }
        private tblPackSch CreateNewPackSchedule(PackSchedule packSchedule, bool useSuppliedPSNum)
        {
            var packSchId  = packSchedule.TimeStamp.ConvertLocalToUTC().RoundMillisecondsForSQL();
            var tblPackSch = new tblPackSch
            {
                SerializedKey = packSchedule.ToPackScheduleKey(),
                PackSchID     = packSchId,
                PSNum         = useSuppliedPSNum && packSchedule.PSNum != null ? packSchedule.PSNum.Value :
                                OldContext.tblPackSches.Select(p => p.PSNum).Where(p => p != null).DefaultIfEmpty(0).Max().Value + 1,
                PSStatus   = 1,
                SetTrtmtID = 0
            };

            SynchronizePackScheduleHelper.SynchronizeOldContextPackSchedule(tblPackSch, packSchedule);
            return(tblPackSch);
        }
            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);
            }
Beispiel #6
0
        public override void Synchronize(Func <LotKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }
            var lotNumber = LotNumberBuilder.BuildLotNumber(getInput());

            var tblLot = OldContext.tblLots
                         .Include
                         (
                l => l.inputBatchItems,
                l => l.tblBatchInstr,
                l => l.tblBOMs,
                l => l.tblLotAttributeHistory,
                l => l.tblIncomings,
                l => l.tblOutgoingInputs,
                l => l.tblPackSch
                         )
                         .FirstOrDefault(l => l.Lot == lotNumber);

            if (tblLot == null)
            {
                throw new Exception(string.Format("tblLot[{0}] not found.", lotNumber));
            }

            if (tblLot.tblPackSch == null)
            {
                throw new Exception(string.Format("tblPackSch record for tblLot[{0}] not found.", lotNumber));
            }

            var newPackSchedule = UnitOfWork.PackScheduleRepository.SelectPackScheduleForSynch(new PackSchIdKey(tblLot.tblPackSch.PackSchID));

            SynchronizePackScheduleHelper.SynchronizeOldContextPackSchedule(tblLot.tblPackSch, newPackSchedule);

            new DeleteTblLotHelper(OldContext).DeleteLot(tblLot);

            OldContext.SaveChanges();

            Console.WriteLine(ConsoleOutput.RemovedProductionBatch, lotNumber);
        }
            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));
            }