public void Deletes_tblProductionSchedule_and_associated_records()
            {
                //Arrange
                var productionSchedule = RVCUnitOfWork.ProductionScheduleRepository.Filter(p => p.ScheduledItems.Any(),
                                                                                           p => p.ProductionLineLocation)
                                         .OrderByDescending(p => p.ProductionDate)
                                         .FirstOrDefault();

                if (productionSchedule == null)
                {
                    Assert.Inconclusive("No suitable ProductionSchedule to test.");
                }

                //Act
                var result = Service.DeleteProductionSchedule(productionSchedule.ToProductionScheduleKey());

                //Assert
                result.AssertSuccess();
                using (var oldContext = new RioAccessSQLEntities())
                {
                    string street;
                    int    row;
                    LocationDescriptionHelper.GetStreetRow(productionSchedule.ProductionLineLocation.Description, out street, out row);
                    Assert.IsEmpty(oldContext.tblProductionScheduleItems.Where(i => i.ProductionDate == productionSchedule.ProductionDate && (int)i.LineNumber == row));
                    Assert.IsEmpty(oldContext.tblProductionScheduleGroups.Where(i => i.ProductionDate == productionSchedule.ProductionDate && (int)i.LineNumber == row));
                    Assert.IsEmpty(oldContext.tblProductionSchedules.Where(i => i.ProductionDate == productionSchedule.ProductionDate && (int)i.LineNumber == row));
                }
            }
            public void Creates_tblProductionSchedule_record_as_expected()
            {
                //Arrange
                var productionLineLocation = RVCUnitOfWork.LocationRepository.FindBy(l => l.LocationType == LocationType.ProductionLine);

                if (productionLineLocation == null)
                {
                    Assert.Inconclusive("No ProductionLine location found.");
                }

                var productionDate = RVCUnitOfWork.ProductionScheduleRepository.SourceQuery.Select(p => p.ProductionDate).DefaultIfEmpty(DateTime.Now.Date).Max().AddDays(1);

                //Act
                var result = Service.CreateProductionSchedule(new CreateProductionScheduleParameters
                {
                    UserToken                 = TestUser.UserName,
                    ProductionDate            = productionDate,
                    ProductionLineLocationKey = productionLineLocation.ToLocationKey()
                });

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

                string street;
                int    row;

                LocationDescriptionHelper.GetStreetRow(productionLineLocation.Description, out street, out row);
                using (var oldContext = new RioAccessSQLEntities())
                {
                    var productionSchedule = oldContext.tblProductionSchedules.FirstOrDefault(p => p.ProductionDate == productionDate && (int)p.LineNumber == row);
                    Assert.AreEqual(TestUser.EmployeeId, productionSchedule.CreatedBy);
                }
            }
        private static string GetLineNumber(string locationDescription)
        {
            string street;
            int    row;

            return(LocationDescriptionHelper.GetStreetRow(locationDescription, out street, out row) ? row.ToString() : locationDescription);
        }
Example #4
0
        public override void Synchronize(Func <ProductionScheduleKey> getInput)
        {
            var productionScheduleKey = getInput();

            var productionSchedule = UnitOfWork.ProductionScheduleRepository.FindByKey(productionScheduleKey,
                                                                                       p => p.ScheduledItems.Select(i => i.PackSchedule.ProductionBatches));

            var    location = UnitOfWork.LocationRepository.FindByKey(productionScheduleKey.ToLocationKey());
            string street;
            int    row;

            LocationDescriptionHelper.GetStreetRow(location.Description, out street, out row);

            var oldProductionSchedule = OldContext.tblProductionSchedules
                                        .Include(p => p.tblProductionScheduleGroups.Select(g => g.tblProductionScheduleItems))
                                        .FirstOrDefault(p => p.ProductionDate == productionScheduleKey.ProductionScheduleKey_ProductionDate && (int)p.LineNumber == row);

            if (productionSchedule == null)
            {
                if (oldProductionSchedule != null)
                {
                    DeleteSchedule(oldProductionSchedule);
                }
            }
            else
            {
                SetSchedule(oldProductionSchedule, productionSchedule, row);
            }

            OldContext.SaveChanges();

            Console.WriteLine(ConsoleOutput.SyncProductionSchedule, productionScheduleKey.ProductionScheduleKey_ProductionDate.ToString("yyyyMMdd"), row);
        }
