From 004c240719e55084ed60238da82683fc55887fc4 Mon Sep 17 00:00:00 2001 From: Siri Varma Vegiraju Date: Mon, 23 Sep 2024 19:20:36 -0700 Subject: [PATCH] Address more changes --- .../Runtime/ActorRegistrationCollection.cs | 6 ++-- .../Runtime/ActorTypeExtensions.cs | 2 +- .../ActorHostingTest.cs | 32 +++++++++++++++++-- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/Dapr.Actors/Runtime/ActorRegistrationCollection.cs b/src/Dapr.Actors/Runtime/ActorRegistrationCollection.cs index 69187d6ff..bff587a53 100644 --- a/src/Dapr.Actors/Runtime/ActorRegistrationCollection.cs +++ b/src/Dapr.Actors/Runtime/ActorRegistrationCollection.cs @@ -75,7 +75,7 @@ public void RegisterActor(string actorTypeName, ActionAn optional delegate used to configure the actor registration. public void RegisterActor(Action configure = null) where TActorInterface : IActor - where TActor : Actor + where TActor : Actor, TActorInterface { RegisterActor(actorTypeName: null, configure); } @@ -89,7 +89,7 @@ public void RegisterActor(Action con /// An optional delegate used to configure the actor registration. public void RegisterActor(ActorRuntimeOptions typeOptions, Action configure = null) where TActorInterface : IActor - where TActor : Actor + where TActor : Actor, TActorInterface { RegisterActor(typeof(TActorInterface), typeof(TActor), null, typeOptions, configure); } @@ -104,7 +104,7 @@ public void RegisterActor(ActorRuntimeOptions typeOptio /// The value of will have precedence over the default actor type name derived from the actor implementation type or any type name set via . public void RegisterActor(string actorTypeName, Action configure = null) where TActorInterface : IActor - where TActor : Actor + where TActor : Actor, TActorInterface { RegisterActor(typeof(TActorInterface), typeof(TActor), actorTypeName, null, configure); } diff --git a/src/Dapr.Actors/Runtime/ActorTypeExtensions.cs b/src/Dapr.Actors/Runtime/ActorTypeExtensions.cs index 4acaa3912..ddb2e79ed 100644 --- a/src/Dapr.Actors/Runtime/ActorTypeExtensions.cs +++ b/src/Dapr.Actors/Runtime/ActorTypeExtensions.cs @@ -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. diff --git a/test/Dapr.Actors.AspNetCore.Test/ActorHostingTest.cs b/test/Dapr.Actors.AspNetCore.Test/ActorHostingTest.cs index ee530d5a5..1c2e891f8 100644 --- a/test/Dapr.Actors.AspNetCore.Test/ActorHostingTest.cs +++ b/test/Dapr.Actors.AspNetCore.Test/ActorHostingTest.cs @@ -11,6 +11,7 @@ // limitations under the License. // ------------------------------------------------------------------------ +using System; using System.Linq; using System.Text.Json; using System.Threading.Tasks; @@ -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(() => options.Actors.RegisterActor()); + }); + } + + private interface INonActor + { + } + + private interface INonActor1 : INonActor, IActor + { } private interface ITestActor : IActor @@ -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)