Пример #1
0
            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 Sets_InterWarehouseOrderShipmentInformation()
            {
                //Arrange
                const string comments0 = "ShipmentComments! Awesome!";
                const string comments1 = "Awesome comments 2.0!";
                var          order     = RVCUnitOfWork.InventoryShipmentOrderRepository.Filter(o => o.OrderType == InventoryShipmentOrderTypeEnum.InterWarehouseOrder, o => o.ShipmentInformation).FirstOrDefault();

                if (order == null)
                {
                    Assert.Inconclusive("No suitable InterWarehouseOrder record to test found.");
                }
                var expectedComments = order.ShipmentInformation.ExternalNotes == comments0 ? comments1 : comments0;

                //Act
                var result = Service.SetShipmentInformation(new SetInventoryShipmentInformationParameters
                {
                    InventoryShipmentOrderKey = new InventoryShipmentOrderKey(order),
                    ShippingInstructions      = new SetShippingInstructionsParameters
                    {
                        ExternalNotes = expectedComments
                    }
                });
                var resultString = GetKeyFromConsoleString(ConsoleOutput.SetShipmentTblMove);

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

                var moveNum = int.Parse(resultString);
                var tblMove = new RioAccessSQLEntities().tblMoves.FirstOrDefault(o => o.MoveNum == moveNum);

                Assert.AreEqual(expectedComments, tblMove.ExternalNotes);
            }
Пример #3
0
            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));
                }
            }
Пример #4
0
            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 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);
                }
            }
Пример #6
0
            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));
                }
            }
Пример #7
0
            public void Removes_tblMove_record_as_expected()
            {
                //Arrange
                var treatmentOrder = RVCUnitOfWork.TreatmentOrderRepository.Filter(o => o.InventoryShipmentOrder.OrderStatus != OrderStatus.Fulfilled &&
                                                                                   o.InventoryShipmentOrder.ShipmentInformation.Status != ShipmentStatus.Shipped &&
                                                                                   o.InventoryShipmentOrder.PickedInventory.Items.All(i => i.CurrentLocationId == i.FromLocationId)).FirstOrDefault();

                if (treatmentOrder == null)
                {
                    Assert.Inconclusive("No suitable treatment order for testing.");
                }

                //Act
                var result = Service.DeleteTreatmentOrder(new TreatmentOrderKey(treatmentOrder));

                result.AssertSuccess();

                //Assert
                MockKillSwitch.Verify(k => k.Engage(), Times.Never());
                var resultString = GetKeyFromConsoleString(ConsoleOutput.RemovedTblMove);
                var moveNum      = int.Parse(resultString);

                using (var context = new RioAccessSQLEntities())
                {
                    Assert.IsNull(context.tblMoves.FirstOrDefault(m => m.MoveNum == moveNum));
                }
            }
Пример #8
0
            public void Updates_existing_tblMove_record_as_expected()
            {
                //Arrange
                const string expectedComments = "pew-pew-pew";
                var          treatmentOrder   = RVCUnitOfWork.TreatmentOrderRepository.FindBy(o => o.InventoryShipmentOrder.ShipmentInformation.ExternalNotes != expectedComments, o => o.InventoryShipmentOrder);
                var          parameters       = new UpdateTreatmentOrderParameters
                {
                    TreatmentOrderKey      = new TreatmentOrderKey(treatmentOrder),
                    UserToken              = TestUser.UserName,
                    SetShipmentInformation = new SetInventoryShipmentInformationParameters
                    {
                        ShippingInstructions = new SetShippingInstructionsParameters
                        {
                            ExternalNotes = expectedComments
                        }
                    }
                };

                //Act
                var result       = Service.UpdateTreatmentOrder(parameters);
                var resultString = GetKeyFromConsoleString(ConsoleOutput.SyncTblMove);

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

                var moveNum = int.Parse(resultString);
                var tblMove = new RioAccessSQLEntities().tblMoves.FirstOrDefault(m => m.MoveNum == moveNum);

                Assert.AreEqual(treatmentOrder.InventoryShipmentOrder.MoveNum, tblMove.MoveNum);
                Assert.AreEqual(tblMove.ExternalNotes, parameters.SetShipmentInformation.ShippingInstructions.ExternalNotes);
            }
Пример #9
0
            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);
            }
Пример #10
0
            public void Creates_new_Company_record()
            {
                //Arrange
                var companyName = Guid.NewGuid().ToString();

                companyName = companyName.Substring(0, Math.Min(companyName.Length, Constants.StringLengths.CompanyName));

                //Act
                var result = Service.CreateCompany(new CreateCompanyParameters
                {
                    UserToken    = TestUser.UserName,
                    CompanyName  = companyName,
                    Active       = true,
                    CompanyTypes = new[]
                    {
                        CompanyType.Freight
                    }
                });

                //Assert
                result.AssertSuccess();
                MockKillSwitch.Verify(k => k.Engage(), Times.Never());
                var companyKey = GetKeyFromConsoleString(ConsoleOutput.SynchedCompany);

                using (var oldContext = new RioAccessSQLEntities())
                {
                    var company = oldContext.Companies.FirstOrDefault(c => c.Company_IA == companyKey);
                    Assert.AreEqual("Freight", company.CType);
                }
            }
