public void LockTaskTest()
        {
            // Get a test user and test company
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser);

            TaskManagerService.TaskManagerService taskManagerService = new TaskManagerService.TaskManagerService(db, testCompany);

            // Create a task
            var model = createTestTask(testCompany, testUser);
            var error = taskManagerService.InsertOrUpdateTask(model, "");

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

            // Get the current Lock
            string lockGuid = taskManagerService.LockTask(model);

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

            // Simulate another user updating the record
            var otherUser = GetTestUser();

            error = taskManagerService.InsertOrUpdateTask(model, lockGuid);
            Assert.IsTrue(!error.IsError, error.Message);

            // Now get the first user to update the record
            error = taskManagerService.InsertOrUpdateTask(model, 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 = taskManagerService.LockTask(model);
            error    = taskManagerService.InsertOrUpdateTask(model, lockGuid);
            Assert.IsTrue(!error.IsError, $"Error: {error.Message}");
        }
        public void GetTaskCountTest()
        {
            // Get a test user and test company
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser);

            TaskManagerService.TaskManagerService taskManagerService = new TaskManagerService.TaskManagerService(db, testCompany);

            // Now create a task and try to search for it
            int expected = taskManagerService.GetTaskCount();   // Start count

            for (int i = 0; i < 10; i++)
            {
                int rand = RandomInt(5, 20);
                for (int j = 0; j < rand; j++)
                {
                    var testTask = createTestTask(testCompany, testUser);
                    var error    = taskManagerService.InsertOrUpdateTask(testTask, "");
                    Assert.IsTrue(!error.IsError, error.Message);
                }
                expected += rand;

                int actual = taskManagerService.GetTaskCount();
                Assert.IsTrue(actual == expected, $"Error: {actual} items were found when {expected} were expected ");
            }
        }
        public void FindTaskModelTest()
        {
            // Get a test user and test company
            var testUser    = GetTestUser();
            var testCompany = GetTestCompany(testUser);

            TaskManagerService.TaskManagerService taskManagerService = new TaskManagerService.TaskManagerService(db, testCompany);

            // Now create a task and try to search for it
            var testTask = createTestTask(testCompany, testUser);
            var error    = taskManagerService.InsertOrUpdateTask(testTask, "");

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

            var result = taskManagerService.FindTaskModel(testTask.Id, testCompany, testUser, false);

            Assert.IsTrue(result != null, $"Error: 0 records were returned when 1 was expected");
            Assert.IsTrue(result.Id == testTask.Id, $"Error: Supplier {result.Id} was returned when {testTask.Id} was expected");
            AreEqual(testTask, result);
        }