TestingFramework icon indicating copy to clipboard operation
TestingFramework copied to clipboard

Project Sample Unit Tests do not run

Open Marco5793 opened this issue 8 months ago • 2 comments

Hello,

Thanks a lot for this great framework and all effort put in-here.

I am having a hard time running the project's sample unit tests.

I downloaded the framework and could successfully build the "LogicAppUnit.Samples.LogicApps.Tests" Solution. I ran all Azurite services (3) in the LogicAppUnit.Samples.LogicApps.LogicApps directory.

I tried then to run "dotnet test" in the "LogicAppUnit.Samples.LogicApps.Tests" directory but faced an error regarding JSON child access as you can read below: Failed BuiltInConnectorWorkflowTest_When_Invalid_Language_Code [2 ms] Error Message: Initialization method LogicAppUnit.Samples.LogicApps.Tests.BuiltInConnectorWorkflow.BuiltInConnectorWorkflowTest.TestInitialize threw exception. System.InvalidOperationException: Cannot access child value on Newtonsoft.Json.Linq.JValue.. Stack Trace: at Newtonsoft.Json.Linq.JToken.get_Item(Object key) at LogicAppUnit.Wrapper.ConnectionsWrapper.<>c.<ListManagedApiConnectionsUsingManagedServiceIdentity>b__5_0(JToken x) in C:\Users\myoucef\Downloads\TestingFramework-main-original\TestingFramework-main\src\LogicAppUnit\Wrapper\ConnectionsWrapper.cs:line 108 at System.Linq.Enumerable.WhereEnumerableIterator1.ToList() at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at LogicAppUnit.Wrapper.ConnectionsWrapper.ListManagedApiConnectionsUsingManagedServiceIdentity() in C:\Users\myoucef\Downloads\TestingFramework-main-original\TestingFramework-main\src\LogicAppUnit\Wrapper\ConnectionsWrapper.cs:line 108 at LogicAppUnit.WorkflowTestBase.ProcessConnectionsFile(String logicAppBasePath) in C:\Users\myoucef\Downloads\TestingFramework-main-original\TestingFramework-main\src\LogicAppUnit\WorkflowTestBase.cs:line 299 at LogicAppUnit.WorkflowTestBase.Initialize(String logicAppBasePath, String workflowName, String localSettingsFilename) in C:\Users\myoucef\Downloads\TestingFramework-main-original\TestingFramework-main\src\LogicAppUnit\WorkflowTestBase.cs:line 151
at LogicAppUnit.WorkflowTestBase.Initialize(String logicAppBasePath, String workflowName) in C:\Users\myoucef\Downloads\TestingFramework-main-original\TestingFramework-main\src\LogicAppUnit\WorkflowTestBase.cs:line 109 at LogicAppUnit.Samples.LogicApps.Tests.BuiltInConnectorWorkflow.BuiltInConnectorWorkflowTest.TestInitialize() in C:\Users\myoucef\Downloads\TestingFramework-main-original\TestingFramework-main\src\LogicAppUnit.Samples.LogicApps.Tests\BuiltInConnectorWorkflow\BuiltInConnectorWorkflowTest.cs:line 19

Standard Output Messages:


  •                          INITIALIZING TEST                               -    
    

Azurite is listening on ports 10000 (Blob service), 10001 (Queue service) and 10002 (Table service). Workflow 'built-in-connector-workflow' is Stateful Replacing workflow trigger 'When_messages_are_available_in_a_queue' with a HTTP Request trigger. Replacing workflow actions using a built-in connector with a HTTP action for the mock test server: Send_message_to_Topic: Connector Type: /serviceProviders/serviceBus/sendMessage Mocked URL: http://lududfea029:7075/Send_message_to_Topic Execute_Query_to_get_Language_Name: Connector Type: /serviceProviders/sql/executeQuery Mocked URL: http://lududfea029:7075/Execute_Query_to_get_Language_Name Using local settings file: local.settings.json Updating local settings file for 'https://external-service-one.testing.net': ServiceOne-Url: https://external-service-one.testing.net/api/v1 -> http://lududfea029:7075/api/v1 Updating local settings file for 'https://external-service-two.testing.net': ServiceTwo-Url: https://external-service-two.testing.net/api/v1.1 -> http://lududfea029:7075/api/v1.1 ServiceTwo-Verison2Url: https://external-service-two.testing.net/api/v2.0 -> http://lududfea029:7075/api/v2.0 Updating connections file for managed API connectors: salesforce: https://7606763fdc09952f.10.common.logic-uksouth.azure-apihub.net/apim/salesforce/fba515601ef14f9193eee596a9dcfd1c/ -> http://lududfea029:7075/apim/salesforce/fba515601ef14f9193eee596a9dcfd1c/ outlook: https://7606763fdc09952f.10.common.logic-uksouth.azure-apihub.net/apim/outlook/79a0bc680716416e90e17323b581695d/ -> http://lududfea029:7075/apim/outlook/79a0bc680716416e90e17323b581695d/

