Ejemplo n.º 1
0
        public async Task GoodRequest_Success()
        {
            // Create mock data to be tested
            var request = new Models.APIRequest
            {
                homeTeam     = "Corinthians",
                awayTeam     = "Chelsea",
                customerName = "Alessandro Moura",
                date         = DateTime.Now.ToString("2012-12-16T21:00:00"),
                postTwitter  = false,
                price        = 150
            };

            // Call Logic App
            var result = await CallLogicApp <Models.APIRequest>(request, "any");

            // Receive Logic App response
            var response = await GetHttpResponseMessage <Models.LogicAppsErrorResponse>(result);

            // Verify that the http code returned is 202 (Accepted)
            string details = response.error != null ? response.error.message : string.Empty;

            Assert.IsTrue(result.StatusCode == System.Net.HttpStatusCode.Accepted,
                          $"Expected '{System.Net.HttpStatusCode.Accepted}' but received '{result.StatusCode}. Details: {details}'");

            // Obtain LogicApps RunId to investigate its actions
            var runId = result.Headers.GetValues("x-ms-workflow-run-id").First();

            while (true)
            {
                // Get Logic App execution status
                var workflowStatus = await LogicAppClient.WorkflowRuns.GetAsync(ResourceGroupName, LogicAppName, runId);

                // Await workflow completion to retrieve the action result
                if (workflowStatus.Status == WorkflowStatus.Succeeded || workflowStatus.Status == WorkflowStatus.Failed)
                {
                    // Get HTTP call status
                    var httpAction = await LogicAppClient.WorkflowRunActions.GetAsync(ResourceGroupName, LogicAppName, runId, "Buy_Ticket");

                    Assert.IsTrue(httpAction.Code == "OK", "Response not expected!",
                                  $"Expected 'OK' but received '{httpAction.Code}'");

                    var httpActionResponse = await LogicAppClient.HttpClient.GetAsync(httpAction.OutputsLink.Uri);

                    var httpActionResponseContent = await GetHttpResponseMessage <Models.APIResponse>(httpActionResponse, true);

                    Assert.IsTrue(httpActionResponseContent.mensagem == "Vai Corinthians!!!");

                    // Get Log Storage account
                    var storageAction = await LogicAppClient.WorkflowRunActions.GetAsync(ResourceGroupName, LogicAppName, runId, "Log_Buy_Ticket_Success");

                    Assert.IsTrue(storageAction.Code == "Created", "Response not expected!",
                                  $"Expected 'Created' but received '{storageAction.Code}'");

                    break;
                }
                Thread.Sleep(500);
            }
        }
Ejemplo n.º 2
0
        public async Task SchemaBadRequest_Missing_RequiredFields_SimplerCode()
        {
            var tenantId       = Environment.GetEnvironmentVariable("ACSUG_TENANT_ID");
            var clientId       = Environment.GetEnvironmentVariable("ACSUG_CLIENT_ID");
            var clientSecret   = Environment.GetEnvironmentVariable("ACSUG_CLIENT_SECRET");
            var subscriptionId = Environment.GetEnvironmentVariable("ACSUG_SUBSCRIPTION_ID");

            // Get credentials
            var context     = new AuthenticationContext($"https://login.windows.net/{tenantId}");
            var credentials = new ClientCredential(clientId, clientSecret);
            var result      = await context.AcquireTokenAsync("https://management.core.windows.net/", credentials);

            string token            = result.CreateAuthorizationHeader().Substring("Bearer ".Length);
            var    tokenCredentials = new TokenCredentials(token);

            // Use Logic Apps Management
            var logicAppsClient = new LogicManagementClient(tokenCredentials);

            logicAppsClient.SubscriptionId = subscriptionId;

            // Retrieve Logic Apps Uri
            var url = await logicAppsClient.WorkflowTriggers.ListCallbackUrlWithHttpMessagesAsync("ACSUG-LogicApps-Testing", "lapp-buyticketcorinthians-dev", "manual");

            // Create mock data to be tested
            var request = new Models.APIRequest
            {
                price = 0
            };

            // Serialize payload
            var serializerOptions = new JsonSerializerOptions {
                IgnoreNullValues = true
            };
            var requestContent = new StringContent(JsonSerializer.Serialize <Models.APIRequest>(
                                                       request, serializerOptions), Encoding.UTF8, "application/json");

            var httpClient = new HttpClient();
            var response   = await httpClient.PostAsync(new Uri(url.Body.Value), requestContent);

            var responseContent = await response.Content.ReadAsStreamAsync();

            var logicAppsResponse = await JsonSerializer.DeserializeAsync <Models.LogicAppsErrorResponse>(responseContent, serializerOptions);

            // Verify that the Http code returned is 400 (BadRequest)
            Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.BadRequest, $"Expected '{System.Net.HttpStatusCode.BadRequest}' but received '{response.StatusCode}. Details: {logicAppsResponse.error.message}'");
            Assert.AreEqual(logicAppsResponse.error.code, "TriggerInputSchemaMismatch", $"Expected 'TriggerInputSchemaMismatch' but received '{logicAppsResponse.error.code}. Details: {logicAppsResponse.error.message}'");
            Assert.IsTrue(logicAppsResponse.error.message.Contains("Required properties are missing from object") &&
                          logicAppsResponse.error.message.Contains("customerName") &&
                          logicAppsResponse.error.message.Contains("date") &&
                          logicAppsResponse.error.message.Contains("homeTeam") &&
                          logicAppsResponse.error.message.Contains("awayTeam"),
                          $"Error message received not matching the expected: '{logicAppsResponse.error.message}'");
        }
