-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Siri Varma Vegiraju <[email protected]>
- Loading branch information
1 parent
c47e650
commit 1a376cf
Showing
6 changed files
with
125 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// ------------------------------------------------------------------------ | ||
// Copyright 2022 The Dapr Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ------------------------------------------------------------------------ | ||
|
||
namespace Dapr.Workflow | ||
{ | ||
using System; | ||
using Microsoft.DurableTask; | ||
|
||
/// <summary> | ||
/// Defines properties and methods for task activity context objects. | ||
/// </summary> | ||
public class DaprWorkflowActivityContext : WorkflowActivityContext | ||
{ | ||
readonly TaskActivityContext innerContext; | ||
|
||
internal DaprWorkflowActivityContext(TaskActivityContext innerContext) | ||
{ | ||
this.innerContext = innerContext ?? throw new ArgumentNullException(nameof(innerContext)); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override TaskName Name => this.innerContext.Name; | ||
|
||
/// <inheritdoc/> | ||
public override string InstanceId => this.innerContext.InstanceId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<RootNamespace>Dapr.Workflow.Tests</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.msbuild" Version="6.0.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="FluentAssertions" Version="5.9.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" /> | ||
<PackageReference Include="Moq" Version="4.20.70" /> | ||
<PackageReference Include="xunit" Version="2.8.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Dapr.Workflow\Dapr.Workflow.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// ------------------------------------------------------------------------ | ||
// Copyright 2021 The Dapr Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ------------------------------------------------------------------------ | ||
|
||
namespace Dapr.Workflow.Test | ||
{ | ||
using Moq; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
/// <summary> | ||
/// Contains tests for WorkflowActivityContext. | ||
/// </summary> | ||
public class WorkflowActivityTest | ||
{ | ||
private IWorkflowActivity workflowActivity; | ||
|
||
private Mock<WorkflowActivityContext> workflowActivityContextMock; | ||
|
||
[Fact] | ||
public async Task RunAsync_ShouldReturnCorrectContextInstanceId() | ||
{ | ||
this.workflowActivity = new TestDaprWorkflowActivity(); | ||
this.workflowActivityContextMock = new Mock<WorkflowActivityContext>(); | ||
|
||
this.workflowActivityContextMock.Setup((x) => x.InstanceId).Returns("instanceId"); | ||
|
||
string result = (string) await this.workflowActivity.RunAsync(this.workflowActivityContextMock.Object, "input"); | ||
|
||
Assert.Equal("instanceId", result); | ||
} | ||
|
||
|
||
public class TestDaprWorkflowActivity : WorkflowActivity<string, string> | ||
{ | ||
public override Task<string> RunAsync(WorkflowActivityContext context, string input) | ||
{ | ||
return Task.FromResult(context.InstanceId); | ||
} | ||
} | ||
} | ||
} |