Example #5
0
        public bool IsGroup(string groupName)
        {
            string street;
            int    row;

            if (LocationDescriptionHelper.GetStreetRow(Location, out street, out row))
            {
                return(street == groupName);
            }
            return(Location == groupName);
        }
Example #6
0
        public PackSchedulePickSheetReportModel Initialize()
        {
            if (LocationDescriptionHelper.GetStreetRow(WarehouseLocation, out _street, out _row))
            {
                WarehouseLocation = LocationDescriptionHelper.ToDisplayString(_street, _row);
            }
            else
            {
                _street = null;
                _row    = 0;
            }

            return(this);
        }
Example #7
0
            public void Creates_new_tblLocation_record_as_expected()
            {
                //Arrange
                var facility = RVCUnitOfWork.FacilityRepository.Filter(f => f.WHID != null).FirstOrDefault();

                if (facility == null)
                {
                    Assert.Inconclusive("No suitable Facility found.");
                }

                var locations = RVCUnitOfWork.LocationRepository.Filter(l => l.Description.StartsWith("A")).ToList();
                var row       = 1;

                if (locations.Any())
                {
                    locations.ForEach(l =>
                    {
                        string street;
                        int otherRow;
                        LocationDescriptionHelper.GetStreetRow(l.Description, out street, out otherRow);
                        row = Math.Max(row, otherRow);
                    });
                }
                row += 1;

                //Act
                var result = Service.CreateLocation(new CreateLocationParameters
                {
                    UserToken    = TestUser.UserName,
                    FacilityKey  = new FacilityKey(facility),
                    LocationType = LocationType.ProductionLine,
                    Description  = string.Format("A~{0}", row),
                    Active       = true,
                    Locked       = true,
                });
                var resultString = GetKeyFromConsoleString(ConsoleOutput.SyncLocation);

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

                var locId    = int.Parse(resultString);
                var location = new RioAccessSQLEntities().tblLocations.FirstOrDefault(l => l.LocID == locId);

                Assert.AreEqual("A", location.Street);
                Assert.AreEqual(row, location.Row);
                Assert.AreEqual(facility.WHID.Value, location.WHID);
            }
Example #8
0
        private static tblLocation Update(IEmployeeKey employeeKey, Location location, tblLocation tblLocation)
        {
            string street;
            int    row;

            LocationDescriptionHelper.GetStreetRow(location.Description, out street, out row);

            tblLocation.EmployeeID = employeeKey == null ? tblLocation.EmployeeID : employeeKey.EmployeeKey_Id;
            tblLocation.EntryDate  = tblLocation.EntryDate ?? DateTime.UtcNow.ConvertUTCToLocal();
            tblLocation.Street     = street;
            tblLocation.Row        = row;
            tblLocation.WHID       = location.Facility.WHID.Value;
            tblLocation.InActive   = !location.Active;
            tblLocation.FreezeRow  = location.Locked ? "Yes" : null;

            return(tblLocation);
        }
        public void Initialize()
        {
            string street;
            int    row;

            if (LocationDescriptionHelper.GetStreetRow(Description, out street, out row))
            {
                LocationDescription = string.Format("{0}{1}", street, row);
                Street = street;
                Row    = row;
            }
            else
            {
                LocationDescription = Description;
                Street = Description;
                Row    = 0;
            }
        }
            public void Updates_existing_tblProductionSchedule_record_as_expected()
            {
                //Arrange
                var productionSchedule = RVCUnitOfWork.ProductionScheduleRepository.Filter(p => p.ScheduledItems.Any(),
                                                                                           p => p.ProductionLineLocation,
                                                                                           p => p.ScheduledItems.Select(i => i.PackSchedule))
                                         .OrderByDescending(p => p.ProductionDate)
                                         .FirstOrDefault();

                if (productionSchedule == null)
                {
                    Assert.Inconclusive("No suitable ProductionSchedule to test.");
                }

                //Act
                var result = Service.UpdateProductionSchedule(new UpdateProductionScheduleParameters
                {
                    UserToken             = TestUser.UserName,
                    ProductionScheduleKey = productionSchedule.ToProductionScheduleKey(),
                    ScheduledItems        = productionSchedule.ScheduledItems.Select((i, n) => new SetProductionScheduleItemParameters
                    {
                        Index = n,
                        FlushBeforeInstructions = "testing old context sync",
                        PackScheduleKey         = i.ToPackScheduleKey()
                    }).ToList()
                });

                //Assert
                result.AssertSuccess();
                using (var oldContext = new RioAccessSQLEntities())
                {
                    string street;
                    int    row;
                    LocationDescriptionHelper.GetStreetRow(productionSchedule.ProductionLineLocation.Description, out street, out row);
                    var oldProductionSchedule = oldContext.tblProductionSchedules
                                                .Include(p => p.tblProductionScheduleGroups)
                                                .FirstOrDefault(p => p.ProductionDate == productionSchedule.ProductionDate && p.LineNumber == row);
                    foreach (var item in productionSchedule.ScheduledItems)
                    {
                        var oldItem = oldProductionSchedule.tblProductionScheduleGroups.FirstOrDefault(g => g.PSNum == item.PackSchedule.PSNum);
                        Assert.AreEqual("testing old context sync", oldItem.FlushBeforeInstructions);
                    }
                }
            }
