Skip to content

Commit a03a213

Browse files
committed
Added unit test for exception generated in case the type is not convertible to an ActorReference
Signed-off-by: Manuel Menegazzo <manuel.menegazzo@outlook.com>
1 parent 6e3ce2c commit a03a213

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/Dapr.Actors/ActorReference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private static ActorReference GetActorReference(object actor)
8888
ActorType = actorBase.Host.ActorTypeInfo.ActorTypeName,
8989
},
9090
// Handle case when we can't cast to IActorProxy or Actor.
91-
_ => throw new ArgumentOutOfRangeException("actor"),
91+
_ => throw new ArgumentOutOfRangeException("actor", "Invalid actor object type."),
9292
};
9393

9494
return actorReference;

test/Dapr.Actors.Test/ActorReferenceTests.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading.Tasks;
1+
using System;
2+
using System.Threading.Tasks;
23
using Dapr.Actors.Client;
34
using Dapr.Actors.Runtime;
45
using Dapr.Actors.Test;
@@ -56,6 +57,20 @@ public async Task Get_FromActorImplementation_ReturnsActorReference()
5657
Assert.Equal(expectedActorType, actorReference.ActorType);
5758
}
5859

60+
[Fact]
61+
public void Get_WithInvalidObjectType_ThrowArgumentOutOfRangeException()
62+
{
63+
// Arrange
64+
var actor = new object();
65+
66+
// Act
67+
var act = () => ActorReference.Get(actor);
68+
69+
// Assert
70+
var exception = Assert.Throws<ArgumentOutOfRangeException>(act);
71+
Assert.Equal("actor", exception.ParamName);
72+
Assert.Equal("Invalid actor object type. (Parameter 'actor')", exception.Message);
73+
}
5974
}
6075

6176
public interface IActorReferenceTestActor : IActor

0 commit comments

Comments
 (0)