Failed! - Failed: 53, Passed: 0, Skipped: 0, Total: 53, Duration: 386 ms - LogicAppUnit.Samples.LogicApps.Tests.dll (net6.0)`

I am running the latest version of Azure Func Core tool : 4.0.6821 on VS Code.

Am I missing a step here?

Thanks a lot in advance. Marc

Marco5793 avatar Mar 03 '25 09:03 Marco5793

Hi @Marco5793 , thanks for raising this issue. I've not run into this specific issue, but I am aware of an issue when you open the sample Logic App project in VS Code and the VS Code Logic App Extension will update the connections.json, parameters.json and localSettings.json files and try to change the parameterisation of the connections. This then breaks the framework because it can't mock connections that reference parameters using @parameters(). But this gives a different error.

Just to be sure, can you check your connections.json, parameters.json and localSettings.json files and see if they have been updated by the extension? If they have, can you undo the changes and run the test again?

mark-abrams avatar Mar 04 '25 19:03 mark-abrams

Hi @mark-abrams , thanks a lot for your feedback and time to support. Indeed I saw this happening and was usually updating the connection.json file to put the full urls (as also mentioned in another open issue sorted as future enhancement). But then saw that the connection.json file itself in the repository was not containing the URL but parametrized as well.

So I manually updated the connection.json to put full urls for connectionRuntimeUrl, this helped some test to actually run but still lots of them fail from assert statement. 35 tests are successful over 53 currently.

For instance, the test BuiltInConnectorWorkflowTest_When_Valid_Language_Code fails because the workflow itself failed, thus assert line 110 fails from BuiltInConnectorWorkflowTest.cs

I am basically battling to have to BuiltInConnector Test cases running in the sample project as it is also failing for my own custom project. Probably it is a similar error as on my personal workflow, but not sure because my test is timing out: I have a service bus workflow that pulls from topic (peak lock) and then : sends some messages, sends Logs through managedAPI, decodes data form Integration Account, uploads a blob, ... You can have a quick look at the workflow here and there

so I am mocking with default response for all the "POST" and creating custom responses for all the "GET" like Read Blob Content and Decode with Integration Account. This looks like below for the Test method specifically: `

[TestMethod]
        public void BuiltInConnectorWorkflowTest_When_No_Language_Code()
        {
            using (ITestRunner testRunner = CreateTestRunner())
            {
                // Mock the SQL and Service Bus actions and customize responses
                // For both types of actions, the URI in the request matches the action name
            testRunner
                .AddMockResponse("MockServiceBusSendMessage_Payload",
                    MockRequestMatcher.Create()
                    .UsingPost()
                    .WithPath(PathMatchType.Exact, "/Send_message_Payload")
                    .FromAction("Send_message_Payload"))
                // No response content for Service Bus actions
                .RespondWithDefault();

            testRunner
                .AddMockResponse("MockServiceBusSendMessage_FA",
                    MockRequestMatcher.Create()
                    .UsingPost()
                    .WithPath(PathMatchType.Exact, "/Send_message_FA")
                    .FromAction("Send_message_FA"))
                // No response content for Service Bus actions
                .RespondWithDefault();

            testRunner
                .AddMockResponse("MockServiceBusSendMessage_Complete",
                    MockRequestMatcher.Create()
                    .UsingPost()
                    .WithPath(PathMatchType.Exact, "/Complete_the_message_in_a_topic_subscription")
                    .FromAction("Complete_the_message_in_a_topic_subscription"))
                // No response content for Service Bus actions
                .RespondWithDefault();

            testRunner
                .AddMockResponse("MockBlobUpload_Storage",
                    MockRequestMatcher.Create()
                    .UsingPost()
                    .WithPath(PathMatchType.Exact, "/Upload_blob_to_storage_container")
                    .FromAction("Upload_blob_to_storage_container"))
                // No response content for Service Bus actions
                .RespondWithDefault();

            testRunner
                .AddMockResponse("MockLAWSendData_LAW",
                    MockRequestMatcher.Create()
                    .UsingPost()
                    .WithPath(PathMatchType.Exact, "/Send_Data")
                    .FromAction("Send_Data"))
                // No response content for Service Bus actions
                .RespondWithDefault();

            // Mock the SQL and Service Bus actions and customize responses
            // For both types of actions, the URI in the request matches the action name
            testRunner.AddApiMocks = (request) =>
            {
                HttpResponseMessage mockedResponse = new HttpResponseMessage();
                if (request.RequestUri.AbsolutePath == "/Read_blob_content")
                {
                    mockedResponse.RequestMessage = request;
                    mockedResponse.StatusCode = HttpStatusCode.OK;
                    mockedResponse.Content = ContentHelper.CreateJsonStringContent(GetReadBlobResponse());
                }
                else if (request.RequestUri.AbsolutePath == "/X12_Decode")
                {
                    mockedResponse.RequestMessage = request;
                    mockedResponse.StatusCode = HttpStatusCode.OK;
                    mockedResponse.Content = ContentHelper.CreateJsonStringContent(GetX12DecodeResponse());
                }
                return mockedResponse;
            };

            // Run the workflow
            // The Service Bus trigger has been replaced with a HTTP trigger that uses a POST method
            var workflowResponse = testRunner.TriggerWorkflow(GetServiceBusMessageForTriggerNoLanguageCode(), HttpMethod.Post);

            // Check workflow run status
            Assert.AreEqual(WorkflowRunStatus.Succeeded, testRunner.WorkflowRunStatus);

            // Check the workflow termination status
            Assert.IsFalse(testRunner.WorkflowWasTerminated);
            Assert.IsNull(testRunner.WorkflowTerminationCode);
            Assert.IsNull(testRunner.WorkflowTerminationMessage);

            // Check workflow response
            // The workflow does not have a 'Response' action, so no content to validate
            Assert.AreEqual(HttpStatusCode.Accepted, workflowResponse.StatusCode);

            // Check action result
            // Assert.AreEqual(ActionStatus.Skipped, testRunner.GetWorkflowActionStatus("Execute_Query_to_get_Language_Name"));
            // Assert.AreEqual(ActionStatus.Skipped, testRunner.GetWorkflowActionStatus("Set_Language_Name"));
            // Assert.AreEqual(ActionStatus.Skipped, testRunner.GetWorkflowActionStatus("Terminate"));
            // Assert.AreEqual(ActionStatus.Succeeded, testRunner.GetWorkflowActionStatus("Send_message_to_Topic"));

            // Check message sent to Service Bus
            var serviceBusRequest = testRunner.MockRequests.First(r => r.RequestUri.AbsolutePath == "/Send_message_Payload");
            Assert.AreEqual(
                ContentHelper.FormatJson(ResourceHelper.GetAssemblyResourceAsString($"{GetType().Namespace}.MockData.ServiceBus_Request_payload.json")),
                ContentHelper.FormatJson(serviceBusRequest.Content));
        }
    }

