public void FindPurchasersListItemModelTest() { var testUser = GetTestUser(); var testCompany = GetTestCompany(testUser, true); int itemCount = RandomInt(5, 15); var testOrder = GetTestPurchaseOrderHeader(testCompany, testUser, itemCount); var brandCat = ProductService.FindBrandCategoryModel(testOrder.BrandCategoryId.Value, testCompany, false); string errorMsg = ""; var purchasers = PurchasingService.FindOrderPurchasers(testOrder, testCompany, testOrder.OrderNumber.Value, ref errorMsg); int expected = 1, actual = purchasers.Count(); Assert.IsTrue(actual == expected, $"Error: {actual} Purchaser(s) were found when {expected} were expected"); // No add some more users to the same user group as the purchaser var testPurchaser1 = GetTestUser(); MembershipManagementService.AddUserToGroup(brandCat.CategoryName + " Purchasing", testPurchaser1); var testPurchaser2 = GetTestUser(); MembershipManagementService.AddUserToGroup(brandCat.CategoryName + " Purchasing", testPurchaser2); purchasers = PurchasingService.FindOrderPurchasers(testOrder, testCompany, testOrder.OrderNumber.Value, ref errorMsg); expected = 3; actual = purchasers.Count(); Assert.IsTrue(actual == expected, $"Error: {actual} Purchaser(s) were found when {expected} were expected"); }
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); }
public void FindOrderPurchasersTest() { var testUser = GetTestUser(); var testCompany = GetTestCompany(testUser, true); // Create a purchase var poh = GetTestPurchaseOrderHeader(testCompany, testUser, 10); var brandCategory = ProductService.FindBrandCategoryModel(poh.BrandCategoryId.Value, testCompany, false); string userGroup = brandCategory.CategoryName + " purchasing"; MembershipManagementService.AddUserToGroup(userGroup, testUser); // Get the users string errorMsg = ""; var users = PurchasingService.FindOrderPurchasers(poh, testCompany, poh.OrderNumber.Value, ref errorMsg); Assert.IsTrue(users != null, errorMsg); int expected = 1, actual = users.Count(); Assert.IsTrue(actual == expected, $"Error: {actual} user(s) were returned when {expected} were expected"); // Add some more users var testUser2 = GetTestUser(); MembershipManagementService.AddUserToGroup(userGroup, testUser2); var testUser3 = GetTestUser(); MembershipManagementService.AddUserToGroup(userGroup, testUser3); users = PurchasingService.FindOrderPurchasers(poh, testCompany, poh.OrderNumber.Value, ref errorMsg); Assert.IsTrue(users != null, errorMsg); expected = 3; actual = users.Count(); Assert.IsTrue(actual >= expected, $"Error: {actual} user(s) were returned when {expected} were expected"); // Now remove one and try again MembershipManagementService.DeleteUser(testUser2); users = PurchasingService.FindOrderPurchasers(poh, testCompany, poh.OrderNumber.Value, ref errorMsg); Assert.IsTrue(users != null, errorMsg); expected = 2; actual = users.Count(); Assert.IsTrue(actual >= expected, $"Error: {actual} user(s) were returned when {expected} were expected"); // Now delete another and try again MembershipManagementService.DeleteUser(testUser3); users = PurchasingService.FindOrderPurchasers(poh, testCompany, poh.OrderNumber.Value, ref errorMsg); Assert.IsTrue(users != null, errorMsg); expected = 1; actual = users.Count(); Assert.IsTrue(actual >= expected, $"Error: {actual} user(s) were returned when {expected} were expected"); }