Ejemplo n.º 3
0
        public async Task SchemaBadRequest_NotInEnum_HomeTeam()
        {
            // Create mock data to be tested
            var request = new Models.APIRequest
            {
                homeTeam = "Invalid Team"
            };

            await SchemaBadRequest_TestBase <Models.APIRequest>(
                request,
                x => x.error.message.Contains("Value \"Invalid Team\" is not defined in enum."));
        }
Ejemplo n.º 4
0
        public async Task SchemaBadRequest_MinimumLengthNotMet_CustomerName()
        {
            // Create mock data to be tested
            var request = new Models.APIRequest
            {
                customerName = "X"
            };

            await SchemaBadRequest_TestBase <Models.APIRequest>(
                request,
                x => x.error.message.Contains("String 'X' is less than minimum length of 10"));
        }
Ejemplo n.º 5
0
        public async Task SchemaBadRequest_Missing_RequiredFields()
        {
            // Create mock data to be tested
            var request = new Models.APIRequest();

            await SchemaBadRequest_TestBase <Models.APIRequest>(
                request,
                x => x.error.message.Contains("Required properties are missing from object") &&
                x.error.message.Contains("customerName") &&
                x.error.message.Contains("date") &&
                x.error.message.Contains("homeTeam") &&
                x.error.message.Contains("awayTeam"));
        }
Ejemplo n.º 6
0
        public async Task SchemaBadRequest_WrongDataType_ExpectedBoolean()
        {
            // Create mock data to be tested
            var request = new Models.APIRequest
            {
                postTwitter = "true"
            };


            await SchemaBadRequest_TestBase <Models.APIRequest>(
                request,
                x => x.error.message.Contains("Invalid type") &&
                x.error.message.Contains("Expected Boolean but got "));
        }
Ejemplo n.º 7
0
        public async Task SchemaBadRequest_WrongDataType_ExpectedNumber()
        {
            // Create mock data to be tested
            var request = new Models.APIRequest
            {
                price = "1.00"
            };


            await SchemaBadRequest_TestBase <Models.APIRequest>(
                request,
                x => x.error.message.Contains("Invalid type") &&
                x.error.message.Contains("Expected Number but got "));
        }
        public async Task WorkflowBadRequest_ErrorAPI()
        {
            // Create mock data to be tested
            var request = new Models.APIRequest
            {
                awayTeam     = "Palmeiras",
                homeTeam     = "Corinthians",
                customerName = "Alessandro Moura",
                date         = DateTime.Now.ToString("yyyy-MM-ddThh:mm:ss"),
                postTwitter  = false,
                price        = 150
            };

            await WorkflowBadRequest_TestBase(
                request,
                x => x.message.Contains("Palmeiras does not have a Clubs World Cup"),
                "1951 by fax does not matter");
        }
Ejemplo n.º 9
0
        public async Task NonHttpTrigger()
        {
            var tenantId       = Environment.GetEnvironmentVariable("ACSUG_TENANT_ID");
            var clientId       = Environment.GetEnvironmentVariable("ACSUG_CLIENT_ID");
            var clientSecret   = Environment.GetEnvironmentVariable("ACSUG_CLIENT_SECRET");
            var subscriptionId = Environment.GetEnvironmentVariable("ACSUG_SUBSCRIPTION_ID");

            // Get credentials
            var context     = new AuthenticationContext($"https://login.windows.net/{tenantId}");
            var credentials = new ClientCredential(clientId, clientSecret);
            var result      = await context.AcquireTokenAsync("https://management.core.windows.net/", credentials);

            string token            = result.CreateAuthorizationHeader().Substring("Bearer ".Length);
            var    tokenCredentials = new TokenCredentials(token);

            // Use Logic Apps Management
            var logicAppsClient = new LogicManagementClient(tokenCredentials);

            logicAppsClient.SubscriptionId = subscriptionId;

            // Retrieve Logic Apps Uri
            var xxx = logicAppsClient.WorkflowTriggers.Run("ACSUG-LogicApps-Testing", "lapp-nonhttptrigger-dev", "When_a_blob_is_added_or_modified_(properties_only)");

            // Create mock data to be tested
            var request = new Models.APIRequest
            {
                price = 0
            };

            // Serialize payload
            var serializerOptions = new JsonSerializerOptions {
                IgnoreNullValues = true
            };
            var requestContent = new StringContent(JsonSerializer.Serialize <Models.APIRequest>(
                                                       request, serializerOptions), Encoding.UTF8, "application/json");

            /*var httpClient = new HttpClient();
             * var response = await httpClient.PostAsync(new Uri(url.Body.Value), requestContent);
             *
             * var responseContent = await response.Content.ReadAsStreamAsync();
             * var logicAppsResponse = await JsonSerializer.DeserializeAsync<Models.LogicAppsErrorResponse>(responseContent, serializerOptions);*/
        }