Пример #11
0
            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);
                }
            }
Пример #12
0
            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_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);
            }
Пример #14
0
            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));
                }
            }
Пример #15
0
            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);
                }
            }
Пример #16
0
            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);
                }
            }
Пример #17
0
            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);
                    }
                }
            }
Пример #18
0
            public void Updates_Contact_record()
            {
                //Arrange
                var contact = RVCUnitOfWork.ContactRepository
                              .Filter(n => n.Name != "removedAddresses" && n.OldContextID != null && n.Addresses.Count > 1)
                              .FirstOrDefault();

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

                //Act
                var result = Service.UpdateContact(new UpdateContactParameters
                {
                    ContactKey   = contact.ToContactKey(),
                    UserToken    = TestUser.UserName,
                    Name         = "removedAddresses",
                    EmailAddress = "*****@*****.**",
                    PhoneNumber  = "nope"
                });

                //Assert
                result.AssertSuccess();
                MockKillSwitch.Verify(k => k.Engage(), Times.Never());
                var companyKey = GetKeyFromConsoleString(ConsoleOutput.SynchedCompany);

                using (var oldContext = new RioAccessSQLEntities())
                {
                    var oldContact = oldContext.Contacts.SingleOrDefault(c => c.Company_IA == companyKey && c.Contact_IA == "removedAddresses");
                    Assert.AreEqual(null, oldContact.Address1_IA);
                }
            }
Пример #19
0
            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);
            }
Пример #20
0
            public void Updates_tblMove_Status_as_expected()
            {
                var inventory      = RVCUnitOfWork.InventoryRepository.All().AsQueryable();
                var treatmentOrder = RVCUnitOfWork.TreatmentOrderRepository.FindBy(o => o.InventoryShipmentOrder.OrderStatus == OrderStatus.Scheduled && o.InventoryShipmentOrder.ShipmentInformation.Status == ShipmentStatus.Shipped && o.InventoryShipmentOrder.PickedInventory.Items.Any() &&
                                                                                   o.InventoryShipmentOrder.PickedInventory.Items.All(p => inventory.Any(i => i.LotTypeId == p.LotTypeId && i.LotDateCreated == p.LotDateCreated && i.LotDateSequence == p.LotDateSequence && i.LocationId == p.CurrentLocationId && i.PackagingProductId == p.PackagingProductId && i.TreatmentId == p.TreatmentId && i.ToteKey == p.ToteKey && i.Quantity >= p.Quantity)),
                                                                                   o => o.InventoryShipmentOrder.DestinationFacility.Locations,
                                                                                   o => o.InventoryShipmentOrder.SourceFacility.Locations);

                if (treatmentOrder == null)
                {
                    Assert.Inconclusive("No suitable treatment order for testing.");
                }

                //Act
                var result = Service.ReceiveOrder(new ReceiveTreatmentOrderParameters
                {
                    UserToken              = TestUser.UserName,
                    TreatmentOrderKey      = new TreatmentOrderKey(treatmentOrder),
                    DestinationLocationKey = new LocationKey(treatmentOrder.InventoryShipmentOrder.DestinationFacility.Locations.First())
                });

                result.AssertSuccess();
                var resultString = GetKeyFromConsoleString(ConsoleOutput.ReceivedTreatmentOrder);

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

                var moveNum = int.Parse(resultString);
                var tblMove = new RioAccessSQLEntities().tblMoves.FirstOrDefault(m => m.MoveNum == moveNum);

                Assert.AreEqual((int)tblOrderStatus.Treated, tblMove.Status);
            }
            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));
            }
Пример #22
0
            public void Creates_new_tblMove_record_as_expected()
            {
                //Arrange
                var source      = RVCUnitOfWork.FacilityRepository.Filter(f => f.Name.Contains("rincon")).First();
                var destination = RVCUnitOfWork.FacilityRepository.All().First(f => f.FacilityType == FacilityType.Treatment);
                var treatment   = RVCUnitOfWork.InventoryTreatmentRepository.All().First();
                var parameters  = new CreateTreatmentOrderParameters
                {
                    UserToken              = TestUser.UserName,
                    SourceFacilityKey      = new FacilityKey(source),
                    DestinationFacilityKey = new FacilityKey(destination),
                    TreatmentKey           = new InventoryTreatmentKey(treatment),
                    SetShipmentInformation = new SetInventoryShipmentInformationParameters
                    {
                        ShippingInstructions = new SetShippingInstructionsParameters
                        {
                            ExternalNotes = "When will my ship come in..."
                        }
                    }
                };

                //Act
                var result = Service.CreateInventoryTreatmentOrder(parameters);

                result.AssertSuccess();
                var resultString = GetKeyFromConsoleString(ConsoleOutput.SyncTblMove);

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

                var moveNum = int.Parse(resultString);
                var tblMove = new RioAccessSQLEntities().tblMoves.FirstOrDefault(m => m.MoveNum == moveNum);

                Assert.AreEqual(tblMove.ExternalNotes, parameters.SetShipmentInformation.ShippingInstructions.ExternalNotes);
            }