Example #11
0
 public void Initialize()
 {
     ReportDateTime = DateTime.Now;
     Locations      = LocationsSelect
                      .Where(l => l.IsGroup(GroupName))
                      .Select(l =>
     {
         string street;
         int row;
         LocationDescriptionHelper.GetStreetRow(l.Location, out street, out row);
         return(new
         {
             Street = street,
             Row = row,
             Select = l
         });
     })
                      .OrderBy(l => l.Street).ThenBy(l => l.Row)
                      .Select(l => new InventoryCycleCountLocationReturn
     {
         Location  = LocationDescriptionHelper.FormatLocationDescription(l.Select.Location),
         Inventory = l.Select.InventorySelect.GroupBy(i => new
         {
             lotKey       = i.LotKeyReturn.ToLotKey(),
             productKey   = i.ProductSelect.ToProductKey(),
             packagingKey = i.PackagingSelect.ProductKeyReturn.ToProductKey(),
             treatmentKey = i.TreatmentSelect.InventoryTreatmentKeyReturn.ToInventoryTreatmentKey()
         }).Select(g => new InventoryCycleCountInventoryReturn
         {
             LotKey         = g.Key.lotKey,
             ProductionDate = g.First().ProductionDate,
             ProductCode    = g.First().ProductSelect.ProductCode,
             ProductName    = g.First().ProductSelect.ProductName,
             Packaging      = g.First().PackagingSelect.ProductName,
             Treatment      = g.First().TreatmentSelect.TreatmentNameShort,
             Quantity       = g.Sum(i => i.Quantity),
             Weight         = g.Sum(i => i.Weight)
         })
                     .OrderBy(i => i.LotKey)
                     .ToList()
     })
                      .ToList();
 }
        public ProductionRecap_Lot(ProductionRecapLot lot)
        {
            Name = lot.ChileProduct.ProductName;
            Lot  = lot.LotKey.LotKey;

            string street;
            int    row;

            Line = LocationDescriptionHelper.GetStreetRow(lot.ProductionLocation.Description, out street, out row) ? row.ToString() : lot.ProductionLocation.Description;

            Shift = lot.Shift;
            PSNum = lot.ProductionBatch != null && lot.ProductionBatch.PSNum != null?lot.ProductionBatch.PSNum.ToString() : "";

            BatchType      = lot.WorkType;
            LotStat        = lot.TestResult.ToString();
            TargetWeight   = (int)lot.TotalInputWeight;
            ProducedWeight = (int)lot.TotalOutputWeight;
            ProductionTime = lot.ProductionTime;
        }
        public void Works_as_expected()
        {
            Assert.AreEqual("Line~23", LocationDescriptionHelper.GetDescription("Line", 23));
            Assert.AreEqual("A~1", LocationDescriptionHelper.GetDescription("A", 1));

            string street;
            int    row;

            Assert.IsTrue(LocationDescriptionHelper.GetStreetRow("Line", out street, out row));
            Assert.AreEqual("Line", street);
            Assert.AreEqual(0, row);

            Assert.IsTrue(LocationDescriptionHelper.GetStreetRow("Line~23", out street, out row));
            Assert.AreEqual("Line", street);
            Assert.AreEqual(23, row);

            Assert.IsTrue(LocationDescriptionHelper.GetStreetRow("Line~Thing~23", out street, out row));
            Assert.AreEqual("Line~Thing", street);
            Assert.AreEqual(23, row);
        }