From 98497a7ff84ac6891815d69f045474c72311f80c Mon Sep 17 00:00:00 2001 From: Manuel Menegazzo Date: Thu, 2 May 2024 16:16:54 +0200 Subject: [PATCH] Added unit test for exception generated in case the type is not convertible to an ActorReference Signed-off-by: Manuel Menegazzo --- src/Dapr.Actors/ActorReference.cs | 2 +- test/Dapr.Actors.Test/ActorReferenceTests.cs | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Dapr.Actors/ActorReference.cs b/src/Dapr.Actors/ActorReference.cs index 14a35feb6..d72b6676f 100644 --- a/src/Dapr.Actors/ActorReference.cs +++ b/src/Dapr.Actors/ActorReference.cs @@ -88,7 +88,7 @@ private static ActorReference GetActorReference(object actor) ActorType = actorBase.Host.ActorTypeInfo.ActorTypeName, }, // Handle case when we can't cast to IActorProxy or Actor. - _ => throw new ArgumentOutOfRangeException("actor"), + _ => throw new ArgumentOutOfRangeException("actor", "Invalid actor object type."), }; return actorReference; diff --git a/test/Dapr.Actors.Test/ActorReferenceTests.cs b/test/Dapr.Actors.Test/ActorReferenceTests.cs index 73e764638..7450f616c 100644 --- a/test/Dapr.Actors.Test/ActorReferenceTests.cs +++ b/test/Dapr.Actors.Test/ActorReferenceTests.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; using Dapr.Actors.Client; using Dapr.Actors.Runtime; using Dapr.Actors.Test; @@ -56,6 +57,20 @@ public async Task Get_FromActorImplementation_ReturnsActorReference() Assert.Equal(expectedActorType, actorReference.ActorType); } + [Fact] + public void Get_WithInvalidObjectType_ThrowArgumentOutOfRangeException() + { + // Arrange + var actor = new object(); + + // Act + var act = () => ActorReference.Get(actor); + + // Assert + var exception = Assert.Throws(act); + Assert.Equal("actor", exception.ParamName); + Assert.Equal("Invalid actor object type. (Parameter 'actor')", exception.Message); + } } public interface IActorReferenceTestActor : IActor