From f34409696d8ab0604e5abcdb5277c7a831c595aa Mon Sep 17 00:00:00 2001 From: Craig Fowler Date: Thu, 25 Feb 2021 08:24:00 +0000 Subject: [PATCH] Should resolve #653 - Reinstate tests in CI process for v2 branch (#658) * WIP #653 - Delete two tests These two couldn't easily be fixed, in both cases they were integration tests which involved passing through many classes. It wasn't immediately clear what needed to be done to fix them. As noted in the issue description, removing them was an acceptable fix. * WIP #653 - Fix a failing test I split this test into two. Per the discussion at: https://github.com/xunit/xunit/issues/350 XUnit seems quite opinonated about not having assertion messages. Thus, without changing assertion library (which deserves discussion before I just do it), the logical next best thing is to split into two single-assert tests, so it's clear which assertion failed on a test failure. Also, I moved the AutoMoqData attribute to the shared test lib, so that it can be used anywhere. That allowed me to eliminate the constructor for this test class, except for initialising the base class. * Provisionally resolve #653 - reinstate tests in CI This should complete the issue although we need to see a passing CI build with this code change before we can say it's done. * Provisionally resolves #653 - Add test script --- appveyor.yml | 3 +- .../WorkflowDefinitions/SaveTests.cs | 48 ------------------- .../Elsa.Core.IntegrationTests.csproj | 6 ++- .../StorageWorkflowProviderTests.cs | 32 ------------- .../Workflows/FinishWorkflowTests.cs | 27 ++++++----- .../AutoMoqDataAttribute.cs | 0 6 files changed, 21 insertions(+), 95 deletions(-) delete mode 100644 test/component/Elsa.ComponentTests/Clients/RestClient/WorkflowDefinitions/SaveTests.cs delete mode 100644 test/integration/Elsa.Core.IntegrationTests/StorageProvider/StorageWorkflowProviderTests.cs rename test/{unit/Elsa.UnitTests => shared/Elsa.Testing.Shared}/AutoMoqDataAttribute.cs (100%) diff --git a/appveyor.yml b/appveyor.yml index ec72dc0db..cec1ae950 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -41,7 +41,8 @@ cd ..\..\..\..\ dotnet pack Elsa.sln --include-symbols /p:Version=$env:APPVEYOR_BUILD_VERSION - test: off + test_script: + - ps: dotnet test artifacts: - path: '**/*.nupkg' name: MyGet diff --git a/test/component/Elsa.ComponentTests/Clients/RestClient/WorkflowDefinitions/SaveTests.cs b/test/component/Elsa.ComponentTests/Clients/RestClient/WorkflowDefinitions/SaveTests.cs deleted file mode 100644 index 05ac3f6da..000000000 --- a/test/component/Elsa.ComponentTests/Clients/RestClient/WorkflowDefinitions/SaveTests.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using AutoFixture; -using Elsa.Activities.Console; -using Elsa.Client.Models; -using Elsa.ComponentTests.Helpers; -using Xunit; - -namespace Elsa.ComponentTests.Clients.RestClient.WorkflowDefinitions -{ - [Collection(ComponentTestsCollection.Name)] - public class SaveTests : ElsaClientTestBase - { - public SaveTests(ElsaHostApplicationFactory hostApplicationFactory) : base(hostApplicationFactory) - { - } - - [Fact(DisplayName = "Saving a new workflow definition returns HTTP 201.")] - public async Task Post01() - { - var request = CreateSaveWorkflowRequest(); - var workflowDefinition = await ElsaClient.WorkflowDefinitions.SaveAsync(request); - Assert.Equal(request.Name, workflowDefinition.Name); - } - - private SaveWorkflowDefinitionRequest CreateSaveWorkflowRequest() - { - var writeLine = new ActivityDefinition - { - ActivityId = Fixture.Create(), - Type = nameof(WriteLine), - Properties = new List() - { - ActivityDefinitionProperty.Literal(nameof(WriteLine.Text), "Hello World!") - } - }; - - var readLine = new ActivityDefinition {ActivityId = Fixture.Create(), Type = nameof(ReadLine)}; - var activities = new[] {writeLine, readLine}; - var connections = new[] {new ConnectionDefinition(writeLine.ActivityId, readLine.ActivityId, OutcomeNames.Done)}; - - return Fixture.Build() - .With(x => x.Activities, activities) - .With(x => x.Connections, connections) - .Create(); - } - } -} \ No newline at end of file diff --git a/test/integration/Elsa.Core.IntegrationTests/Elsa.Core.IntegrationTests.csproj b/test/integration/Elsa.Core.IntegrationTests/Elsa.Core.IntegrationTests.csproj index 0dc32fbde..c9a1d3c0a 100644 --- a/test/integration/Elsa.Core.IntegrationTests/Elsa.Core.IntegrationTests.csproj +++ b/test/integration/Elsa.Core.IntegrationTests/Elsa.Core.IntegrationTests.csproj @@ -7,9 +7,11 @@ - - + + + + diff --git a/test/integration/Elsa.Core.IntegrationTests/StorageProvider/StorageWorkflowProviderTests.cs b/test/integration/Elsa.Core.IntegrationTests/StorageProvider/StorageWorkflowProviderTests.cs deleted file mode 100644 index d2717f9d6..000000000 --- a/test/integration/Elsa.Core.IntegrationTests/StorageProvider/StorageWorkflowProviderTests.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Threading.Tasks; -using Elsa.Core.IntegrationTests.Helpers; -using Elsa.Models; -using Elsa.Testing.Shared.Unit; -using Microsoft.Extensions.DependencyInjection; -using Storage.Net.Blobs; -using Xunit; -using Xunit.Abstractions; - -namespace Elsa.Core.IntegrationTests.StorageProvider -{ - public class StorageWorkflowProviderTests : WorkflowsUnitTestBase - { - public StorageWorkflowProviderTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) - { - } - - [Fact(DisplayName = "Runs workflows provided by storage provider")] - public async Task Test01() - { - const string workflowFileName = "hello-world-workflow.json"; - const string workflowName = "SampleWorkflow"; - var json = await AssetHelper.ReadAssetAsync(workflowFileName); - var storage = ServiceProvider.GetRequiredService(); - await storage.WriteTextAsync(workflowFileName, json); - var workflowBlueprint = await WorkflowRegistry.GetWorkflowAsync(workflowName, VersionOptions.Published); - var workflowInstance = await WorkflowRunner.RunWorkflowAsync(workflowBlueprint!); - - Assert.Equal(WorkflowStatus.Finished, workflowInstance.WorkflowStatus); - } - } -} \ No newline at end of file diff --git a/test/integration/Elsa.Core.IntegrationTests/Workflows/FinishWorkflowTests.cs b/test/integration/Elsa.Core.IntegrationTests/Workflows/FinishWorkflowTests.cs index a13f981cd..e3c6e7245 100644 --- a/test/integration/Elsa.Core.IntegrationTests/Workflows/FinishWorkflowTests.cs +++ b/test/integration/Elsa.Core.IntegrationTests/Workflows/FinishWorkflowTests.cs @@ -1,5 +1,6 @@ using System.Threading.Tasks; using AutoFixture; +using AutoFixture.Xunit2; using Elsa.Models; using Elsa.Testing.Shared.Unit; using Xunit; @@ -9,22 +10,24 @@ namespace Elsa.Core.IntegrationTests.Workflows { public class FinishWorkflowTests : WorkflowsUnitTestBase { - private readonly Fixture _fixture; + public FinishWorkflowTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) {} - public FinishWorkflowTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) + [Theory(DisplayName = "Sets the workflow status of the workflow instance to WorkflowStatus.Finished after RunWorkflowAsync is used"), AutoMoqData] + public async Task RunWorkflowAsyncShouldSetWorkflowStatusToFinished(FinishWorkflow sut) { - _fixture = new Fixture(); - } - - [Fact(DisplayName = "Sets the workflow output to the specified value")] - public async Task Test01() - { - var output = _fixture.Create(); - var workflow = new FinishWorkflow(output); - var workflowInstance = await WorkflowRunner.RunWorkflowAsync(workflow); + var workflowInstance = await WorkflowRunner.RunWorkflowAsync(sut); Assert.Equal(WorkflowStatus.Finished, workflowInstance.WorkflowStatus); - Assert.Equal(output, workflowInstance.Output); + } + + [Theory(DisplayName = "Sets the output of the workflow instance to a FinishOutput which contains the expected output after RunWorkflowAsync is used"), AutoMoqData] + public async Task RunWorkflowAsyncShouldReturnExpectedOutput([Frozen] object expectedOutput, + FinishWorkflow sut) + { + var workflowInstance = await WorkflowRunner.RunWorkflowAsync(sut); + var actualOutput = (workflowInstance.Output as FinishOutput)?.Output; + + Assert.Same(expectedOutput, actualOutput); } } } \ No newline at end of file diff --git a/test/unit/Elsa.UnitTests/AutoMoqDataAttribute.cs b/test/shared/Elsa.Testing.Shared/AutoMoqDataAttribute.cs similarity index 100% rename from test/unit/Elsa.UnitTests/AutoMoqDataAttribute.cs rename to test/shared/Elsa.Testing.Shared/AutoMoqDataAttribute.cs