From 054bd5b14f5ee0eb369fe513148e5e9c218efa3f Mon Sep 17 00:00:00 2001 From: Shankar Reddy Sama Date: Fri, 19 Jun 2026 12:00:21 -0700 Subject: [PATCH] Fix net48 test assembly binding issues and HttpClient mock - Add binding redirects for revision-number mismatches in both SF test projects (Microsoft.Extensions.Logging.Abstractions, System.Diagnostics.DiagnosticSource, System.Memory, System.Threading.Tasks.Extensions, Castle.Core, Newtonsoft.Json) - Fix HttpClient mock in FunctionalTests: mock HttpMessageHandler.SendAsync instead of non-virtual HttpClient.PutAsync - Add AzureServiceFabricTests.md with local test setup instructions - Update Newtonsoft.Json redirect to 13.0.0.0 (matching Directory.Packages.props) - Place all new files under active test/ directory (not legacy Test/) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- test/AzureServiceFabricTests.md | 55 +++++++++++++++++++ .../App.config | 22 +++++++- .../FunctionalTests.cs | 37 +++++-------- .../App.config | 31 +++++++++++ 4 files changed, 122 insertions(+), 23 deletions(-) create mode 100644 test/AzureServiceFabricTests.md create mode 100644 test/DurableTask.AzureServiceFabric.Tests/App.config diff --git a/test/AzureServiceFabricTests.md b/test/AzureServiceFabricTests.md new file mode 100644 index 000000000..125f6bc45 --- /dev/null +++ b/test/AzureServiceFabricTests.md @@ -0,0 +1,55 @@ +# Running Azure Service Fabric Tests Locally + +## Prerequisites + +### 1. Install Service Fabric SDK + +Follow the official guide to install the Service Fabric SDK and runtime: + +https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-get-started + +### 2. Start the Local Cluster (5-Node Configuration) + +1. Look for the **Service Fabric Local Cluster Manager** tray icon in the Windows system tray. +2. Right-click the tray icon. +3. Select **Start Local Cluster**. +4. Choose the **5 Node** configuration. +5. Wait for the cluster to finish initializing — the tray icon will change to indicate it's running. + +### 3. Build the Solution + +```powershell +dotnet build DurableTask.sln -c Debug -p:Platform=x64 +``` + +### 4. Package the Test Application + +1. Open the solution in Visual Studio. +2. In Solution Explorer, right-click **TestApplication** (`test\TestFabricApplication\TestApplication\TestApplication.sfproj`). +3. Click **Package**. + +This produces the Service Fabric application package needed by the integration tests. + +### 5. Run the Tests + +```powershell +# Unit tests +dotnet test test\DurableTask.AzureServiceFabric.Tests\DurableTask.AzureServiceFabric.Tests.csproj -c Debug -p:Platform=x64 + +# Integration tests (requires the local cluster and packaged application) +dotnet test test\DurableTask.AzureServiceFabric.Integration.Tests\DurableTask.AzureServiceFabric.Integration.Tests.csproj -c Debug -p:Platform=x64 +``` + +## Troubleshooting + +### Binding redirect / assembly load errors + +The `net48` test projects require binding redirects for assemblies with revision-number mismatches. If you see `FileNotFoundException` or `ReflectionTypeLoadException` errors, verify that `App.config` exists in each test project with the appropriate `` entries. + +The binding redirect files are located at: +- `test/DurableTask.AzureServiceFabric.Tests/App.config` (unit tests) +- `test/DurableTask.AzureServiceFabric.Integration.Tests/App.config` (integration tests) + +### Cluster not reachable + +If tests fail to connect to the local cluster, verify the cluster is running by opening **Service Fabric Explorer** at http://localhost:19080. diff --git a/test/DurableTask.AzureServiceFabric.Integration.Tests/App.config b/test/DurableTask.AzureServiceFabric.Integration.Tests/App.config index e936cc132..a62530332 100644 --- a/test/DurableTask.AzureServiceFabric.Integration.Tests/App.config +++ b/test/DurableTask.AzureServiceFabric.Integration.Tests/App.config @@ -4,7 +4,27 @@ - + + + + + + + + + + + + + + + + + + + + + diff --git a/test/DurableTask.AzureServiceFabric.Integration.Tests/FunctionalTests.cs b/test/DurableTask.AzureServiceFabric.Integration.Tests/FunctionalTests.cs index 448568d8a..10dc90b28 100644 --- a/test/DurableTask.AzureServiceFabric.Integration.Tests/FunctionalTests.cs +++ b/test/DurableTask.AzureServiceFabric.Integration.Tests/FunctionalTests.cs @@ -24,6 +24,7 @@ namespace DurableTask.AzureServiceFabric.Integration.Tests using DurableTask.Test.Orchestrations.Performance; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; + using Moq.Protected; using TestApplication.Common.Orchestrations; [TestClass] @@ -591,13 +592,24 @@ public async Task ScheduledStartTest_NotSupported() [TestMethod] public async Task CreateTaskOrchestration_HandlesConflictResponse_When_HttpClientReturnsNullContent() { - var httpClientMock = new Mock(); var response = new HttpResponseMessage(System.Net.HttpStatusCode.Conflict) { Content = null }; - SetupHttpClientMockForPut(httpClientMock, response); + var mockHandler = new Mock(); + mockHandler + .Protected() + .Setup>( + "SendAsync", + ItExpr.IsAny(), + ItExpr.IsAny()) + .ReturnsAsync(response); + + var httpClient = new HttpClient(mockHandler.Object) + { + BaseAddress = new Uri("http://localhost") + }; var taskHubClient = Utilities.CreateTaskHubClient((serviceClient) => { - serviceClient.HttpClient = httpClientMock.Object; + serviceClient.HttpClient = httpClient; }); await Assert.ThrowsExceptionAsync(async () => @@ -605,24 +617,5 @@ await Assert.ThrowsExceptionAsync(async () await taskHubClient.CreateOrchestrationInstanceAsync(typeof(TestOrchestration), new TestOrchestrationData()); }); } - - private static void SetupHttpClientMockForPut(Mock httpClientMock, HttpResponseMessage response) - { - httpClientMock - .Setup(x => x.PutAsync(It.IsAny(), It.IsAny())) - .ReturnsAsync(response); - - httpClientMock - .Setup(x => x.PutAsync(It.IsAny(), It.IsAny())) - .ReturnsAsync(response); - - httpClientMock - .Setup(x => x.PutAsync(It.IsAny(), It.IsAny(), It.IsAny())) - .ReturnsAsync(response); - - httpClientMock - .Setup(x => x.PutAsync(It.IsAny(), It.IsAny(), It.IsAny())) - .ReturnsAsync(response); - } } } diff --git a/test/DurableTask.AzureServiceFabric.Tests/App.config b/test/DurableTask.AzureServiceFabric.Tests/App.config new file mode 100644 index 000000000..38337d7bd --- /dev/null +++ b/test/DurableTask.AzureServiceFabric.Tests/App.config @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +