Add test for multiple calls to UseActors (#459)

Fixes: #411

The bug was actually addressed in PR #453 - this change adds a test that
verifies that we actually fixed it.

Co-authored-by: vinayada1 <28875764+vinayada1@users.noreply.github.com>
This commit is contained in:
Ryan Nowak 2020-11-16 13:00:38 -08:00 committed by GitHub
parent 6ce5e319fd
commit 721ea4a1be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 126 additions and 0 deletions

View File

@ -50,6 +50,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapr.Actors.AspNetCore.Test", "test\Dapr.Actors.AspNetCore.Test\Dapr.Actors.AspNetCore.Test.csproj", "{9C1D6ABA-5EDE-4FA0-A8A9-0AB98CB74737}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -116,6 +118,10 @@ Global
{576B28F7-0D86-4C11-828A-B648E11863F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{576B28F7-0D86-4C11-828A-B648E11863F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{576B28F7-0D86-4C11-828A-B648E11863F6}.Release|Any CPU.Build.0 = Release|Any CPU
{9C1D6ABA-5EDE-4FA0-A8A9-0AB98CB74737}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9C1D6ABA-5EDE-4FA0-A8A9-0AB98CB74737}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C1D6ABA-5EDE-4FA0-A8A9-0AB98CB74737}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C1D6ABA-5EDE-4FA0-A8A9-0AB98CB74737}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -139,6 +145,7 @@ Global
{DCBEAB71-0BDE-42F4-8187-F576942CB038} = {B2DB41EE-45F5-447B-95E8-38E1E8B70C4E}
{576B28F7-0D86-4C11-828A-B648E11863F6} = {9ED03812-9DDE-4DFE-9574-DF3671EECA25}
{9ED03812-9DDE-4DFE-9574-DF3671EECA25} = {B2DB41EE-45F5-447B-95E8-38E1E8B70C4E}
{9C1D6ABA-5EDE-4FA0-A8A9-0AB98CB74737} = {DD020B34-460F-455F-8D17-CF4A949F100B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {65220BF2-EAE1-4CB2-AA58-EBE80768CB40}

View File

@ -0,0 +1,6 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// ------------------------------------------------------------
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Dapr.Actors.AspNetCore.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b1f597635c44597fcecb493e2b1327033b29b1a98ac956a1a538664b68f87d45fbaada0438a15a6265e62864947cc067d8da3a7d93c5eb2fcbb850e396c8684dba74ea477d82a1bbb18932c0efb30b64ff1677f85ae833818707ac8b49ad8062ca01d2c89d8ab1843ae73e8ba9649cd28666b539444dcdee3639f95e2a099bb2")]

View File

@ -4,4 +4,5 @@
// ------------------------------------------------------------
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Dapr.Actors.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b1f597635c44597fcecb493e2b1327033b29b1a98ac956a1a538664b68f87d45fbaada0438a15a6265e62864947cc067d8da3a7d93c5eb2fcbb850e396c8684dba74ea477d82a1bbb18932c0efb30b64ff1677f85ae833818707ac8b49ad8062ca01d2c89d8ab1843ae73e8ba9649cd28666b539444dcdee3639f95e2a099bb2")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Dapr.Actors.AspNetCore.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b1f597635c44597fcecb493e2b1327033b29b1a98ac956a1a538664b68f87d45fbaada0438a15a6265e62864947cc067d8da3a7d93c5eb2fcbb850e396c8684dba74ea477d82a1bbb18932c0efb30b64ff1677f85ae833818707ac8b49ad8062ca01d2c89d8ab1843ae73e8ba9649cd28666b539444dcdee3639f95e2a099bb2")]
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Dapr.Actors.AspNetCore, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b1f597635c44597fcecb493e2b1327033b29b1a98ac956a1a538664b68f87d45fbaada0438a15a6265e62864947cc067d8da3a7d93c5eb2fcbb850e396c8684dba74ea477d82a1bbb18932c0efb30b64ff1677f85ae833818707ac8b49ad8062ca01d2c89d8ab1843ae73e8ba9649cd28666b539444dcdee3639f95e2a099bb2")]

View File

@ -0,0 +1,84 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// ------------------------------------------------------------
using System.Linq;
using Dapr.Actors.Runtime;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
namespace Dapr.Actors.AspNetCore
{
public class ActorHostingTest
{
[Fact]
public void CanRegisterActorsInSingleCalls()
{
var builder = new WebHostBuilder();
builder.UseActors(actors =>
{
actors.RegisterActor<TestActor1>();
actors.RegisterActor<TestActor2>();
});
// Configuring the HTTP pipeline is required. It's ok if it's empty.
builder.Configure(_ => {});
var host = builder.Build();
var runtime = host.Services.GetRequiredService<ActorRuntime>();
Assert.Collection(
runtime.RegisteredActorTypes.OrderBy(t => t),
t => Assert.Equal(ActorTypeInformation.Get(typeof(TestActor1)).ActorTypeName, t),
t => Assert.Equal(ActorTypeInformation.Get(typeof(TestActor2)).ActorTypeName, t));
}
[Fact]
public void CanRegisterActorsInMultipleCalls()
{
var builder = new WebHostBuilder();
builder.UseActors(actors =>
{
actors.RegisterActor<TestActor1>();
});
builder.UseActors(actors =>
{
actors.RegisterActor<TestActor2>();
});
// Configuring the HTTP pipeline is required. It's ok if it's empty.
builder.Configure(_ => {});
var host = builder.Build();
var runtime = host.Services.GetRequiredService<ActorRuntime>();
Assert.Collection(
runtime.RegisteredActorTypes.OrderBy(t => t),
t => Assert.Equal(ActorTypeInformation.Get(typeof(TestActor1)).ActorTypeName, t),
t => Assert.Equal(ActorTypeInformation.Get(typeof(TestActor2)).ActorTypeName, t));
}
private interface ITestActor : IActor
{
}
private class TestActor1 : Actor, ITestActor
{
public TestActor1(ActorService actorService, ActorId actorId, IActorStateManager actorStateManager = null)
: base(actorService, actorId, actorStateManager)
{
}
}
private class TestActor2 : Actor, ITestActor
{
public TestActor2(ActorService actorService, ActorId actorId, IActorStateManager actorStateManager = null)
: base(actorService, actorId, actorStateManager)
{
}
}
}
}

View File

@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<BaseNamespace>Dapr.Actors.AspNetCore</BaseNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.9.0">
<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.3.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Dapr.Actors.AspNetCore\Dapr.Actors.AspNetCore.csproj" />
</ItemGroup>
</Project>