Exemplo n.º 1
0
        public void LockPurchaseOrderHeaderTest()
        {
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser, true);

            // Create a record
            var model = GetTestPurchaseOrderHeader(testCompany, testUser, 10);

            // Get the current Lock
            string lockGuid = PurchasingService.LockPurchaseOrderHeader(model);

            Assert.IsTrue(!string.IsNullOrEmpty(lockGuid), "Error: Lock record was not found");

            // Simulate another user updating the record
            var otherUser = GetTestUser();
            var error     = PurchasingService.InsertOrUpdatePurchaseOrderHeader(model, otherUser, lockGuid);

            Assert.IsTrue(!error.IsError, error.Message);

            // Now get the first user to update the record
            error = PurchasingService.InsertOrUpdatePurchaseOrderHeader(model, testUser, lockGuid);
            Assert.IsTrue(error.IsError, "Error: The lock should have caused an error as it has changed");

            // Try to update with the new lock
            lockGuid = PurchasingService.LockPurchaseOrderHeader(model);
            error    = PurchasingService.InsertOrUpdatePurchaseOrderHeader(model, testUser, lockGuid);
            Assert.IsTrue(!error.IsError, $"Error: {error.Message}");
        }
        public void GetNextSequenceNumberTest()
        {
            var user        = GetTestUser();
            var testCompany = GetTestCompany(user);

            decimal actual = 0;

            // At this stage, no sequences or orders exist
            for (int expected = 1; expected <= 10; expected++)
            {
                actual = LookupService.GetNextSequenceNumber(testCompany, SequenceNumberType.PurchaseOrderNumber);

                Assert.IsTrue(actual == expected, $"Error: {actual} was returned when {expected} was expected");
            }

            // Find the "Warehouse" location
            var location = db.FindLocations()
                           .Where(l => l.LocationName == "Warehouse")
                           .FirstOrDefault();

            // Find a supplier with lots of products
            var supplier = db.FindSuppliers(testCompany.Id)
                           .Where(s => s.Products.Count() > 100)
                           .FirstOrDefault();

            // Now create a purchase order with a large purchase order number
            var poh = new PurchaseOrderHeaderModel {
                CompanyId    = testCompany.Id,
                LocationId   = location.Id,
                POStatus     = Convert.ToInt32(LookupService.FindPurchaseOrderHeaderStatusListItemModel().First().Id),
                SupplierId   = supplier.Id,
                SupplierInv  = "INV" + RandomInt(1000, 9999).ToString(),
                RequiredDate = RandomDateTime(),
                OrderNumber  = 1000
            };

            var error = PurchasingService.InsertOrUpdatePurchaseOrderHeader(poh, user, "");

            Assert.IsTrue(!error.IsError, error.Message);

            // Check that the correct number is returned
            // On the first iteration, the next number should be one more than the largest purchase order number ie 1001
            for (int expected = 1001; expected <= 1010; expected++)
            {
                actual = LookupService.GetNextSequenceNumber(testCompany, SequenceNumberType.PurchaseOrderNumber);
                Assert.IsTrue(actual == expected, $"Error: {actual} was returned when {expected} was expected");
            }
        }
        public void CheckCompanyForPassedUnpackDatesTest()
        {
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser);

            EMailService.EMailService service = new EMailService.EMailService(db);
            service.EmptyEMailQueue();

            var task = new NotificationTask(db);

            // Check email queue - should be 0 added
            var expected = 0;

            task.CheckCompanyForPassedUnpackDates(testCompany);
            var actual = service.GetQueueCount();

            Assert.IsTrue(actual == expected, $"Error: Email Count returned {actual} when {expected} was expected");

            // Call email queue = 0 = actual
            // Create POs with Data > now
            var poStatuses = Enum.GetValues(typeof(PurchaseOrderStatus));
            var names      = Enum.GetNames(typeof(PurchaseOrderStatus));

            foreach (var value in Enum.GetValues(typeof(PurchaseOrderStatus)))
            {
                var po = GetTestPurchaseOrderHeader(testCompany, testUser);
                po.RealisticRequiredDate = DateTime.Now.AddDays((int)value);
                po.POStatus = (int)value;
                PurchasingService.InsertOrUpdatePurchaseOrderHeader(po, testUser, PurchasingService.LockPurchaseOrderHeader(po));
            }
            task.CheckCompanyForPassedUnpackDates(testCompany);
            actual = service.GetQueueCount();
            Assert.IsTrue(actual == expected, $"Error: Email Count returned {actual} when {expected} was expected");

            // Create POs with Data < now
            foreach (var value in Enum.GetValues(typeof(PurchaseOrderStatus)))
            {
                var po = GetTestPurchaseOrderHeader(testCompany, testUser);
                po.RealisticRequiredDate = DateTime.Now.AddDays((int)value - 100);
                po.POStatus = (int)value;
                PurchasingService.InsertOrUpdatePurchaseOrderHeader(po, testUser, PurchasingService.LockPurchaseOrderHeader(po));
            }
            expected = 9;
            task.CheckCompanyForPassedUnpackDates(testCompany);
            actual = service.GetQueueCount();
            Assert.IsTrue(actual == expected, $"Error: Email Count returned {actual} when {expected} was expected");
        }
