Exemple #1
0
        public async Task UnauthorizedListAttempt()
        {
            using var usersContext = await BuildUsersContext();

            var authController = new AuthenticationController(usersContext);

            using var jobsContext = await BuildJobsContext();

            var jobsController = new JobAidController(jobsContext, authController);

            // get the list of jobs using a random, unexisting token
            var result = await jobsController.ListJobs(239048923);

            Assert.IsInstanceOfType(result, typeof(UnauthorizedResult));
        }
Exemple #2
0
        public async Task ListJobs()
        {
            using var usersContext = await BuildUsersContext();

            var authController = new AuthenticationController(usersContext);

            using var jobsContext = await BuildJobsContext();

            var jobsController = new JobAidController(jobsContext, authController);

            // log in
            dynamic result = await authController.Login(
                new AuthenticationLoginModel { Username = "******", Password = "******" });

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual(result.StatusCode, 200);

            // get the token
            var token = (ulong)Support.Get(result.Value, "token");

            // get the list of jobs
            result = await jobsController.ListJobs(token);

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            Assert.AreEqual(result.StatusCode, 200);

            // test the username
            var username = (string)Support.Get(result.Value, "username");

            Assert.AreEqual(username, "uname1");

            // test the array of jobs
            dynamic jobs = Support.Get(result.Value, "jobs");

            foreach (var job in jobs)
            {
                var jobId = (int)Support.Get(job, "JobId");
                var name  = (string)Support.Get(job, "Name");
                Assert.IsNotNull(name);
            }
        }