Skip to content

Commit

Permalink
Address more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
svegiraju-microsoft committed Sep 24, 2024
1 parent 18ac355 commit 004c240
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/Dapr.Actors/Runtime/ActorRegistrationCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void RegisterActor<TActor>(string actorTypeName, Action<ActorRegistration
/// <param name="configure">An optional delegate used to configure the actor registration.</param>
public void RegisterActor<TActorInterface, TActor>(Action<ActorRegistration> configure = null)
where TActorInterface : IActor
where TActor : Actor
where TActor : Actor, TActorInterface
{
RegisterActor<TActorInterface, TActor>(actorTypeName: null, configure);
}
Expand All @@ -89,7 +89,7 @@ public void RegisterActor<TActorInterface, TActor>(Action<ActorRegistration> con
/// <param name="configure">An optional delegate used to configure the actor registration.</param>
public void RegisterActor<TActorInterface, TActor>(ActorRuntimeOptions typeOptions, Action<ActorRegistration> configure = null)
where TActorInterface : IActor
where TActor : Actor
where TActor : Actor, TActorInterface
{
RegisterActor(typeof(TActorInterface), typeof(TActor), null, typeOptions, configure);
}
Expand All @@ -104,7 +104,7 @@ public void RegisterActor<TActorInterface, TActor>(ActorRuntimeOptions typeOptio
/// <remarks>The value of <paramref name="actorTypeName"/> will have precedence over the default actor type name derived from the actor implementation type or any type name set via <see cref="ActorAttribute"/>.</remarks>
public void RegisterActor<TActorInterface, TActor>(string actorTypeName, Action<ActorRegistration> configure = null)
where TActorInterface : IActor
where TActor : Actor
where TActor : Actor, TActorInterface
{
RegisterActor(typeof(TActorInterface), typeof(TActor), actorTypeName, null, configure);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Dapr.Actors/Runtime/ActorTypeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// 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.
Expand Down
32 changes: 29 additions & 3 deletions test/Dapr.Actors.AspNetCore.Test/ActorHostingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// limitations under the License.
// ------------------------------------------------------------------------

using System;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
Expand Down Expand Up @@ -104,8 +105,33 @@ public void CanRegisterActorsToSpecificInterface()

Assert.Collection(
runtime.RegisteredActors.Select(r => r.Type.ActorTypeName).OrderBy(t => t),
t => Assert.Equal(ActorTypeInformation.Get(typeof(TestActor1), actorTypeName: null).ActorTypeName, t),
t => Assert.Equal(ActorTypeInformation.Get(typeof(TestActor2), actorTypeName: null).ActorTypeName, t));
t => Assert.Equal(ActorTypeInformation.Get(typeof(IMyActor), typeof(InternalMyActor), actorTypeName: null).ActorTypeName, t));

Assert.Collection(
runtime.RegisteredActors.Select(r => r.Type.InterfaceTypes.First()).OrderBy(t => t),
t => Assert.Equal(ActorTypeInformation.Get(typeof(IMyActor), typeof(InternalMyActor), actorTypeName: null).InterfaceTypes.First(), t));

Assert.True(runtime.RegisteredActors.First().Type.InterfaceTypes.Count() == 1);
}

[Fact]
public void RegisterActorThrowsArgumentExceptionWhenAnyInterfaceInTheChainIsNotIActor()
{
var services = new ServiceCollection();
services.AddLogging();
services.AddOptions();
services.AddActors(options =>
{
Assert.Throws<ArgumentException>(() => options.Actors.RegisterActor<INonActor1, InternalMyActor>());
});
}

private interface INonActor
{
}

private interface INonActor1 : INonActor, IActor
{
}

private interface ITestActor : IActor
Expand Down Expand Up @@ -138,7 +164,7 @@ public interface IInternalMyActor : IMyActor
void SomeInternalMethod();
}

public class InternalMyActor : Actor, IInternalMyActor
public class InternalMyActor : Actor, IInternalMyActor, INonActor1
{
public InternalMyActor(ActorHost host)
: base(host)
Expand Down

0 comments on commit 004c240

Please sign in to comment.