public async Task ShouldReturnRate()
        {
            var query = new GetClientRateQuery();

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

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

                result.Should().NotBeNull("both rates are available");
                result.ClientEmpRate.Should().Be(245m, "service is returning \"245\" for client rate as JSON-ish single number.");
                result.ClientTaxRate.Should().Be(0.1m, "service is returning \"0.10000\" for client tax rate as JSON-ish single number.");
                httpTest.CallLog.Should().HaveCount(2, "should not fail");
                httpTest
                .ShouldHaveCalled("http://tntUrl.xyz/Ajax/GetClientRate?empID=JEK&clientID=SSW")
                // TimePro bug: Basic auth is not base64 decoded on the server and takes the raw token.
                //.WithBasicAuth("token-1", string.Empty)
                .Times(1);

                httpTest
                .ShouldHaveCalled("http://tntUrl.xyz/Ajax/GetClientTaxRate?clientID=SSW&timesheetID=0")
                // TimePro bug: Basic auth is not base64 decoded on the server and takes the raw token.
                //.WithBasicAuth("token-1", string.Empty)
                .Times(1);
            }
        }
Esempio n. 2
0
        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 clientID  = req.Query["clientID"];
            string token     = req.Query["token"];

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

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

            var request = new GetClientRateRequest(tenantUrl, empID, clientID, token);
            var result  = await _getClientRateQuery.Execute(request);

            return(new JsonResult(result));
        }
        public async Task ShouldReturnNull(string clientRateString, string clientTaxString, double?clientRate, double?clientTaxRate)
        {
            var query = new GetClientRateQuery();

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

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

                result.Should().NotBeNull("even if both rates are null, this should not be null");
                result.ClientEmpRate.Should().Be((decimal?)clientRate, "service is returning \"\" and is parsed as null.");
                result.ClientTaxRate.Should().Be((decimal?)clientTaxRate, "service is returning \"\" and is parsed as null.");
                httpTest.CallLog.Should().HaveCount(2, "should not fail");
                httpTest
                .ShouldHaveCalled("http://tntUrl.xyz/Ajax/GetClientRate?empID=JEK&clientID=SSW")
                // TimePro bug: Basic auth is not base64 decoded on the server and takes the raw token.
                //.WithBasicAuth("token-1", string.Empty)
                .Times(1);
            }
        }