Skip to content

Commit

Permalink
Added unit test for exception generated in case the type is not conve…
Browse files Browse the repository at this point in the history
…rtible to an ActorReference

Signed-off-by: Manuel Menegazzo <manuel.menegazzo@outlook.com>
  • Loading branch information
m3nax committed May 2, 2024
1 parent 9d98c75 commit 98497a7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Dapr.Actors/ActorReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 16 additions & 1 deletion test/Dapr.Actors.Test/ActorReferenceTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<ArgumentOutOfRangeException>(act);
Assert.Equal("actor", exception.ParamName);
Assert.Equal("Invalid actor object type. (Parameter 'actor')", exception.Message);
}
}

public interface IActorReferenceTestActor : IActor
Expand Down

0 comments on commit 98497a7

Please sign in to comment.