public AdditiveLot GetAdditiveLotWithProduct(LotKey lotKey) { AdditiveLot additiveLot; AdditiveLotsWithProduct.TryGetValue(lotKey, out additiveLot); return(additiveLot); }
public void Creates_new_Inventory_record_as_expected_if_Adjustment_quantity_is_positive_and_Inventory_record_does_not_previously_exist() { //Arrange const int adjustmentQuantity = 12; const string toteKey = ""; var userToken = TestUser.UserName; var lotKey = new LotKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Lot>(l => l.EmptyLot())); var packagingProductKey = new PackagingProductKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PackagingProduct>()); var warehouseLocationKey = new LocationKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Location>()); var treatmentKey = new InventoryTreatmentKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <InventoryTreatment>()); var inventoryKey = new InventoryKey(lotKey, packagingProductKey, warehouseLocationKey, treatmentKey, toteKey); //Act var result = Service.CreateInventoryAdjustment(new Params { UserToken = userToken, InventoryAdjustments = new List <IInventoryAdjustmentParameters> { new Params.ParamsItem(inventoryKey) { Adjustment = adjustmentQuantity } } }); //Assert result.AssertSuccess(); Assert.AreEqual(adjustmentQuantity, RVCUnitOfWork.InventoryRepository.FindByKey(inventoryKey).Quantity); }
public PackagingLot GetPackagingLotWithProduct(LotKey lotKey) { PackagingLot packagingLot; PackagingLotsWithProduct.TryGetValue(lotKey, out packagingLot); return(packagingLot); }
public IResult <ILotQualitySingleSummaryReturn> GetLot(string lotKey) { if (lotKey == null) { throw new ArgumentNullException("lotKey"); } var lotKeyResult = KeyParserHelper.ParseResult <ILotKey>(lotKey); if (!lotKeyResult.Success) { return(lotKeyResult.ConvertTo <ILotQualitySingleSummaryReturn>()); } var predicate = new LotKey(lotKeyResult.ResultingObject).FindByPredicate; var select = LotProjectors.SplitSelectSingleLotSummary(_lotUnitOfWork, _timeStamper.CurrentTimeStamp); var lotSummary = _lotUnitOfWork.LotRepository .Filter(predicate) .SplitSelect(select) .ToList().SingleOrDefault(); if (lotSummary == null) { return(new InvalidResult <ILotQualitySingleSummaryReturn>(null, string.Format(UserMessages.LotNotFound, lotKey))); } return(new SuccessResult <ILotQualitySingleSummaryReturn>(lotSummary)); }
public ChileLot GetChileLot(LotKey lotKey) { ChileLot chileLot; ChileLots.TryGetValue(lotKey, out chileLot); return(chileLot); }
public IResult <IMillAndWetdownDetailReturn> GetMillAndWetdownDetail(string lotKey) { if (lotKey == null) { throw new ArgumentNullException("lotKey"); } var keyResult = KeyParserHelper.ParseResult <ILotKey>(lotKey); if (!keyResult.Success) { return(keyResult.ConvertTo <IMillAndWetdownDetailReturn>()); } var predicate = new LotKey(keyResult.ResultingObject).GetPredicate <ChileLotProduction>().And(c => c.ProductionType == ProductionType.MillAndWetdown); var select = ChileLotProductionProjectors.SelectDetail(_productionUnitOfWork); var entry = _productionUnitOfWork.ChileLotProductionRepository.Filter(predicate).AsExpandable().Select(select).FirstOrDefault(); if (entry == null) { return(new InvalidResult <IMillAndWetdownDetailReturn>(null, string.Format(UserMessages.MillAndWetdownEntryNotFound, lotKey))); } return(new SuccessResult <IMillAndWetdownDetailReturn>(entry)); }
internal static void AssertEqual(this ProductionBatch productionBatch, IProductionResultSummaryReturn summaryReturn) { if (productionBatch == null) { throw new ArgumentNullException("productionBatch"); } if (summaryReturn == null) { throw new ArgumentNullException("summaryReturn"); } var productionResult = productionBatch.Production.Results; var lotKeyValue = new LotKey(productionResult).KeyValue; Assert.AreEqual(lotKeyValue, summaryReturn.ProductionResultKey); Assert.AreEqual(lotKeyValue, summaryReturn.ProductionBatchKey); Assert.AreEqual(lotKeyValue, summaryReturn.OutputLotNumber); Assert.AreEqual(new LocationKey(productionResult).KeyValue, summaryReturn.ProductionLineKey); Assert.AreEqual(new ChileProductKey(productionResult.Production.ResultingChileLot).KeyValue, summaryReturn.ChileProductKey); Assert.AreEqual(productionResult.Production.ResultingChileLot.ChileProduct.Product.Name, summaryReturn.ChileProductName); Assert.AreEqual(productionBatch.TargetParameters.BatchTargetWeight, summaryReturn.TargetBatchWeight); Assert.AreEqual(productionResult.ShiftKey, summaryReturn.ProductionShiftKey); Assert.AreEqual(productionBatch.PackSchedule.WorkType.Description, summaryReturn.WorkType); if (productionBatch.ProductionHasBeenCompleted) { Assert.AreEqual("Completed", summaryReturn.BatchStatus); } else { Assert.AreEqual("NotCompleted", summaryReturn.BatchStatus); } }
private List <LotAttribute> UpdateNewLotAttributes(LotKey lotKey) { var predicate = ((IKey <ProductionBatch>)lotKey).FindByPredicate; var batch = _newContext.ProductionBatches .Include ( b => b.Production.ResultingChileLot.Lot.Attributes.Select(a => a.AttributeName), b => b.Production.PickedInventory.Items ) .FirstOrDefault(predicate); if (batch == null) { throw new Exception(string.Format("Could not find ProductionBatch[{0}]", lotKey.KeyValue)); } if (!batch.Production.PickedInventory.Items.Any()) { Console.WriteLine("No picked items for this lot. Skipping."); return(null); } var result = new SetLotWeightedAttributesConductor(new EFRVCUnitOfWork(_newContext)).Execute(batch.Production.ResultingChileLot, batch.Production.PickedInventory.Items.ToList()); if (!result.Success) { throw new Exception(result.Message); } return(batch.Production.ResultingChileLot.Lot.Attributes.ToList()); }
internal IResult <IQueryable <ProductionResultReturn> > Execute(LotKey productionResultKey, bool includeDetails) { var batches = _productionUnitOfWork.ProductionBatchRepository.All(); var predicate = (productionResultKey == null ? r => true : productionResultKey.GetPredicate <LotProductionResults>()).And(r => r.Production.ProductionType == ProductionType.ProductionBatch).ExpandAll(); var selector = includeDetails ? LotProductionResultsProjectors.SplitSelectDetail(batches) : LotProductionResultsProjectors.SplitSelectSummary(batches); return(new SuccessResult <IQueryable <ProductionResultReturn> >(_productionUnitOfWork.LotProductionResultsRepository.Filter(predicate).SplitSelect(selector))); }
internal IResult <ResultReason> Execute(LotKey lotKey) { if (lotKey == null) { throw new ArgumentNullException("lotKey"); } var productionBatch = UnitOfWork.ProductionBatchRepository.FindByKey(lotKey, b => b.InstructionNotebook, b => b.InstructionNotebook.Notes, b => b.Production.PickedInventory, b => b.Production.PickedInventory.Items.Select(i => i.CurrentLocation), b => b.Production.Results); if (productionBatch == null) { return(new InvalidResult(string.Format(UserMessages.ProductionBatchNotFound, lotKey.KeyValue)).ConvertTo(new ResultReason(Reason.ProductionBatchNotFound, lotKey, null))); } var instructionNotebook = productionBatch.InstructionNotebook; var pickedInventory = productionBatch.Production.PickedInventory; var production = productionBatch.Production; if (productionBatch.ProductionHasBeenCompleted) { return(new InvalidResult(string.Format(UserMessages.ProductionBatchAlreadyComplete, lotKey.KeyValue)).ConvertTo(new ResultReason(Reason.ProductionBatchCompleted, lotKey, new LotKey(productionBatch)))); } if (productionBatch.Production.Results != null) { return(new InvalidResult(string.Format(UserMessages.ProductionBatchHasResult, lotKey.KeyValue)).ConvertTo(new ResultReason(Reason.ProductionBatchHasResults, lotKey, new LotKey(productionBatch)))); } var removeLotResult = new RemoveLotCommand(UnitOfWork).Execute(new LotKey(productionBatch)); if (!removeLotResult.Success) { return(removeLotResult.ConvertTo(new ResultReason(Reason.RemoveLotFailed, lotKey, new LotKey(productionBatch)))); } var removePickedItemsResult = UpdatePickedInventory(null, null, DateTime.UtcNow, pickedInventory, null); if (!removePickedItemsResult.Success) { return(removePickedItemsResult.ConvertTo(new ResultReason(Reason.RemovePickedItemFailed, lotKey, new LotKey(productionBatch)))); } UnitOfWork.ChileLotProductionRepository.Remove(production); UnitOfWork.PickedInventoryRepository.Remove(pickedInventory); foreach (var note in instructionNotebook.Notes.ToList()) { UnitOfWork.NoteRepository.Remove(note); } UnitOfWork.NotebookRepository.Remove(instructionNotebook); return(new SuccessResult().ConvertTo((ResultReason)null)); }
internal IResult Execute(DateTime timestamp, Employee employee, LotKey lotKey, LotQualityStatus status, bool forceResolveAllDefects = false) { var lot = _lotUnitOfWork.LotRepository.FindByKey(lotKey, l => l.ChileLot, l => l.Attributes.Select(a => a.AttributeName), l => l.LotDefects.Select(d => d.Resolution)); if (lot == null) { return(new InvalidResult(string.Format(UserMessages.LotNotFound, lotKey))); } var historyResult = new RecordLotHistoryCommand(_lotUnitOfWork).Execute(lot, timestamp); if (!historyResult.Success) { return(historyResult); } if (forceResolveAllDefects) { foreach (var defect in lot.LotDefects) { if (defect.Resolution == null) { defect.Resolution = new LotDefectResolution { EmployeeId = employee.EmployeeId, TimeStamp = timestamp, ResolutionType = ResolutionTypeEnum.AcceptedByUser, Description = "Forced acceptance by user." }; } } } if (lot.ChileLot != null) { var chileLot = _lotUnitOfWork.ChileLotRepository.FindByKey(lotKey, LotStatusHelper.ChileLotIncludePaths); if (chileLot == null) { return(new InvalidResult(string.Format(UserMessages.ChileLotNotFound, lotKey))); } if (!LotStatusHelper.GetValidLotQualityStatuses(chileLot).Contains(status)) { return(new InvalidResult(string.Format(UserMessages.CannotSetLotStatus, lotKey, chileLot.Lot.QualityStatus, status))); } } lot.QualityStatus = status; lot.EmployeeId = employee.EmployeeId; lot.TimeStamp = timestamp; return(new SuccessResult()); }
internal static IResult <SetSampleOrderItemParameters> ToParsedParameters(this ISampleOrderItemParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } SampleOrderItemKey itemKey = null; if (!string.IsNullOrWhiteSpace(parameters.SampleOrderItemKey)) { var itemKeyResult = KeyParserHelper.ParseResult <ISampleOrderItemKey>(parameters.SampleOrderItemKey); if (!itemKeyResult.Success) { return(itemKeyResult.ConvertTo <SetSampleOrderItemParameters>()); } itemKey = itemKeyResult.ResultingObject.ToSampleOrderItemKey(); } ProductKey productKey = null; if (!string.IsNullOrWhiteSpace(parameters.ProductKey)) { var chileProductKeyResult = KeyParserHelper.ParseResult <IProductKey>(parameters.ProductKey); if (!chileProductKeyResult.Success) { return(chileProductKeyResult.ConvertTo <SetSampleOrderItemParameters>()); } productKey = chileProductKeyResult.ResultingObject.ToProductKey(); } LotKey lotKey = null; if (!string.IsNullOrWhiteSpace(parameters.LotKey)) { var chileLotKeyResult = KeyParserHelper.ParseResult <ILotKey>(parameters.LotKey); if (!chileLotKeyResult.Success) { return(chileLotKeyResult.ConvertTo <SetSampleOrderItemParameters>()); } lotKey = chileLotKeyResult.ResultingObject.ToLotKey(); } return(new SuccessResult <SetSampleOrderItemParameters>(new SetSampleOrderItemParameters { Parameters = parameters, SampleOrderItemKey = itemKey, ProductKey = productKey, LotKey = lotKey })); }
private ChileLotProduction CreateChileLotProduction(LotKey lotKey, ProductionBatchDTO oldBatch, PackSchedule newPackSchedule, DateTime timeStamp, int employeeId) { _loadCount.AddRead(EntityTypes.ChileLotProduction); var chileLot = _newContextHelper.GetChileLot(lotKey); if (chileLot == null) { Log(new CallbackParameters(CallbackReason.OutputChileLotNotLoaded) { Batch = oldBatch }); return(null); } var pickedInventory = CreateNewPickedInventory(oldBatch); LotProductionResults productionResults; _productionResultHelper.CreateNewProductionResult(newPackSchedule, chileLot, oldBatch.ResultLot, out productionResults); if (productionResults != null) { _loadCount.AddRead(EntityTypes.LotProductionResults); productionResults.ResultItems = _productionResultHelper.CreateNewProductionResultItems(productionResults, oldBatch.ResultLot) .Where(r => { _loadCount.AddRead(EntityTypes.LotProductionResultItem); return(r.Result == ProductionResultHelper.CreateNewProductionResultItemResult.Success); }) .Select(i => i.ResultItem).ToList(); } var deserializedProduction = _serializedData.GetDeserialized <SerializableEmployeeIdentifiable>(SerializableType.ChileLotProduction, oldBatch.ResultLot.Lot.ToString()); pickedInventory.Archived = productionResults != null; return(new ChileLotProduction { TimeStamp = deserializedProduction == null ? timeStamp : deserializedProduction.TimeStamp, EmployeeId = deserializedProduction == null ? employeeId : deserializedProduction.EmployeeKey.EmployeeKeyId, LotDateCreated = chileLot.LotDateCreated, LotDateSequence = chileLot.LotDateSequence, LotTypeId = chileLot.LotTypeId, PickedInventoryDateCreated = pickedInventory.DateCreated, PickedInventorySequence = pickedInventory.Sequence, ProductionType = ProductionType.ProductionBatch, PickedInventory = pickedInventory, Results = productionResults }); }
public void Returns_detail_with_expected_key_on_success() { //Arrange var key = new LotKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileMaterialsReceived>(d => d.ChileLot.Lot.EmptyLot())); //Act var result = Service.GetChileMaterialsReceivedDetail(key.KeyValue); //Assert result.AssertSuccess(); Assert.AreEqual(key.KeyValue, result.ResultingObject.LotKey); }
internal IResult Execute(LotKey lotKey) { var includePaths = DeleteLotConductor.ConstructIncludePaths <ChileLotProduction>(p => p.ResultingChileLot.Lot, p => p.PickedInventory.Items.Select(i => i.CurrentLocation), p => p.Results.ResultItems).ToArray(); var lotProduction = _productionUnitOfWork.ChileLotProductionRepository.FindByKey(lotKey, includePaths); if (lotProduction == null) { return(new NoWorkRequiredResult()); } if (lotProduction.ProductionType != ProductionType.MillAndWetdown) { return(new InvalidResult(string.Format(UserMessages.MillAndWetdownEntryNotFound, lotKey))); } var pickedInventoryItemModifications = PickedInventoryHelper.CreateModifyPickedInventoryItemParameters(lotProduction.PickedInventory, new List <PickedInventoryParameters>()); var modifyPickedResult = new ModifyPickedInventoryItemsCommand(_productionUnitOfWork).Execute(lotProduction, pickedInventoryItemModifications); if (!modifyPickedResult.Success) { return(modifyPickedResult.ConvertTo <ChileLotProduction>()); } var inventoryModifications = pickedInventoryItemModifications.Select(i => i.ToModifySourceInventoryParameters()).ToList(); var setResults = new SetLotProductionResultItemsCommand(_productionUnitOfWork).Execute(lotProduction.Results, new List <IProductionResultItemParameters>(), ref inventoryModifications); if (!setResults.Success) { return(setResults.ConvertTo <ChileLotProduction>()); } var modifyInventoryResult = new ModifyInventoryCommand(_productionUnitOfWork).Execute(inventoryModifications, null); if (!modifyInventoryResult.Success) { return(modifyInventoryResult.ConvertTo <ChileLotProduction>()); } _productionUnitOfWork.LotProductionResultsRepository.Remove(lotProduction.Results); _productionUnitOfWork.PickedInventoryRepository.Remove(lotProduction.PickedInventory); var deleteLotResult = new DeleteLotConductor(_productionUnitOfWork).Delete(lotProduction.ResultingChileLot.Lot); if (!deleteLotResult.Success) { return(deleteLotResult); } return(new SuccessResult()); }
internal static Expression <Func <InventoryTransaction, bool> > ByInventoryKey(IInventoryKey inventoryKey) { var lot = new LotKey(inventoryKey).FindByPredicate; var location = new LocationKey(inventoryKey).FindByPredicate; var packaging = new PackagingProductKey(inventoryKey).FindByPredicate; var treatment = new InventoryTreatmentKey(inventoryKey).FindByPredicate; return(Projector <InventoryTransaction> .To(i => lot.Invoke(i.SourceLot) && location.Invoke(i.Location) && packaging.Invoke(i.PackagingProduct) && treatment.Invoke(i.Treatment) && i.ToteKey == inventoryKey.InventoryKey_ToteKey)); }
internal IResult <IProductionPacketReturn> Execute(ILotKey lotKey, DateTime currentDate) { var productionBatchKey = new LotKey(lotKey); var select = ProductionBatchProjectors.SplitSelectProductionPacketFromBatch(_productionUnitOfWork, currentDate.Date, productionBatchKey); var productionPacket = _productionUnitOfWork.ProductionBatchRepository .Filter(productionBatchKey.GetPredicate <ProductionBatch>()) .SplitSelect(select) .ToList(); if (productionPacket.Count != 1) { return(new InvalidResult <IProductionPacketReturn>(null, string.Format(UserMessages.ProductionBatchNotFound, productionBatchKey))); } return(Process(productionPacket.Single())); }
public IResult <IProductionBatchDetailReturn> Execute(LotKey lotKey, DateTime currentDate) { var predicate = lotKey.GetPredicate <ProductionBatch>(); var batchDetails = _productionUnitOfWork.ProductionBatchRepository .Filter(predicate) .SplitSelect(ProductionBatchProjectors.SplitSelectDetail(_productionUnitOfWork, currentDate)).ToList() .FirstOrDefault(); if (batchDetails == null) { return(new InvalidResult <IProductionBatchDetailReturn>(null, string.Format(UserMessages.ProductionBatchNotFound, lotKey.KeyValue))); } return(CreateProductionBatchDetail(batchDetails)); }
internal LotPackagingKeyValueQuantity(ILotKey lot, IPackagingProductKey packaging, int quantity) { var lotKey = new LotKey(lot); LotKeyValue = lotKey.KeyValue; LotPredicateExpression = lotKey.FindByPredicate; LotPredicate = lotKey.FindByPredicate.Compile(); var packagingKey = new PackagingProductKey(packaging); PackagingKeyValue = packagingKey.KeyValue; PackagingPredicateExpression = packagingKey.FindByPredicate; PackagingPredicate = packagingKey.FindByPredicate.Compile(); Quantity = quantity; }
public IResult <IQueryable <IProductionResultDetailReturn> > GetProductionResults(GetObjectParameters parameters) { LotKey productionResultKey = null; if (parameters != null && parameters.Key != null) { var keyResult = KeyParserHelper.ParseResult <ILotKey>(parameters.Key); if (!keyResult.Success) { return(keyResult.ConvertTo <IQueryable <IProductionResultDetailReturn> >()); } productionResultKey = new LotKey(keyResult.ResultingObject); } var includeDetails = productionResultKey != null && parameters.IncludeDetails; return(new GetProductionResultsCommand(_productionUnitOfWork).Execute(productionResultKey, includeDetails)); }
public void Returns_InventoryAdjustments_as_expected_with_combined_filtering_options() { //Arrange const int expectedResults = 2; var rangeStart = new DateTime(2012, 3, 29); var rangeEnd = new DateTime(2012, 4, 20); var lotKey = new LotKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Lot>(l => l.EmptyLot().SetChileLot())); var inventoryAdjustment0 = TestHelper.CreateObjectGraphAndInsertIntoDatabase <InventoryAdjustment>(a => a.AdjustmentDate = rangeStart.AddDays(10), a => a.Items = new List <InventoryAdjustmentItem> { TestHelper.CreateObjectGraph <InventoryAdjustmentItem>(i => i.ConstrainByKeys(null, lotKey)) }); var inventoryAdjustment1 = TestHelper.CreateObjectGraphAndInsertIntoDatabase <InventoryAdjustment>(a => a.AdjustmentDate = rangeStart, a => a.Items = new List <InventoryAdjustmentItem> { TestHelper.CreateObjectGraph <InventoryAdjustmentItem>(i => i.ConstrainByKeys(null, lotKey)) }); TestHelper.CreateObjectGraphAndInsertIntoDatabase <InventoryAdjustment>(a => a.AdjustmentDate = rangeStart.AddDays(10)); TestHelper.CreateObjectGraphAndInsertIntoDatabase <InventoryAdjustment>(a => a.AdjustmentDate = rangeStart.AddDays(-10), a => a.Items = new List <InventoryAdjustmentItem> { TestHelper.CreateObjectGraph <InventoryAdjustmentItem>(i => i.ConstrainByKeys(null, lotKey)) }); TestHelper.CreateObjectGraphAndInsertIntoDatabase <InventoryAdjustment>(a => a.AdjustmentDate = rangeEnd.AddDays(10), a => a.Items = new List <InventoryAdjustmentItem> { TestHelper.CreateObjectGraph <InventoryAdjustmentItem>(i => i.ConstrainByKeys(null, lotKey)) }); //Act StartStopwatch(); var result = Service.GetInventoryAdjustments(new FilterInventoryAdjustmentParameters { AdjustmentDateRangeStart = rangeStart, AdjustmentDateRangeEnd = rangeEnd, LotKey = lotKey.KeyValue }); var results = result.ResultingObject == null ? null : result.ResultingObject.ToList(); StopWatchAndWriteTime("Act"); //Assert result.AssertSuccess(); Assert.AreEqual(expectedResults, results.Count); inventoryAdjustment0.AssertEqual(results.Single(r => r.InventoryAdjustmentKey == new InventoryAdjustmentKey(inventoryAdjustment0).KeyValue)); inventoryAdjustment1.AssertEqual(results.Single(r => r.InventoryAdjustmentKey == new InventoryAdjustmentKey(inventoryAdjustment1).KeyValue)); }
public static bool ParseLotNumber(int lotNumber, out LotKey lotKey) { lotKey = null; var lotNumberString = lotNumber.ToString(CultureInfo.InvariantCulture); var match = LotNumberRegex.Match(lotNumberString); if (!match.Success) { return(false); } var typeValue = match.Groups[INV_TYPE].Value; var yearValue = match.Groups[YEAR].Value; var julianValue = match.Groups[JULDATE].Value; var seqValue = match.Groups[SEQUENCE].Value; var year = int.Parse(yearValue); var century = "20"; if (year > YearCenturyCutoff % 100) { century = "19"; } yearValue = string.Format("{0}{1:00}", century, year); var lotDate = new DateTime(int.Parse(yearValue), 1, 1); lotDate = lotDate.AddDays(Math.Max(int.Parse(julianValue) - 1, 0)); if (lotDate.Year < YearCenturyCutoff) { return(false); } lotKey = new LotKey(new LotKeyParameters { LotKey_DateCreated = lotDate.Date, LotKey_DateSequence = int.Parse(seqValue), LotKey_LotTypeId = int.Parse(typeValue) }); return(true); }
public void Will_return_summary_with_TotalLoad_equal_to_0_if_it_has_no_Items() { //Arrange const int expectedResults = 3; var expectedKey0 = new LotKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileMaterialsReceived>(d => d.Items = null, d => d.ChileLot.Lot.EmptyLot())); TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileMaterialsReceived>(d => d.ChileLot.Lot.EmptyLot()); TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileMaterialsReceived>(d => d.ChileLot.Lot.EmptyLot()); //Act var result = Service.GetChileMaterialsReceivedSummaries(); //Assert result.AssertSuccess(); var results = result.ResultingObject.ToList(); Assert.AreEqual(expectedResults, results.Count); Assert.AreEqual(0, results.Single(r => r.LotKey == expectedKey0.KeyValue).TotalLoad); }
public void Returns_summaries_with_expected_keys_on_success() { //Arrange const int expectedResults = 3; var expectedKey0 = new LotKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileMaterialsReceived>(d => d.ChileLot.Lot.EmptyLot())); var expectedKey1 = new LotKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileMaterialsReceived>(d => d.ChileLot.Lot.EmptyLot())); var expectedKey2 = new LotKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileMaterialsReceived>(d => d.ChileLot.Lot.EmptyLot())); //Act var result = Service.GetChileMaterialsReceivedSummaries(); //Assert result.AssertSuccess(); var results = result.ResultingObject.ToList(); Assert.AreEqual(expectedResults, results.Count); Assert.IsNotNull(results.Single(r => r.LotKey == expectedKey0.KeyValue)); Assert.IsNotNull(results.Single(r => r.LotKey == expectedKey1.KeyValue)); Assert.IsNotNull(results.Single(r => r.LotKey == expectedKey2.KeyValue)); }
public void Returns_PickedInventoryItems_with_Lot_status_properties_as_expected_on_success() { //Arrange StartStopwatch(); const LotQualityStatus lotStatus0 = LotQualityStatus.Contaminated; const bool onHold0 = false; const LotProductionStatus productionStatus0 = LotProductionStatus.Batched; const LotQualityStatus lotStatus1 = LotQualityStatus.Pending; const bool onHold1 = true; const LotProductionStatus status1 = LotProductionStatus.Produced; var lotKey0 = new LotKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Lot>(l => l.EmptyLot(), l => l.QualityStatus = lotStatus0, l => l.ProductionStatus = productionStatus0, l => l.Hold = null)); var lotKey1 = new LotKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <Lot>(l => l.EmptyLot(), l => l.QualityStatus = lotStatus1, l => l.ProductionStatus = status1, l => l.Hold = LotHoldType.HoldForAdditionalTesting)); var parentRecord = CreateParentRecord(); var pickedInventory = GetPickedInventoryRecordFromParent(parentRecord); var pickedKey0 = new PickedInventoryItemKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PickedInventoryItem>(i => i.ConstrainByKeys(pickedInventory, lotKey0))); var pickedKey1 = new PickedInventoryItemKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <PickedInventoryItem>(i => i.ConstrainByKeys(pickedInventory, lotKey1))); StopWatchAndWriteTime("Arrange"); //Act var result = TimedExecution(() => MethodUnderTest(parentRecord)); //Assert result.AssertSuccess(); var items = GetPickedInventoryItemsFromResult(result.ResultingObject); var inventory = items.Single(r => r.PickedInventoryItemKey == pickedKey0.KeyValue); Assert.AreEqual(lotStatus0, inventory.QualityStatus); Assert.AreEqual(onHold0, inventory.HoldType != null); Assert.AreEqual(productionStatus0, inventory.ProductionStatus); inventory = items.Single(r => r.PickedInventoryItemKey == pickedKey1.KeyValue); Assert.AreEqual(lotStatus1, inventory.QualityStatus); Assert.AreEqual(onHold1, inventory.HoldType != null); Assert.AreEqual(status1, inventory.ProductionStatus); }
public void Returns_detail_with_Item_collection_as_expected_on_success() { //Arrange const int expectedItems = 3; var materialsReceivedKey = new LotKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileMaterialsReceived>(d => d.Items = null, d => d.ChileLot.Lot.EmptyLot())); var itemKey0 = new ChileMaterialsReceivedItemKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileMaterialsReceivedItem>(i => i.ConstrainByKeys(materialsReceivedKey))); var itemKey1 = new ChileMaterialsReceivedItemKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileMaterialsReceivedItem>(i => i.ConstrainByKeys(materialsReceivedKey))); var itemKey2 = new ChileMaterialsReceivedItemKey(TestHelper.CreateObjectGraphAndInsertIntoDatabase <ChileMaterialsReceivedItem>(i => i.ConstrainByKeys(materialsReceivedKey))); //Act var result = Service.GetChileMaterialsReceivedDetail(materialsReceivedKey.KeyValue); //Assert result.AssertSuccess(); var items = result.ResultingObject.Items.ToList(); Assert.AreEqual(expectedItems, items.Count); Assert.IsNotNull(items.Single(i => i.ItemKey == itemKey0.KeyValue)); Assert.IsNotNull(items.Single(i => i.ItemKey == itemKey1.KeyValue)); Assert.IsNotNull(items.Single(i => i.ItemKey == itemKey2.KeyValue)); }
internal static void AssertEqual(this InventoryAdjustmentItem inventoryAdjustmentItem, IInventoryAdjustmentItemReturn inventoryAdjustmentItemReturn, List <dynamic> derivedLots = null) { if (inventoryAdjustmentItem == null) { throw new ArgumentNullException("inventoryAdjustmentItem"); } if (inventoryAdjustmentItemReturn == null) { throw new ArgumentNullException("inventoryAdjustmentItemReturn"); } Assert.AreEqual(new InventoryAdjustmentItemKey(inventoryAdjustmentItem).KeyValue, inventoryAdjustmentItemReturn.InventoryAdjustmentItemKey); Assert.AreEqual(inventoryAdjustmentItem.QuantityAdjustment, inventoryAdjustmentItemReturn.AdjustmentQuantity); var lotKey = new LotKey(inventoryAdjustmentItem); Assert.AreEqual(lotKey.KeyValue, inventoryAdjustmentItemReturn.LotKey); Assert.AreEqual(inventoryAdjustmentItem.ToteKey, inventoryAdjustmentItemReturn.ToteKey); inventoryAdjustmentItem.Location.AssertEqual(inventoryAdjustmentItemReturn.Location); inventoryAdjustmentItem.PackagingProduct.AssertEqual(inventoryAdjustmentItemReturn.PackagingProduct); inventoryAdjustmentItem.Treatment.AssertEqual(inventoryAdjustmentItemReturn.InventoryTreatment); if (inventoryAdjustmentItem.Lot.ChileLot != null) { inventoryAdjustmentItem.Lot.ChileLot.ChileProduct.AssertEqual(inventoryAdjustmentItemReturn.InventoryProduct); } else if (inventoryAdjustmentItem.Lot.AdditiveLot != null) { inventoryAdjustmentItem.Lot.AdditiveLot.AdditiveProduct.AssertEqual(inventoryAdjustmentItemReturn.InventoryProduct); } else if (inventoryAdjustmentItem.Lot.PackagingLot != null) { inventoryAdjustmentItem.Lot.PackagingLot.PackagingProduct.AssertEqual(inventoryAdjustmentItemReturn.InventoryProduct); } else { Assert.IsNull(inventoryAdjustmentItemReturn.InventoryProduct); } }
public IResult <string> UpdateMillAndWetdown(IUpdateMillAndWetdownParameters parameters) { var parseResult = parameters.ToParsedParameters(); if (!parseResult.Success) { return(parseResult.ConvertTo <string>()); } var result = new UpdateMillAndWetdownConductor(_productionUnitOfWork).Execute(_timeStamper.CurrentTimeStamp, parseResult.ResultingObject); if (!result.Success) { return(result.ConvertTo <string>()); } _productionUnitOfWork.Commit(); var lotKey = new LotKey(result.ResultingObject); return(SyncParameters.Using(new SuccessResult <string>(lotKey), lotKey)); }
private static Dictionary <int, Tuple <DateTime, int> > GetEmployeeIdentifiableByLot(PackScheduleDTO packSchedule) { if (packSchedule == null || string.IsNullOrWhiteSpace(packSchedule.Serialized)) { return(new Dictionary <int, Tuple <DateTime, int> >()); } try { var lotKeyParser = new LotKey(); var employeeKey = new EmployeeKey(); return(SerializablePackSchedule.Deserialize(packSchedule.Serialized).Batches.ToDictionary(b => { var lotKey = lotKeyParser.Parse(b.LotKey); return LotNumberBuilder.BuildLotNumber(lotKey).LotNumber; }, b => new Tuple <DateTime, int>(b.TimeStamp, employeeKey.Parse(b.EmployeeKey).EmployeeKey_Id))); } catch (Exception ex) { throw new Exception("Error parsing PackSchedule deserialized data.", ex); } }
public tblLot SynchronizeOldLot(LotKey lotKey, bool overrideOldContextLotAsCompleted, bool updateSerializationOnly = false) { var newLot = _unitOfWork.LotRepository.GetLotForSynch(lotKey); if (newLot == null) { throw new Exception(string.Format("Lot[{0}] not found in new context.", lotKey)); } var customer = GetProductionCustomer(newLot); var oldLot = GetOrCreateLot(newLot); var lotHistory = CreateNewLotHistoryRecord(oldLot); UpdateOldLot(oldLot, newLot, customer, overrideOldContextLotAsCompleted, updateSerializationOnly); if (!updateSerializationOnly && CommitLotHistory(oldLot, lotHistory)) { _oldContext.tblLotAttributeHistories.AddObject(lotHistory); } return(oldLot); }