Exemplo n.º 4
0
        public void FindUndeliveredPurchaseOrders2Test()
        {
            // Tests the TaskProcessor/emails
            // Get a test user and test company
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser, true);

            // Get the current email queue count
            db.EmptyEMailQueue();
            int beforeCount = db.FindEMailQueues().Count();

            var task = new NotificationTask(db);

            task.StartTask();

            int afterCount = db.FindEMailQueues().Count();

            Assert.IsTrue(afterCount == beforeCount, $"Error: The EMail queue contains {afterCount} item(s) when {beforeCount} were expected (1)");

            // Create some orders
            var order1 = GetTestPurchaseOrderHeader(testCompany, testUser, 10);
            var order2 = GetTestPurchaseOrderHeader(testCompany, testUser, 10);

            task.CheckCompanyForPassedUnpackDates(testCompany);

            // The orders are not overdue, so we should not have added any messages to the email queue
            afterCount = db.FindEMailQueues().Count();
            Assert.IsTrue(afterCount == beforeCount, $"Error: The EMail queue contains {afterCount} item(s) when {beforeCount} were expected (2)");

            // Now move the RealisticRequiredDate back so that the orders are overdue
            order1.RealisticRequiredDate = DateTimeOffset.Now.AddDays(RandomInt(1, 10) * -1);

            string lockGuid = PurchasingService.LockPurchaseOrderHeader(order1);

            PurchasingService.InsertOrUpdatePurchaseOrderHeader(order1, testUser, lockGuid);

            beforeCount = db.FindEMailQueues().Count();

            var error = task.CheckCompanyForPassedUnpackDates(testCompany);

            Assert.IsTrue(!error.IsError, error.Message);

            // We should have added a message to the email queue
            afterCount = db.FindEMailQueues().Count();
            int expected = 1 + beforeCount;

            Assert.IsTrue(afterCount == expected, $"Error: The EMail queue contains {afterCount} item(s) when {expected} were expected (3)");

            // Now move the other order back
            order2.RealisticRequiredDate = DateTimeOffset.Now.AddDays(RandomInt(1, 10) * -1);

            lockGuid = PurchasingService.LockPurchaseOrderHeader(order2);
            PurchasingService.InsertOrUpdatePurchaseOrderHeader(order2, testUser, lockGuid);

            beforeCount = db.FindEMailQueues().Count() - beforeCount;

            task.CheckCompanyForPassedUnpackDates(testCompany);

            // We should have added two messages
            afterCount = db.FindEMailQueues().Count();
            expected   = 2 + beforeCount;
            Assert.IsTrue(afterCount == expected, $"Error: The EMail queue contains {afterCount} item(s) when {expected} were expected (4)");

            // Now add another sales person to the user groups of the orders.
            // Note that each order could be a different brand category/group
            var testUser2     = GetTestUser();
            var brandCategory = ProductService.FindBrandCategoryModel(order1.BrandCategoryId.Value, testCompany, false);

            MembershipManagementService.AddUserToGroup(brandCategory.CategoryName + " Purchasing", testUser2);

            brandCategory = ProductService.FindBrandCategoryModel(order2.BrandCategoryId.Value, testCompany, false);
            MembershipManagementService.AddUserToGroup(brandCategory.CategoryName + " Purchasing", testUser2);

            beforeCount = db.FindEMailQueues().Count();

            task.CheckCompanyForPassedUnpackDates(testCompany);

            // We should have added another 4 messages
            afterCount = db.FindEMailQueues().Count();
            expected   = 2 + beforeCount;
            Assert.IsTrue(afterCount == expected, $"Error: The EMail queue contains {afterCount} item(s) when {expected} were expected (5)");

            // Put the orders forward
            order1.RealisticRequiredDate = DateTimeOffset.Now.AddDays(RandomInt(1, 10));

            lockGuid = PurchasingService.LockPurchaseOrderHeader(order1);
            PurchasingService.InsertOrUpdatePurchaseOrderHeader(order1, testUser, lockGuid);

            order2.RealisticRequiredDate = DateTimeOffset.Now.AddDays(RandomInt(1, 10));

            lockGuid = PurchasingService.LockPurchaseOrderHeader(order2);
            PurchasingService.InsertOrUpdatePurchaseOrderHeader(order2, testUser, lockGuid);

            beforeCount = db.FindEMailQueues().Count();

            task.CheckCompanyForPassedUnpackDates(testCompany);

            // We should not have added any more messages
            afterCount = db.FindEMailQueues().Count();
            expected   = 0 + beforeCount;
            Assert.IsTrue(afterCount == expected, $"Error: The EMail queue contains {afterCount} item(s) when {expected} were expected (6)");

            task.EndTask(0);
        }
