public void Updates_tblLocation_record_as_expected() { //Arrange var location = RVCUnitOfWork.LocationRepository.Filter(l => l.LocID != null).FirstOrDefault(); if (location == null) { Assert.Inconclusive("Could not find suitable Location to test."); } //Act var result = Service.UpdateLocation(new UpdateLocationParameters { UserToken = TestUser.UserName, LocationKey = new LocationKey(location), Description = location.Description, Active = !location.Active, Locked = true, }); var resultString = GetKeyFromConsoleString(ConsoleOutput.SyncLocation); //Assert result.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var locId = int.Parse(resultString); var tblLocation = new RioAccessSQLEntities().tblLocations.FirstOrDefault(l => l.LocID == locId); Assert.AreNotEqual(!location.Active, tblLocation.InActive); }
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_tblLot_record_and_KillSwitch_will_not_have_been_engaged_if_service_method_and_synchronization_were_successful() { //Arrange var packSchedule = RVCUnitOfWork.PackScheduleRepository.All().Where(p => p.PSNum != null).OrderByDescending(p => p.DateCreated).FirstOrDefault(); if (packSchedule == null) { throw new Exception("Could not find valid test PackSchedule."); } //Act var param = new CreateProductionBatchParameters { PackScheduleKey = new PackScheduleKey(packSchedule), UserToken = TestUser.UserName, Instructions = new[] { "Instruction 0", "Instruction 1", "Instruction 2" } }; var result = Service.CreateProductionBatch(param); var lotString = GetKeyFromConsoleString(ConsoleOutput.AddedLot); //Assert result.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var newLot = int.Parse(lotString); Assert.IsNotNull(new RioAccessSQLEntities().tblLots.FirstOrDefault(t => t.Lot == newLot)); }
public void Creates_new_tblWarehouse_record_as_expected() { //Arrange var facility = RVCUnitOfWork.FacilityRepository.All().FirstOrDefault(); if (facility == null) { Assert.Inconclusive("No Facility records to test with."); } var parameters = new UpdateFacilityParameters { UserToken = TestUser.UserName, FacilityKey = new FacilityKey(facility), Name = facility.Name == "Test Facility Inc." ? "Happy Fun-Times Inc." : "Test Facility Inc.", Address = new Address() }; var result = Service.UpdateFacility(parameters); var resultString = GetKeyFromConsoleString(ConsoleOutput.SyncFacility); //Assert result.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var whid = int.Parse(resultString); var tblMove = new RioAccessSQLEntities().tblWarehouses.FirstOrDefault(w => w.WHID == whid); Assert.AreEqual(parameters.Name, tblMove.WhouseAbbr); }
public void Unlocks_Locations_as_expected() { //Arrange var locations = RVCUnitOfWork.LocationRepository.Filter(l => l.LocID != null && l.Locked).OrderBy(l => l.Description).Take(2).ToList(); if (locations.Count != 2) { Assert.Inconclusive("Not enough locked locations found."); } //Act var result = Service.UnlockLocations(locations.Select(l => new LocationKey(l).KeyValue)); //Assert result.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); using (var context = new RioAccessSQLEntities()) { foreach (var location in locations) { Assert.IsTrue(context.tblLocations.FirstOrDefault(l => l.LocID == location.LocID).FreezeRow == null); } } }
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 SetMatch() { //Arrange var sampleOrderItem = RVCUnitOfWork.SampleOrderItemRepository .Filter(i => i.SampleDetailID != null && i.Match == null) .OrderByDescending(i => i.SampleOrderYear) .FirstOrDefault(); if (sampleOrderItem == null) { Assert.Inconclusive("No SampleOrderItme to test."); } var parameters = new SetSampleMatchParameters { SampleOrderItemKey = sampleOrderItem.ToSampleOrderItemKey(), Notes = "integrated testing" }; //Act var result = Service.SetSampleMatch(parameters); result.AssertSuccess(); //Assert MockKillSwitch.Verify(k => k.Engage(), Times.Never()); using (var oldContext = new RioAccessSQLEntities()) { var match = oldContext.tblSampleRVCMatches.FirstOrDefault(s => s.SampleDetailID == sampleOrderItem.SampleDetailID); Assert.AreEqual(parameters.Notes, match.Notes); } }
public void Delete() { //Arrange var sampleOrder = RVCUnitOfWork.SampleOrderRepository.Filter(o => o.SampleID != null) .OrderByDescending(s => s.Year) .FirstOrDefault(); if (sampleOrder == null) { Assert.Inconclusive("No SampleOrder to test."); } //Act var result = Service.DeleteSampleOrder(sampleOrder.ToSampleOrderKey()); result.AssertSuccess(); //Assert MockKillSwitch.Verify(k => k.Engage(), Times.Never()); using (var oldContext = new RioAccessSQLEntities()) { Assert.IsNull(oldContext.tblSamples.FirstOrDefault(s => s.SampleID == sampleOrder.SampleID)); } }
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 Updates_tblBatchInstr_record_and_KillSwitch_will_not_have_been_engaged_if_service_method_and_synchronization_were_successful() { //Arrange const string testnote = "TestNote!"; var productionBatch = RVCUnitOfWork.ProductionBatchRepository.Filter(b => b.InstructionNotebook.Notes.Count(n => n.Text != testnote) >= 1, b => b.InstructionNotebook.Notes).FirstOrDefault(); if (productionBatch == null) { Assert.Inconclusive("No suitable test ProductionBatch found."); } var note = productionBatch.InstructionNotebook.Notes.First(); //Act var result = Service.UpdateNote(new NoteKey(note), new UpdateNoteParameters { UserToken = TestUser.UserName, Text = testnote }); var lotKeyString = GetKeyFromConsoleString(ConsoleOutput.UpdatedBatchInstructions); //Assert result.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var lot = int.Parse(lotKeyString); using (var oldContext = new RioAccessSQLEntities()) { var instructions = oldContext.tblBatchInstrs.Where(i => i.Lot == lot); Assert.AreEqual(1, instructions.Count(i => i.Step == note.Sequence && i.Action == testnote)); Assert.AreEqual(0, instructions.Count(i => i.Action == note.Text)); } }
public void Updates_tblRincon_record_and_KillSwitch_will_not_have_been_engaged_if_service_method_and_synchronization_were_successful() { //Arrange const string operatorName = "Dr. Update"; var order = RVCUnitOfWork.IntraWarehouseOrderRepository.Filter(i => i.RinconID != null && i.OperatorName != operatorName).FirstOrDefault(); if(order == null) { Assert.Inconclusive("Could not find valid IntraWarehouseOrder to update."); } //Act var result = Service.UpdateIntraWarehouseOrder(new UpdateIntraWarehouseOrderParameters { IntraWarehouseOrderKey = new IntraWarehouseOrderKey(order), UserToken = TestUser.UserName, OperatorName = operatorName, MovementDate = new DateTime(2014, 1, 1) }); var movementString = GetKeyFromConsoleString(ConsoleOutput.SynchronizedIntraWarehouserMovement); //Assert result.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var rinconId = DateTime.ParseExact(movementString, SyncIntraWarehouseOrder.DateTimeFormat, CultureInfo.InvariantCulture); Assert.AreEqual(operatorName, new RioAccessSQLEntities().tblRincons.FirstOrDefault(r => r.RinconID == rinconId).PrepBy); }
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); } }
public void Serializes_Contract_with_updated_Comments_Note_in_old_context() { //Arrange const string updatedNote = "Updated contract comment!"; var contract = RVCUnitOfWork.ContractRepository .Filter(c => c.Comments.Notes.Count() == 1 && c.Comments.Notes.All(n => n.Text != updatedNote), c => c.Comments.Notes) .FirstOrDefault(); if (contract == null) { Assert.Inconclusive("No suitable test contract found."); } var noteKey = new NoteKey(contract.Comments.Notes.Single()); //Assert var result = Service.UpdateNote(noteKey, new UpdateNoteParameters { UserToken = TestUser.UserName, Text = updatedNote }); var contractKeyString = GetKeyFromConsoleString(ConsoleOutput.SynchronizedContract); //Assert result.AssertSuccess(); MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var contractId = int.Parse(contractKeyString); using (var oldContext = new RioAccessSQLEntities()) { var serialized = oldContext.tblContracts.First(c => c.ContractID == contractId).Serialized; var serializedContract = SerializableContract.Deserialize(serialized); Assert.AreEqual(updatedNote, serializedContract.Notes.Single().Text); } }
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_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 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_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 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 void Creates_new_tblLot_record_and_KillSwitch_will_not_have_been_engaged_if_service_method_and_synchronization_were_successful() { //Arrange var dehydrator = RVCUnitOfWork.CompanyRepository.Filter(c => c.CompanyTypes.Any(t => t.CompanyType == (int)CompanyType.Dehydrator)).First(); var chileProduct = RVCUnitOfWork.ChileProductRepository.Filter(c => c.ChileState == ChileStateEnum.Dehydrated).First(); var warehouseLocation = RVCUnitOfWork.LocationRepository.Filter(l => l.LocID != null).First(); var packagingProduct = RVCUnitOfWork.PackScheduleRepository.All().First(); var parameters = new ChileMaterialsReceivedParameters { UserToken = TestUser.UserName, ChileMaterialsReceivedType = ChileMaterialsReceivedType.Dehydrated, DateReceived = new DateTime(2020, 3, 29), SupplierKey = new CompanyKey(dehydrator), TreatmentKey = StaticInventoryTreatments.NoTreatment.ToInventoryTreatmentKey(), LoadNumber = "42", ChileProductKey = new ChileProductKey(chileProduct), PurchaseOrder = "Yes", ShipperNumber = "No", Items = new List <ChileMaterialsReceivedItemParameters> { new ChileMaterialsReceivedItemParameters { ToteKey = "TOTE1", Quantity = 23, PackagingProductKey = new PackagingProductKey(packagingProduct), Variety = "Variety", GrowerCode = "CODE", LocationKey = new LocationKey(warehouseLocation) }, new ChileMaterialsReceivedItemParameters { ToteKey = "TOTE2", Quantity = 45, PackagingProductKey = new PackagingProductKey(packagingProduct), Variety = "Variety", GrowerCode = "CODE", LocationKey = new LocationKey(warehouseLocation) }, } }; TestHelper.ResetContext(); //Act var result = Service.CreateChileMaterialsReceived(parameters); result.AssertSuccess(); var lotString = GetKeyFromConsoleString(ConsoleOutput.SyncDehydratedReceived); //Assert MockKillSwitch.Verify(k => k.Engage(), Times.Never()); var newLot = int.Parse(lotString); Assert.IsNotNull(new RioAccessSQLEntities().tblLots.FirstOrDefault(t => t.Lot == newLot)); }
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 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 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 KillSwitch_will_not_have_been_engaged_if_service_method_was_not_successful() { //Arrange MockMethodReturn.Setup(m => m.Success).Returns(false); //Act SynchronizeOldContext.OnExit(MethodExecutionArgs); //Assert MockKillSwitch.Verify(k => k.Engage(), Times.Never()); }
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 KillSwitch_will_have_been_engaged_if_service_method_was_successful_but_synchronization_was_not() { //Arrange MockMethodReturn.Setup(m => m.Success).Returns(true); MockCommand.Setup(m => m.Synchronize(It.IsAny <Func <TCommandInput> >())).Throws(new Exception()); //Act SynchronizeOldContext.OnExit(MethodExecutionArgs); //Assert MockKillSwitch.Verify(k => k.Engage(), Times.Once()); }
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)); } }
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_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()); } }