public void Creates_tblProduct_record_as_expected() { //Arrange int prodId; using (var context = new RioAccessSQLEntities()) { prodId = context.tblProducts.Select(p => p.ProdID).DefaultIfEmpty(0).Max() + 1; } //Act var parameters = new CreateProductParameters { UserToken = TestUser.UserName, ProductCode = prodId.ToString(), ProductName = "ProductNameTest" }; var result = Service.CreateNonInventoryProduct(parameters); //Assert result.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var resultString = GetKeyFromConsoleString(ConsoleOutput.SynchedTblProduct); prodId = int.Parse(resultString); using (var oldContext = new RioAccessSQLEntities()) { var tblProduct = oldContext.tblProducts.FirstOrDefault(p => p.ProdID == prodId); Assert.AreEqual(parameters.ProductName, tblProduct.Product); Assert.AreEqual(parameters.ProductCode, tblProduct.ProdID.ToString()); Assert.AreEqual(7, tblProduct.ProdGrpID); Assert.AreEqual(3, tblProduct.PTypeID); Assert.AreEqual(false, tblProduct.InActive); } }
public void Removes_tblMove_record_as_expected() { //Arrange var orders = RVCUnitOfWork.SalesOrderRepository.Filter(o => o.InventoryShipmentOrder.ShipmentInformation.Status != ShipmentStatus.Shipped && o.SalesOrderPickedItems.All(i => i.PickedInventoryItem.CurrentLocationId == i.PickedInventoryItem.FromLocationId)) .ToList(); var order = orders.FirstOrDefault(o => o.SalesOrderItems.Any() && o.SalesOrderPickedItems.Any()); if (order == null) { order = orders.FirstOrDefault(); if (order == null) { Assert.Inconclusive("Could not find CustomerOrder suitable for testing."); } } //Act var result = Service.DeleteSalesOrder(order.ToSalesOrderKey()); //Assert result.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var orderNumString = GetKeyFromConsoleString(ConsoleOutput.RemovedTblOrder); var orderNum = int.Parse(orderNumString); using (var oldContext = new RioAccessSQLEntities()) { var tblOrder = oldContext.tblOrders.FirstOrDefault(o => o.OrderNum == orderNum); Assert.IsNull(tblOrder); } }
public void Updates_tblOrder_record_as_expected() { //Arrange var order = RVCUnitOfWork.SalesOrderRepository.Filter(o => o.OrderStatus != SalesOrderStatus.Invoiced && o.InventoryShipmentOrder.ShipmentInformation.Status == ShipmentStatus.Shipped).FirstOrDefault(); if (order == null) { Assert.Inconclusive("No suitable order for testing."); } //Act var result = Service.PostInvoice(order.ToSalesOrderKey()); //Arrange result.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var orderNumString = GetKeyFromConsoleString(ConsoleOutput.InvoicedOrder); var orderNum = int.Parse(orderNumString); using (var oldContext = new RioAccessSQLEntities()) { var tblOrder = oldContext.tblOrders.FirstOrDefault(o => o.OrderNum == orderNum); Assert.AreEqual(tblOrderStatus.Invoiced, (tblOrderStatus)tblOrder.Status); } }
public void Deletes_tblContract_and_tblContractDetail_items_and_KillSwitch_will_not_have_been_engaged_if_service_method_and_synchronization_were_successful() { //Arrange var contract = RVCUnitOfWork.ContractRepository.All() .FirstOrDefault(c => c.ContractId != null && c.ContractItems.Any() && c.ContractItems.All(i => !i.OrderItems.Any())); if (contract == null) { Assert.Inconclusive("Could not find Contract record suitable for testing."); } //Act var result = Service.RemoveCustomerContract(new ContractKey(contract)); var contractKeyString = GetKeyFromConsoleString(ConsoleOutput.RemovedContract); //Assert result.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var contractId = int.Parse(contractKeyString); using (var oldContext = new RioAccessSQLEntities()) { Assert.IsNull(oldContext.tblContracts.FirstOrDefault(c => c.ContractID == contractId)); } }
public void Updates_tblContract_records_status_as_expected() { //Arrange var contracts = RVCUnitOfWork.ContractRepository.All() .Where(c => c.ContractStatus != ContractStatus.Rejected) .OrderByDescending(c => c.ContractDate).Take(3).ToList(); //Act var result = Service.SetCustomerContractsStatus(new SetContractsStatusParameters { ContractStatus = ContractStatus.Rejected, ContractKeys = contracts.Select(c => c.ToContractKey().KeyValue) }); var contractKeyString = GetKeyFromConsoleString(ConsoleOutput.SyncContractsStatus); //Assert result.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var ids = contractKeyString.Split(',').Select(c => int.Parse(c.Trim(' '))).ToArray(); using (var oldContext = new RioAccessSQLEntities()) { foreach (var id in ids) { Assert.AreEqual("Rejected", oldContext.tblContracts.FirstOrDefault(n => n.ContractID == id).KStatus); } } }
public void Creates_new_tblPackaging_record_as_expected() { //Arrange var parameters = new CreatePackagingProductParameters { UserToken = TestUser.UserName, ProductName = "Test Packaging Product", ProductCode = "123456", Weight = 1, PackagingWeight = 2, PalletWeight = 3 }; //Act var result = Service.CreatePackagingProduct(parameters); result.AssertSuccess(); var resultString = GetKeyFromConsoleString(ConsoleOutput.SynchedTblPackaging); //Assert MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var pkgId = int.Parse(resultString); using (var oldContext = new RioAccessSQLEntities()) { var tblProduct = oldContext.tblPackagings.FirstOrDefault(p => p.PkgID == pkgId); Assert.AreEqual(parameters.ProductName, tblProduct.Packaging); Assert.AreEqual(int.Parse(parameters.ProductCode), tblProduct.PkgID); Assert.AreEqual(parameters.Weight, tblProduct.NetWgt); Assert.AreEqual(parameters.PackagingWeight, tblProduct.PkgWgt); Assert.AreEqual(parameters.PalletWeight, tblProduct.PalletWgt); } }
public void Creates_new_tblQuote_record() { //Act var result = Service.SetSalesQuote(new SalesQuoteParameters { UserToken = TestUser.UserName, QuoteDate = new DateTime(2016, 1, 1), Items = new List <ISalesQuoteItemParameters> { new SalesQuoteItemParameters { CustomerProductCode = "code", ProductKey = RVCUnitOfWork.ProductRepository.SourceQuery.First().ToProductKey(), PackagingKey = RVCUnitOfWork.PackagingProductRepository.SourceQuery.First().ToPackagingProductKey(), TreatmentKey = RVCUnitOfWork.InventoryTreatmentRepository.SourceQuery.First().ToInventoryTreatmentKey(), Quantity = 1 } } }); //Assert result.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var quoteNumString = GetKeyFromConsoleString(ConsoleOutput.SyncTblQuote); var quoteNum = int.Parse(quoteNumString); using (var oldContext = new RioAccessSQLEntities()) { Assert.IsNotNull(oldContext.tblQuotes.FirstOrDefault(q => q.QuoteNum == quoteNum)); } }
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 Updates_existing_tblLot_record_and_KillSwitch_will_not_have_been_engaged_if_service_method_and_synchronization_were_successful() { //Arrange var chileLots = RVCUnitOfWork.ChileLotRepository.Filter(c => !c.Lot.LotDefects.Any() && c.ChileProduct.ProductAttributeRanges.Count() > 1, c => c.ChileProduct.ProductAttributeRanges) .OrderByDescending(c => c.LotDateCreated) .Take(3) .ToList(); if (chileLots.Count < 3) { throw new Exception("Could not find ChileLots with no defects."); } var attributes = StaticAttributeNames.AttributeNames.Select(n => new { nameKey = new AttributeNameKey(n), value = chileLots[0].ChileProduct.ProductAttributeRanges .Where(r => r.AttributeShortName == n.ShortName) .Select(r => (r.RangeMax * 2) + 1) .DefaultIfEmpty(0) .First() }).ToArray(); var dateTested = new DateTime(2029, 3, 30); //Act var result = Service.AddLotAttributes(new AddLotAttributesParameters { UserToken = TestUser.UserName, LotKeys = chileLots.Select(c => c.ToLotKey().KeyValue).ToArray(), Attributes = attributes.ToDictionary(a => a.nameKey.KeyValue, a => new AttributeValueParameters { AttributeInfo = new AttributeInfoParameters { Value = a.value, Date = dateTested }, } as IAttributeValueParameters) }); var lotString = GetKeyFromConsoleString(ConsoleOutput.UpdatedLot); //Assert result.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); foreach (var lot in lotString.Split(new [] { ", " }, StringSplitOptions.None)) { var newLot = int.Parse(lot); var tblLot = new RioAccessSQLEntities().tblLots.FirstOrDefault(a => a.Lot == newLot); foreach (var attribute in attributes) { var getter = tblLot.AttributeGet(attribute.nameKey); if (getter != null) { Assert.AreEqual((decimal?)attribute.value, getter()); } } } }
public SerializedData(RioAccessSQLEntities context) { if (context == null) { throw new ArgumentNullException("context"); } _context = context; }
public PackScheduleEntityObjectMother(RioAccessSQLEntities oldContext, RioValleyChiliDataContext newContext, Action <CallbackParameters> loggingCallback) : base(oldContext, loggingCallback) { _newContextHelper = new NewContextHelper(newContext); _packagingHelper = new PackSchedulePackagingHelper(oldContext.CreateObjectSet <tblPackaging>().ToList()); _notebookFactory = NotebookFactory.Create(newContext); _serializedData = new SerializedData(oldContext); }
public SetLotAttributes(RioAccessSQLEntities oldContext) { if (oldContext == null) { throw new ArgumentNullException("oldContext"); } _oldContext = oldContext; }
public void Removes_tblOrderDetail_record_as_expected() { //Arrange var customer = RVCUnitOfWork.CustomerRepository.All().FirstOrDefault(); var contractItem = RVCUnitOfWork.ContractItemRepository.All().FirstOrDefault(i => i.Contract.CustomerId == customer.Id); var inventory = RVCUnitOfWork.InventoryRepository.Filter(i => i.LotTypeId == (decimal)LotTypeEnum.FinishedGood && i.Lot.ProductionStatus == LotProductionStatus.Produced && i.Lot.QualityStatus == LotQualityStatus.Released, i => i.Location.Facility) .FirstOrDefault(); if (inventory == null) { Assert.Inconclusive("No valid test inventory found."); } var sourceFacility = inventory.Location.Facility; var parameters = TestHelper.CreateObjectGraph <CreateSalesOrderParameters>(); parameters.UserToken = TestUser.UserName; parameters.CustomerKey = customer.ToCustomerKey(); parameters.FacilitySourceKey = sourceFacility.ToFacilityKey(); parameters.OrderItems = new List <SalesOrderItemParameters> { new SalesOrderItemParameters { ContractItemKey = contractItem.ToContractItemKey(), ProductKey = contractItem.ToChileProductKey(), PackagingKey = contractItem.ToPackagingProductKey(), TreatmentKey = contractItem.ToInventoryTreatmentKey(), Quantity = 123, CustomerLotCode = "LotCode", PriceBase = 1, PriceFreight = 2, PriceTreatment = 3, PriceWarehouse = 4, PriceRebate = 5 } }; //Act / Assert var createResult = Service.CreateSalesOrder(parameters); createResult.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var orderNumString = GetKeyFromConsoleString(ConsoleOutput.SyncTblOrder); var orderNum = int.Parse(orderNumString); using (var oldContext = new RioAccessSQLEntities()) { var tblOrder = oldContext.tblOrders .Include("tblOrderDetails") .FirstOrDefault(o => o.OrderNum == orderNum); Assert.AreEqual(1, tblOrder.tblOrderDetails.Count()); } }
public void Updates_existing_tblLot_record_and_KillSwitch_will_not_have_been_engaged_if_service_method_and_synchronization_were_successful() { //Arrange var production = RVCUnitOfWork.ChileLotProductionRepository.FindBy(c => c.ProductionType == ProductionType.MillAndWetdown && c.Results.ShiftKey != "UpdateTest" && c.Results.ResultItems.All(i => i.ProductionResults.Production.ResultingChileLot.Lot.Inventory.Any(n => n.PackagingProductId == i.PackagingProductId && n.LocationId == i.LocationId && n.Quantity >= i.Quantity)), c => c.ResultingChileLot); if (production == null) { Assert.Inconclusive("No suitable Mill and Wetdown record found for testing."); } var productionDate = DateTime.Now.Date; var productionLine = RVCUnitOfWork.LocationRepository.Filter(l => l.LocationType == LocationType.ProductionLine).First(); var pickedInventory = RVCUnitOfWork.InventoryRepository.Filter(i => i.Lot.Hold == null && i.Lot.QualityStatus == LotQualityStatus.Released && i.Location.Facility.Name.Contains("rincon")).First(); var warehouseLocation = RVCUnitOfWork.LocationRepository.Filter(l => l.LocID != null).First(); var packagingProduct = RVCUnitOfWork.PackScheduleRepository.All().First(); //Act var result = Service.UpdateMillAndWetdown(new UpdateMillAndWetdownParameters { UserToken = TestUser.UserName, LotKey = production.ToLotKey(), ChileProductKey = production.ResultingChileLot.ToChileProductKey(), ShiftKey = "UpdateTest", ProductionLineKey = productionLine.ToLocationKey(), ProductionBegin = productionDate.AddDays(-1), ProductionEnd = productionDate.AddHours(12), PickedItems = new[] { new MillAndWetdownPickedItemParameters { InventoryKey = pickedInventory.ToInventoryKey(), Quantity = pickedInventory.Quantity } }, ResultItems = new[] { new MillAndWetdownResultItemParameters { PackagingProductKey = packagingProduct.ToPackagingProductKey(), LocationKey = warehouseLocation.ToLocationKey(), Quantity = 10 } } }); result.AssertSuccess(); var lotString = GetKeyFromConsoleString(ConsoleOutput.UpdatedLot); //Assert MockKillSwitch.Verify(k => k.Engage(), Times.Never()); using (var context = new RioAccessSQLEntities()) { var lot = int.Parse(lotString); Assert.IsNotNull(context.tblLots.FirstOrDefault(t => t.Lot == lot)); } }
public DeleteTblLotHelper(RioAccessSQLEntities oldContext) { if (oldContext == null) { throw new ArgumentNullException("oldContext"); } _oldContext = oldContext; _serializedData = new SerializedData(_oldContext); }
private static void LoadLots(RioValleyChiliDataContext newContext, RioAccessSQLEntities oldContext, ConsoleTicker consoleTicker) { StartWatch(); var lots = new List <Lot>(); var chileLots = new List <ChileLot>(); var additiveLots = new List <AdditiveLot>(); var packagingLots = new List <PackagingLot>(); var lotAttributes = new List <LotAttribute>(); var lotDefects = new List <LotDefect>(); var lotAttributeDefects = new List <LotAttributeDefect>(); var lotDefectResolutions = new List <LotDefectResolution>(); ProcessedBirth(new LotEntityObjectMother(oldContext, newContext, RVCDataLoadLoggerGate.LotLoadLoggerCallback), "Loading Lots", consoleTicker, lotResult => { if (lotResult.ChileLot != null) { chileLots.Add(lotResult.ChileLot); lots.Add(lotResult.ChileLot.Lot); lotAttributes.AddRange(lotResult.ChileLot.Lot.Attributes); if (lotResult.ChileLot.Lot.LotDefects != null) { lotDefects.AddRange(lotResult.ChileLot.Lot.LotDefects); lotDefectResolutions.AddRange(lotResult.ChileLot.Lot.LotDefects.Select(d => d.Resolution).Where(r => r != null)); } } else if (lotResult.AdditiveLot != null) { additiveLots.Add(lotResult.AdditiveLot); lots.Add(lotResult.AdditiveLot.Lot); lotAttributes.AddRange(lotResult.AdditiveLot.Lot.Attributes); } else if (lotResult.PackagingLot != null) { packagingLots.Add(lotResult.PackagingLot); lots.Add(lotResult.PackagingLot.Lot); } if (lotResult.LotAttributeDefects != null) { lotAttributeDefects.AddRange(lotResult.LotAttributeDefects); } }); consoleTicker.ReplaceCurrentLine("Loading Lots"); LoadRecords(newContext, lots, "\tlots", consoleTicker); LoadRecords(newContext, chileLots, "\tchile lots", consoleTicker); LoadRecords(newContext, lotAttributes, "\tchile lot attributes", consoleTicker); LoadRecords(newContext, additiveLots, "\tadditive lots", consoleTicker); LoadRecords(newContext, packagingLots, "\tpackaging lots", consoleTicker); LoadRecords(newContext, lotDefects, "\tlot defects", consoleTicker); LoadRecords(newContext, lotDefectResolutions, "\tlot defect resolutions", consoleTicker); LoadRecords(newContext, lotAttributeDefects, "\tlot attribute defects", consoleTicker); consoleTicker.WriteTimeElapsed(StopWatch()); }
public void Creates_new_tblLot_and_tblIncoming_records_and_KillSwitch_will_not_have_been_engaged_if_service_method_and_synchronization_were_successful() { //Arrange var packaging = RVCUnitOfWork.PackagingProductRepository.All().First(); var locations = RVCUnitOfWork.LocationRepository.Filter(l => l.LocID != null).Take(2).ToList(); var parameters = new ReceiveInventoryParameters { UserToken = TestUser.UserName, LotType = LotTypeEnum.Additive, ProductKey = new ProductKey((IProductKey)RVCUnitOfWork.AdditiveProductRepository.All().First()), PackagingReceivedKey = new PackagingProductKey(packaging), Items = new List <ReceiveInventoryItemParameters> { new ReceiveInventoryItemParameters { Quantity = 1, PackagingProductKey = new PackagingProductKey(packaging), WarehouseLocationKey = new LocationKey(locations[0]), TreatmentKey = new InventoryTreatmentKey(RVCUnitOfWork.InventoryTreatmentRepository.All().First()), ToteKey = "TOTE" }, new ReceiveInventoryItemParameters { Quantity = 2, PackagingProductKey = new PackagingProductKey(packaging), WarehouseLocationKey = new LocationKey(locations[1]), TreatmentKey = new InventoryTreatmentKey(RVCUnitOfWork.InventoryTreatmentRepository.All().First()) } } }; //Act var result = Service.ReceiveInventory(parameters); var lotString = GetKeyFromConsoleString(ConsoleOutput.ReceivedInventory); //Assert result.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var newLot = int.Parse(lotString); var oldContext = new RioAccessSQLEntities(); var tblLot = oldContext.tblLots.FirstOrDefault(a => a.Lot == newLot); Assert.IsNotNull(tblLot); var tblIncoming = oldContext.tblIncomings.Where(i => i.Lot == newLot).ToList(); Assert.AreEqual(parameters.Items.Count(), tblIncoming.Count); foreach (var item in parameters.Items) { Assert.AreEqual(1, tblIncoming.Count(i => i.Quantity == item.Quantity)); } }
public void Sets_tblProductIngrs_records_as_expected() { //Arrange var chileProduct = RVCUnitOfWork.ChileProductRepository .FindBy(c => c.Product.ProductCode != null && c.Ingredients.Count > 1, c => c.Ingredients); if (chileProduct == null) { Assert.Inconclusive("No suitable ChileProduct found to test."); } var except = chileProduct.Ingredients.Where((i, n) => n > 0).Select(i => i.AdditiveTypeId).ToList(); var additiveTypes = chileProduct.Ingredients.Where((i, n) => n == 0) .Select(n => n.ToAdditiveTypeKey()) .Concat(RVCUnitOfWork.AdditiveTypeRepository .All().ToList() .Where(a => !except.Contains(a.Id)) .Take(2) .ToList() .Select(a => a.ToAdditiveTypeKey())); //Act var ingredients = additiveTypes.Select((a, n) => new { additiveType = a, parameters = new SetChileProductIngredientParameters { AdditiveTypeKey = a, Percentage = (n + 1) / 10.0f } }).ToList(); var result = Service.SetChileProductIngredients(new SetChileProductIngredientsParameters { UserToken = TestUser.UserName, ChileProductKey = chileProduct.ToChileProductKey(), Ingredients = ingredients.Select(i => i.parameters).ToList() }); result.AssertSuccess(); var resultString = GetKeyFromConsoleString(ConsoleOutput.SynchedTblProduct); //Assert MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var prodId = int.Parse(resultString); using (var oldContext = new RioAccessSQLEntities()) { var tblProductIngrs = oldContext.tblProductIngrs.Where(i => i.ProdID == prodId).ToList(); foreach (var ingredient in ingredients) { Assert.AreEqual(ingredient.parameters.Percentage, (double)tblProductIngrs.Single(i => i.IngrID == ingredient.additiveType.AdditiveTypeKey_AdditiveTypeId).Percentage, 0.01); } } }
public void Updates_MiscInvoice_as_expected() { //Arrange var order = TestHelper.Context.Set <SalesOrder>() .Include ( o => o.Customer.Company, o => o.InventoryShipmentOrder.SourceFacility ) .FirstOrDefault(o => o.InventoryShipmentOrder.OrderType == InventoryShipmentOrderTypeEnum.MiscellaneousOrder && o.Customer == null); var packaging = TestHelper.Context.PackagingProducts.FirstOrDefault(); var product = TestHelper.Context.Products.FirstOrDefault(p => p.ProductType == ProductTypeEnum.NonInventory); var treatment = TestHelper.Context.Set <InventoryTreatment>().FirstOrDefault(); //Act var result = Service.UpdateSalesOrder(new UpdateSalesOrderParameters { SalesOrderKey = order.ToSalesOrderKey(), UserToken = TestUser.UserName, FacilitySourceKey = order.InventoryShipmentOrder.SourceFacility.ToFacilityKey(), HeaderParameters = new SetOrderHeaderParameters(), OrderItems = new List <SalesOrderItemParameters> { new SalesOrderItemParameters { ProductKey = product.ToProductKey(), PackagingKey = packaging.ToPackagingProductKey(), TreatmentKey = treatment.ToInventoryTreatmentKey(), Quantity = 1 } } }); //Assert result.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var orderNumString = GetKeyFromConsoleString(ConsoleOutput.SyncTblOrder); var orderNum = int.Parse(orderNumString); using (var oldContext = new RioAccessSQLEntities()) { var tblOrder = oldContext.tblOrders.AsQueryable() .Include(o => o.tblOrderDetails) .FirstOrDefault(o => o.OrderNum == orderNum); Assert.AreEqual((int)TransType.MiscInvoice, tblOrder.TTypeID); Assert.IsNull(tblOrder.Company_IA); var tblOrderDetail = tblOrder.tblOrderDetails.Single(); Assert.AreEqual(int.Parse(product.ProductCode), tblOrderDetail.ProdID); Assert.IsNull(tblOrderDetail.KDetailID); } }
public void Updates_tblProduct_record_as_expected() { //Arrange var range = RVCUnitOfWork.ChileProductAttributeRangeRepository.FindBy(r => r.AttributeShortName == StaticAttributeNames.Asta.ShortName); if (range == null) { Assert.Inconclusive("No suitable ChileProductAttributeRange to test."); } var asta = new SetAttributeRangeParameters { AttributeNameKey = range.ToAttributeNameKey(), RangeMin = range.RangeMin == 1 ? 2 : 1, RangeMax = range.RangeMax == 333 ? 444 : 333 }; var gran = new SetAttributeRangeParameters { AttributeNameKey = StaticAttributeNames.Granularity.ToAttributeNameKey(), RangeMin = 101, RangeMax = 102 }; var parameters = new SetChileProductAttributeRangesParameters { UserToken = TestUser.UserName, ChileProductKey = range.ToChileProductKey(), AttributeRanges = new List <ISetAttributeRangeParameters> { asta, gran, } }; //Act var result = Service.SetChileProductAttributeRanges(parameters); result.AssertSuccess(); var resultString = GetKeyFromConsoleString(ConsoleOutput.SynchedTblProduct); //Assert MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var prodId = int.Parse(resultString); using (var oldContext = new RioAccessSQLEntities()) { var tblProduct = oldContext.tblProducts.FirstOrDefault(p => p.ProdID == prodId); Assert.AreEqual(asta.RangeMin, tblProduct.AstaStart); Assert.AreEqual(asta.RangeMax, tblProduct.AstaEnd); Assert.AreEqual(gran.RangeMin, tblProduct.GranStart); Assert.AreEqual(gran.RangeMax, tblProduct.GranEnd); } }
public void Modifies_existing_tblLot_and_tblIncoming_records_as_expected() { //Arrange const string expectedPurchaseOrder = "testing"; var inventory = RVCUnitOfWork.InventoryRepository.All(); var received = RVCUnitOfWork.ChileMaterialsReceivedRepository .Filter(d => d.Items.Count > 1 && d.ChileLot.Lot.PurchaseOrderNumber != expectedPurchaseOrder && d.Items.All(i => inventory.Any(n => n.LotDateCreated == i.LotDateCreated && n.LotDateSequence == i.LotDateSequence && n.LotTypeId == i.LotTypeId && n.Quantity >= i.Quantity && n.PackagingProductId == i.PackagingProductId && n.LocationId == i.LocationId && n.ToteKey == i.ToteKey && n.TreatmentId == StaticInventoryTreatments.NoTreatment.Id)), r => r.ChileLot.Lot, r => r.Employee, d => d.Items) .FirstOrDefault(); if (received == null) { Assert.Inconclusive("Could not find suitable ChileMaterialsReceived record for testing."); } var parameters = new ChileMaterialsReceivedParameters(received) { PurchaseOrder = expectedPurchaseOrder }; var quantity = 1; parameters.Items.ForEach(i => i.Quantity = quantity++); parameters.Items.RemoveAt(1); //Act var result = Service.UpdateChileMaterialsReceived(parameters); result.AssertSuccess(); var lotString = GetKeyFromConsoleString(ConsoleOutput.SyncDehydratedReceived); //Assert MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var lotNumber = int.Parse(lotString); var lot = new RioAccessSQLEntities().tblLots .Select(l => new { lot = l, incoming = l.tblIncomings }) .FirstOrDefault(t => t.lot.Lot == lotNumber); Assert.AreEqual(expectedPurchaseOrder, lot.lot.PurchOrder); var resultItems = lot.incoming.ToList(); parameters.Items.AssertEquivalent(resultItems, e => new { e.Quantity }, r => new { Quantity = (int)r.Quantity }, (e, r) => Assert.AreEqual(parameters.TreatmentKey, r.TrtmtID.ToString())); }
public void Creates_new_SerializedCustomerProdSpecs_record_and_KillSwitch_will_not_have_been_engaged_if_service_method_and_synchronization_were_successful() { //Arrange var customer = RVCUnitOfWork.CustomerRepository.Filter(c => !c.ProductSpecs.Any(), c => c.Company).FirstOrDefault(); if (customer == null) { Assert.Inconclusive("No Customer without ProductSpecs found."); } var chileProduct = RVCUnitOfWork.ChileProductRepository.Filter(c => true, c => c.Product).FirstOrDefault(); if (chileProduct == null) { Assert.Inconclusive("No ChileProduct found."); } var attribute = RVCUnitOfWork.AttributeNameRepository.All().FirstOrDefault(); if (attribute == null) { Assert.Inconclusive("No AttributeName found."); } //Act var result = Service.SetCustomerChileProductAttributeRanges(new SetCustomerProductAttributeRangesParameters { UserToken = TestUser.UserName, CustomerKey = customer.ToCustomerKey(), ChileProductKey = chileProduct.ToChileProductKey(), AttributeRanges = new List <ISetCustomerProductAttributeRangeParameters> { new SetCustomerProductAttributeRangeParameters { AttributeNameKey = attribute.ToAttributeNameKey(), RangeMin = 1.0f, RangeMax = 2.0f } } }); //Assert result.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); using (var oldContext = new RioAccessSQLEntities()) { var prodId = int.Parse(chileProduct.Product.ProductCode); var specs = oldContext.SerializedCustomerProdSpecs.First(s => s.ProdID == prodId && s.Company_IA == customer.Company.Name); Assert.IsFalse(string.IsNullOrWhiteSpace(specs.Serialized)); } }
private static void LoadChileMaterialsReceived(RioAccessSQLEntities oldContext, RioValleyChiliDataContext newContext, ConsoleTicker consoleTicker) { StartWatch(); var chileMaterialsReceived = Birth(new ChileMaterialsReceivedEntityMother(oldContext, newContext, RVCDataLoadLoggerGate.DehydratedMaterialsReceivedLoadLoggerCallback), "Loading Chile Materials Received", consoleTicker); consoleTicker.ReplaceCurrentLine("Loading Chile Materials Received"); LoadRecords(newContext, chileMaterialsReceived, "\tchile materials received", consoleTicker); LoadRecords(newContext, chileMaterialsReceived.SelectMany(d => d.Items), "\tchile materials received items", consoleTicker); consoleTicker.WriteTimeElapsed(StopWatch()); }
private PickedInventoryKeyHelper(RioAccessSQLEntities oldContext) { var customerOrderKey = new SalesOrderKey(); foreach (var reservedKey in oldContext.tblOrders.Where(o => o.SerializedKey != null).Select(o => o.SerializedKey)) { ISalesOrderKey parsedKey; if (customerOrderKey.TryParse(reservedKey, out parsedKey)) { GetRange(parsedKey.SalesOrderKey_DateCreated).RegisterSequence(parsedKey.SalesOrderKey_Sequence); } } }
public void Creates_new_tblOrder_record() { //Arrange var customer = RVCUnitOfWork.CustomerRepository.All().FirstOrDefault(); var contractItem = RVCUnitOfWork.ContractItemRepository.All().FirstOrDefault(i => i.Contract.CustomerId == customer.Id); var sourceFacility = RVCUnitOfWork.FacilityRepository.All().FirstOrDefault(); RVCUnitOfWork.FacilityRepository.Filter(f => f.Id != sourceFacility.Id).FirstOrDefault(); var parameters = TestHelper.CreateObjectGraph <CreateSalesOrderParameters>(); parameters.UserToken = TestUser.UserName; parameters.CustomerKey = new CustomerKey((ICustomerKey)customer); parameters.FacilitySourceKey = new FacilityKey(sourceFacility); parameters.OrderItems = new List <SalesOrderItemParameters> { new SalesOrderItemParameters { ContractItemKey = contractItem.ToContractItemKey(), ProductKey = contractItem.ToChileProductKey(), PackagingKey = contractItem.ToPackagingProductKey(), TreatmentKey = contractItem.ToInventoryTreatmentKey(), Quantity = 123, CustomerLotCode = "LotCode", PriceBase = 1, PriceFreight = 2, PriceTreatment = 3, PriceWarehouse = 4, PriceRebate = 5 } }; //Act var result = Service.CreateSalesOrder(parameters); //Assert result.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var orderNumString = GetKeyFromConsoleString(ConsoleOutput.SyncTblOrder); var orderNum = int.Parse(orderNumString); using (var oldContext = new RioAccessSQLEntities()) { var tblOrder = oldContext.tblOrders .Include("tblOrderDetails") .FirstOrDefault(o => o.OrderNum == orderNum); Assert.IsNotNull(tblOrder); Assert.IsNotNull(tblOrder.tblOrderDetails.First()); } }
void IDisposable.Dispose() { if (_oldContext != null) { _oldContext.Dispose(); _oldContext = null; } if (_newContext != null) { _newContext.Dispose(); _newContext = null; } }
public ProductionBatchEntityObjectMother(RioAccessSQLEntities oldContext, RioValleyChiliDataContext newContext, Action <CallbackParameters> loggingCallback) : base(oldContext, loggingCallback) { if (newContext == null) { throw new ArgumentNullException("newContext"); } _newContextHelper = new NewContextHelper(newContext); _serializedData = new SerializedData(oldContext); _productionResultHelper = new ProductionResultHelper(_newContextHelper, _serializedData); _pickedInventoryItemLocationHelper = new PickedInventoryItemLocationHelper(_newContextHelper); _notebookFactory = NotebookFactory.Create(newContext); }
private static void LoadInventory(RioValleyChiliDataContext newContext, RioAccessSQLEntities oldContext, ConsoleTicker consoleTicker) { StartWatch(); Console.WriteLine("Loading Inventory"); LoadRecords(newContext, new AdditiveLotInventoryEntityObjectMother(oldContext, newContext, RVCDataLoadLoggerGate.AdditiveLotInventoryLoadLogger), "\tAdditive", consoleTicker); LoadRecords(newContext, new PackagingLotInventoryItemEntityObjectMother(oldContext, newContext, RVCDataLoadLoggerGate.PackagingLotInventoryLoadLogger), "\tPackaging", consoleTicker); LoadRecords(newContext, new WIPChileLotInventoryItemEntityObjectMother(oldContext, newContext, RVCDataLoadLoggerGate.WIPChileLotInventoryLoadLogger), "\tChile WIP", consoleTicker); LoadRecords(newContext, new FinishedGoodsChileLotInventoryItemEntityObjectMother(oldContext, newContext, RVCDataLoadLoggerGate.FinishedGoodsChileLotInventoryLoadLogger), "\tChile Finished Goods", consoleTicker); LoadRecords(newContext, new DehyChileLotInventoryItemEntityObjectMother(oldContext, newContext, RVCDataLoadLoggerGate.DehyChileLotInventoryLoadLogger), "\tChile Dehydrated", consoleTicker); LoadRecords(newContext, new RawChileLotInventoryItemEntityObjectMother(oldContext, newContext, RVCDataLoadLoggerGate.RawChileLotInventoryLoadLogger), "\tChile Raw", consoleTicker); LoadRecords(newContext, new OtherChileLotInventoryItemEntityObjectMother(oldContext, newContext, RVCDataLoadLoggerGate.OtherChileLotInventoryLoadLogger), "\tChile Other", consoleTicker); LoadRecords(newContext, new GRPChileLotInventoryItemEntityObjectMother(oldContext, newContext, RVCDataLoadLoggerGate.GRPChileLotInventoryLoadLogger), "\tChile GRP", consoleTicker); consoleTicker.WriteTimeElapsed(StopWatch()); }
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 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); }