Пример #23
0
            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));
                }
            }
Пример #24
0
            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);
                    }
                }
            }
Пример #25
0
            public void Updates_existing_tblLot_record_and_KillSwitch_will_not_have_engaged_if_service_method_and_synchronization_were_successful()
            {
                //Arrange
                var lot = RVCUnitOfWork.LotRepository.Filter(l => l.LotTypeId == (decimal)LotTypeEnum.FinishedGood && l.QualityStatus != LotQualityStatus.Rejected).FirstOrDefault();

                if (lot == null)
                {
                    throw new Exception("Could not find Lot that has not been rejected.");
                }

                //Act
                var result = Service.SetLotQualityStatus(new SetLotStatusParameters
                {
                    UserToken     = TestUser.UserName,
                    LotKey        = new LotKey(lot),
                    QualityStatus = LotQualityStatus.Rejected
                });
                var lotString = GetKeyFromConsoleString(ConsoleOutput.UpdatedLot);

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

                var newLot = int.Parse(lotString);
                var tblLot = new RioAccessSQLEntities().tblLots.FirstOrDefault(l => l.Lot == newLot);

                Assert.AreEqual((int?)LotStat.Rejected, tblLot.LotStat);
            }
Пример #26
0
            public void Will_create_new_tblLotHistory_record_if_setting_lot_hold_status_results_in_a_LotStat_change()
            {
                //Arrange
                var chileLot = RVCUnitOfWork.ChileLotRepository.Filter(c => c.Lot.Hold == null && c.Lot.QualityStatus == LotQualityStatus.Released).FirstOrDefault();

                if (chileLot == null)
                {
                    throw new Exception("Could not find Accepted ChileLot without hold.");
                }
                var lotNumber = LotNumberBuilder.BuildLotNumber(chileLot);
                var expectedLotAttributeHistories = new RioAccessSQLEntities().tblLotAttributeHistories.Count(h => h.Lot == lotNumber) + 1;

                //Act
                var result = Service.SetLotHoldStatus(new SetLotHoldStatusParameters
                {
                    UserToken = TestUser.UserName,
                    LotKey    = chileLot.ToLotKey(),
                    Hold      = new LotHold
                    {
                        HoldType    = LotHoldType.HoldForCustomer,
                        Description = "HOLDIT!"
                    }
                });
                var lotString = GetKeyFromConsoleString(ConsoleOutput.UpdatedLot);

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

                Assert.AreEqual(lotNumber, int.Parse(lotString));
                Assert.AreEqual(expectedLotAttributeHistories, new RioAccessSQLEntities().tblLotAttributeHistories.Count(h => h.Lot == lotNumber));
            }
Пример #27
0
            public void Updates_existing_tblLot_record_and_KillSwitch_will_not_have_been_engaged_if_service_method_and_synchronization_were_successful()
            {
                //Arrange
                var chileLot = RVCUnitOfWork.ChileLotRepository.Filter(c => c.Lot.Hold == null && c.Lot.LotDefects.All(d => d.Resolution != null),
                                                                       c => c.Lot.LotDefects).FirstOrDefault();

                if (chileLot == null)
                {
                    throw new Exception("Could not find ChileLot with single InHouseContamination defect.");
                }

                //Act
                var result = Service.SetLotHoldStatus(new SetLotHoldStatusParameters
                {
                    UserToken = TestUser.UserName,
                    LotKey    = new LotKey(chileLot),
                    Hold      = new LotHold
                    {
                        HoldType    = LotHoldType.HoldForCustomer,
                        Description = "TestTestTest"
                    }
                });
                var lotString = GetKeyFromConsoleString(ConsoleOutput.UpdatedLot);

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

                var newLot = int.Parse(lotString);
                var tblLot = new RioAccessSQLEntities().tblLots.FirstOrDefault(a => a.Lot == newLot);

                Assert.AreEqual((int?)LotStat.Completed_Hold, tblLot.LotStat);
            }
Пример #28
0
            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());
                        }
                    }
                }
            }
Пример #29
0
            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));
                }
            }