public void Creates_new_tblProduct_record_when_receiving_packaging_if_record_does_not_exist() { //Arrange var oldContext = new RioAccessSQLEntities(); var helper = new OldContextHelper(oldContext); var packagings = TestHelper.Context.PackagingProducts.Select(p => new { Packaging = p, p.Product }).ToList(); tblPackaging tblPackaging; var packaging = packagings.FirstOrDefault(p => helper.GetProductFromPackagingId(p.Product.ProductCode, out tblPackaging) == null); if (packaging == null) { Assert.Inconclusive("No suitable Packaging product for testing."); } var location = RVCUnitOfWork.LocationRepository.Filter(l => l.LocID != null).First(); var parameters = new ReceiveInventoryParameters { UserToken = TestUser.UserName, LotType = LotTypeEnum.Additive, ProductKey = new ProductKey((IProductKey)RVCUnitOfWork.AdditiveProductRepository.All().First()), PackagingReceivedKey = new PackagingProductKey(packaging.Packaging), Items = new List <ReceiveInventoryItemParameters> { new ReceiveInventoryItemParameters { Quantity = 1, PackagingProductKey = new PackagingProductKey(packaging.Packaging), WarehouseLocationKey = new LocationKey(location), TreatmentKey = new InventoryTreatmentKey(RVCUnitOfWork.InventoryTreatmentRepository.All().First()), ToteKey = "" }, } }; //Act var result = Service.ReceiveInventory(parameters); result.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); Assert.IsNotNull(oldContext.tblPackagings.Single(p => p.Packaging == packaging.Product.Name)); }
private tblProduct GetOrCreatePackagingProduct(PackagingProduct packagingProduct, IEmployeeKey employeeKey, DateTime timestamp) { tblPackaging tblPackaging; var product = _oldContextHelper.GetProductFromPackagingId(packagingProduct.Product.ProductCode, out tblPackaging); if (product == null) { product = new tblProduct { ProdID = _oldContextHelper.GetNextProductId(5), Product = packagingProduct.Product.Name, ProdGrpID = 98, PTypeID = 5, PkgID = tblPackaging == null ? (int?)null : tblPackaging.PkgID, TrtmtID = 0, EmployeeID = employeeKey.EmployeeKey_Id, EntryDate = timestamp.ConvertUTCToLocal(), InActive = false }; _oldContext.CreateObjectSet <tblProduct>().AddObject(product); } return(product); }
public void Creates_LotKey_as_expected() { //Arrange var oldContext = new RioAccessSQLEntities(); var helper = new OldContextHelper(oldContext); var packagings = TestHelper.Context.PackagingProducts.Select(p => new { Packaging = p, p.Product }).ToList(); tblPackaging tblPackaging; var packaging = packagings.FirstOrDefault(p => helper.GetProductFromPackagingId(p.Product.ProductCode, out tblPackaging) == null); if (packaging == null) { Assert.Inconclusive("No suitable Packaging product for testing."); } var location = RVCUnitOfWork.LocationRepository.Filter(l => l.LocID != null).First(); var lotDate = DateTime.Now.Date; var lotSequence = 42; var parameters = new ReceiveInventoryParameters { UserToken = TestUser.UserName, LotType = LotTypeEnum.Additive, LotDate = lotDate, LotSequence = lotSequence, ProductKey = new ProductKey((IProductKey)RVCUnitOfWork.AdditiveProductRepository.All().First()), PackagingReceivedKey = new PackagingProductKey(packaging.Packaging), Items = new List <ReceiveInventoryItemParameters> { new ReceiveInventoryItemParameters { Quantity = 1, PackagingProductKey = new PackagingProductKey(packaging.Packaging), WarehouseLocationKey = new LocationKey(location), TreatmentKey = new InventoryTreatmentKey(RVCUnitOfWork.InventoryTreatmentRepository.All().First()), ToteKey = "" }, } }; //Act var result = Service.ReceiveInventory(parameters); result.AssertSuccess(); var lotString = GetKeyFromConsoleString(ConsoleOutput.ReceivedInventory); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var newLot = int.Parse(lotString); var lotKey = LotNumberParser.ParseLotNumber(newLot); Assert.AreEqual((int)LotTypeEnum.Additive, lotKey.LotKey_LotTypeId); Assert.AreEqual(lotDate, lotKey.LotKey_DateCreated); Assert.AreEqual(lotSequence, lotKey.LotKey_DateSequence); var tblLot = oldContext.tblLots.FirstOrDefault(a => a.Lot == newLot); Assert.IsNotNull(tblLot); Assert.IsNotNull(oldContext.tblPackagings.Single(p => p.Packaging == packaging.Product.Name)); }