Exemple #1
0
        public async Task <RecentProjectModel[]> Trigger(
            [ActivityTrigger]
            GetRecentProjects request,
            ILogger log,
            CancellationToken ct)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            return(await Mediator.Send(request, ct));
        }
Exemple #2
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)]
            GetRecentProjects request,
            ILogger log,
            CancellationToken ct)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            return(await RunRequest(request, ct));
        }
        public async Task ShouldReturnNull()
        {
            var query = new GetRecentProjectsHandler();

            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWith("", 200);

                var request = new GetRecentProjects("http://tntUrl.xyz", "JEK", "token-1");
                var result  = await query.Execute(request);

                result.Should().BeNull("empty string results in null");
                httpTest.CallLog.Should().HaveCount(1, "should not fail");
                httpTest
                .ShouldHaveCalled("http://tntUrl.xyz/Ajax/GetPreviousProjects?empID=JEK")
                // TimePro bug: Basic auth is not base64 decoded on the server and takes the raw token.
                //.WithBasicAuth("token-1", string.Empty)
                .Times(1);
            }
        }
        public async Task ShouldRecentProjects()
        {
            var query = new GetRecentProjectsHandler();

            using (var httpTest = new HttpTest())
            {
                string response = "[{\"Client\":\"SSWTest\",\"ClientID\":\"SSW\",\"Project\":\"Non-working day (e.g. Leave)\",\"ProjectID\":\"LEAVE\",\"Iteration\":null,\"IterationId\":null,\"Category\":\"Non-working day - Public Holiday\",\"CategoryID\":\"LNWD\",\"DateCreated\":\"\\/Date(1556200800000)\\/\"}]";
                httpTest.RespondWith(response, 200);

                var request = new GetRecentProjects("http://tntUrl.xyz", "JEK", "token-1");
                var result  = await query.Execute(request);

                result.Should().HaveCount(1, "raw JSON response has only one response");
                httpTest.CallLog.Should().HaveCount(1, "should not fail");
                httpTest
                .ShouldHaveCalled("http://tntUrl.xyz/Ajax/GetPreviousProjects?empID=JEK")
                // TimePro bug: Basic auth is not base64 decoded on the server and takes the raw token.
                //.WithBasicAuth("token-1", string.Empty)
                .Times(1);
            }
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string tenantUrl = req.Query["tenantUrl"];
            string empID     = req.Query["empID"];
            string token     = req.Query["token"];

            var validationModel = Validate(tenantUrl, empID, token);

            if (!validationModel.IsValid)
            {
                return(new BadRequestObjectResult(validationModel));
            }

            var request = new GetRecentProjects(tenantUrl, empID, token);
            var result  = await _getRecentProjectsQuery.Execute(request);

            return(new JsonResult(result));
        }