` I do not know if this Framework can support a decoding task from Integration Account? It is using a callback url in the local.settings.json, should I be adding this url to the "externalApiUrlsToMock" setting maybe?

At this stage, It is timing out because of I guess below error while decoding: [2025-03-04T20:28:38.928Z] Outgoing HTTP request ends with server failure: correlationId='76e85286-562a-4034-8e85-d36bc59baf8a', operationName='GET/INTEGRATIONACCOUNTS/AGREEMENTS', httpMethod='GET', hostName='prod-25.canadacentral.logic.azure.com', targetUri='https://prod-25.canadacentral.logic.azure.com:443/integrationAccounts/90972c0cc5584f0ca8f76922cfcc88af/agreements?api-version=2015-08-01-preview&sp=%2f%2f*&sv=1.0&sig=*sanitized*&$top=*sanitized*', clientRequestId='e66afd1bd1554d3288d3c55a1da61e83', clientSessionId='', clientApplicationId='', apiVersion='2015-08-01-preview', contentLength='-1', serviceRequestId='', durationInMilliseconds='133', httpStatusCode='0', exceptionMessage='System.DllNotFoundException: Unable to load DLL 'System.IO.Compression.Native' or one of its dependencies: The specified module could not be found. (0x8007007E) [2025-03-04T20:28:38.929Z] at Interop.ZLib.InflateInit2_(ZStream* stream, Int32 windowBits) [2025-03-04T20:28:38.929Z] at System.IO.Compression.ZLibNative.ZLibStreamHandle.InflateInit2_(Int32 windowBits) [2025-03-04T20:28:38.930Z] at System.IO.Compression.Inflater.InflateInit(Int32 windowBits)', errorCode='', errorMessage='', referer='<null>', failureCause='', contentType='', contentEncoding='', armServiceRequestId='', organizationId='', activityVector='IN.0E', locale='en-US', additionalProperties='{"ParentActivityId":"00-b47a1be88e3046697391a57f107ca43c-6a5392cfa284de64-00"}', targetResourceProvider='', targetResourceType='', extensionVersion='1.94.69.0', siteName='UNDEFINED_SITE_NAME', slotName='', activityId='8c4156ed-c7e6-4353-a530-67f9655206f7'.

I am a bit lost to be honest and not sure where to look but I have a very critical dependency to this great unit test framework that I am really eager to successfully integrate to our project.

Thanks again for your time and dedication. Marc

Marco5793 avatar Mar 04 '25 21:03 Marco5793