Exemplo n.º 5
0
        public void FindUndeliveredPurchaseOrdersTest()
        {
            // Tests the service
            // Get a test user and test company
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser, true);

            // Should be no orders to start with
            var undeliveredOrders = PurchasingService.FindUndeliveredPurchaseOrders(testCompany);
            int expected          = 0,
                actual            = undeliveredOrders.Items.Count;

            Assert.IsTrue(actual == expected, $"Error: {actual} orders were returned when {expected} were expected (1)");


            // Create some orders
            var order1 = GetTestPurchaseOrderHeader(testCompany, testUser, 10);
            var order2 = GetTestPurchaseOrderHeader(testCompany, testUser, 10);

            undeliveredOrders = PurchasingService.FindUndeliveredPurchaseOrders(testCompany);
            expected          = 0;
            actual            = undeliveredOrders.Items.Count;
            Assert.IsTrue(actual == expected, $"Error: {actual} orders were returned when {expected} were expected (2)");

            // Now move the RealisticRequiredDate back so that the orders are overdue
            order1.RealisticRequiredDate = DateTimeOffset.Now.AddDays(RandomInt(1, 10) * -1);

            string lockGuid = PurchasingService.LockPurchaseOrderHeader(order1);

            PurchasingService.InsertOrUpdatePurchaseOrderHeader(order1, testUser, lockGuid);

            undeliveredOrders = PurchasingService.FindUndeliveredPurchaseOrders(testCompany);
            expected          = 1;
            actual            = undeliveredOrders.Items.Count;
            Assert.IsTrue(actual == expected, $"Error: {actual} orders were returned when {expected} were expected (3)");

            // Now move the other order back
            order2.RealisticRequiredDate = DateTimeOffset.Now.AddDays(RandomInt(1, 10) * -1);

            lockGuid = PurchasingService.LockPurchaseOrderHeader(order2);
            PurchasingService.InsertOrUpdatePurchaseOrderHeader(order2, testUser, lockGuid);

            undeliveredOrders = PurchasingService.FindUndeliveredPurchaseOrders(testCompany);
            expected          = 2;
            actual            = undeliveredOrders.Items.Count;
            Assert.IsTrue(actual == expected, $"Error: {actual} orders were returned when {expected} were expected (4)");

            // Put them forward
            order1.RealisticRequiredDate = DateTimeOffset.Now.AddDays(RandomInt(1, 10));

            lockGuid = PurchasingService.LockPurchaseOrderHeader(order1);
            PurchasingService.InsertOrUpdatePurchaseOrderHeader(order1, testUser, lockGuid);

            order2.RealisticRequiredDate = DateTimeOffset.Now.AddDays(RandomInt(1, 10));

            lockGuid = PurchasingService.LockPurchaseOrderHeader(order2);
            PurchasingService.InsertOrUpdatePurchaseOrderHeader(order2, testUser, lockGuid);

            undeliveredOrders = PurchasingService.FindUndeliveredPurchaseOrders(testCompany);
            expected          = 0;
            actual            = undeliveredOrders.Items.Count;
            Assert.IsTrue(actual == expected, $"Error: {actual} orders were returned when {expected} were expected (5)");
        }