-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ActorReference creation from the ActorBase class informations (#…
…1277) * Handled creation of ActorReference from Actor base class Signed-off-by: Manuel Menegazzo <[email protected]> * Updated null check Signed-off-by: Manuel Menegazzo <[email protected]> * Added unit test for GetActorReference from null actore and actor proxy Signed-off-by: Manuel Menegazzo <[email protected]> * Added test for ActorReference created inside Actor implementation Signed-off-by: Manuel Menegazzo <[email protected]> * Updated description Signed-off-by: Manuel Menegazzo <[email protected]> * Fixed test method naming Signed-off-by: Manuel Menegazzo <[email protected]> * Added unit test for exception generated in case the type is not convertible to an ActorReference Signed-off-by: Manuel Menegazzo <[email protected]> --------- Signed-off-by: Manuel Menegazzo <[email protected]>
- Loading branch information
Showing
2 changed files
with
111 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Dapr.Actors.Client; | ||
using Dapr.Actors.Runtime; | ||
using Dapr.Actors.Test; | ||
using Xunit; | ||
|
||
namespace Dapr.Actors | ||
{ | ||
public class ActorReferenceTests | ||
{ | ||
[Fact] | ||
public void Get_WhenActorIsNull_ReturnsNull() | ||
{ | ||
// Arrange | ||
object actor = null; | ||
|
||
// Act | ||
var result = ActorReference.Get(actor); | ||
|
||
// Assert | ||
Assert.Null(result); | ||
} | ||
|
||
[Fact] | ||
public void Get_FromActorProxy_ReturnsActorReference() | ||
{ | ||
// Arrange | ||
var expectedActorId = new ActorId("abc"); | ||
var expectedActorType = "TestActor"; | ||
var proxy = ActorProxy.Create(expectedActorId, typeof(ITestActor), expectedActorType); | ||
|
||
// Act | ||
var actorReference = ActorReference.Get(proxy); | ||
|
||
// Assert | ||
Assert.NotNull(actorReference); | ||
Assert.Equal(expectedActorId, actorReference.ActorId); | ||
Assert.Equal(expectedActorType, actorReference.ActorType); | ||
} | ||
|
||
[Fact] | ||
public async Task Get_FromActorImplementation_ReturnsActorReference() | ||
{ | ||
// Arrange | ||
var expectedActorId = new ActorId("abc"); | ||
var expectedActorType = nameof(ActorReferenceTestActor); | ||
var host = ActorHost.CreateForTest<ActorReferenceTestActor>(new ActorTestOptions() { ActorId = expectedActorId }); | ||
var actor = new ActorReferenceTestActor(host); | ||
|
||
// Act | ||
var actorReference = await actor.GetActorReference(); | ||
|
||
// Assert | ||
Assert.NotNull(actorReference); | ||
Assert.Equal(expectedActorId, actorReference.ActorId); | ||
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 | ||
{ | ||
Task<ActorReference> GetActorReference(); | ||
} | ||
|
||
public class ActorReferenceTestActor : Actor, IActorReferenceTestActor | ||
{ | ||
public ActorReferenceTestActor(ActorHost host) | ||
: base(host) | ||
{ | ||
} | ||
|
||
public Task<ActorReference> GetActorReference() | ||
{ | ||
return Task.FromResult(ActorReference.Get(this)); | ||
} | ||
} | ||
} |