diff --git a/src/core/Akka.Tests/Actor/ActorRefSpec.cs b/src/core/Akka.Tests/Actor/ActorRefSpec.cs index 0cb77f298db..05d012521ad 100644 --- a/src/core/Akka.Tests/Actor/ActorRefSpec.cs +++ b/src/core/Akka.Tests/Actor/ActorRefSpec.cs @@ -12,6 +12,7 @@ using Akka.Serialization; using Akka.TestKit; using Akka.TestKit.TestActors; +using Akka.Util; using Xunit; namespace Akka.Tests.Actor @@ -290,6 +291,16 @@ public void An_ActorRef_should_never_have_a_null_Sender_Bug_1212() ExpectNoMsg(); } + [Fact] + public void An_ActorRef_Mock_should_be_like_Nobody() + { + var mock = new ActorRefMock(); + + mock.Tell("dummy"); + + mock.IsNobody().ShouldBeTrue(); + } + private void VerifyActorTermination(IActorRef actorRef) { var watcher = CreateTestProbe(); @@ -297,6 +308,37 @@ private void VerifyActorTermination(IActorRef actorRef) watcher.ExpectTerminated(actorRef, TimeSpan.FromSeconds(20)); } + private sealed class ActorRefMock : IActorRef + { + public ActorRefMock() { } + + ActorPath IActorRef.Path => null; + + int IComparable.CompareTo(IActorRef other) + { + throw new NotSupportedException(); + } + + int IComparable.CompareTo(object obj) + { + throw new NotSupportedException(); + } + + bool IEquatable.Equals(IActorRef other) + { + throw new NotSupportedException(); + } + + void ICanTell.Tell(object message, IActorRef sender) + { + } + + ISurrogate ISurrogated.ToSurrogate(ActorSystem system) + { + throw new NotSupportedException(); + } + } + private class NestingActor : ActorBase { internal readonly IActorRef Nested; diff --git a/src/core/Akka/Actor/ActorRef.Extensions.cs b/src/core/Akka/Actor/ActorRef.Extensions.cs index e876d9744a4..ef4be2f9988 100644 --- a/src/core/Akka/Actor/ActorRef.Extensions.cs +++ b/src/core/Akka/Actor/ActorRef.Extensions.cs @@ -23,7 +23,8 @@ public static class ActorRefExtensions /// true if the is valid; otherwise false. public static bool IsNobody(this IActorRef actorRef) { - return actorRef == null || actorRef is Nobody || actorRef is DeadLetterActorRef || (actorRef.Path.Uid == 0 && actorRef.Path.Name == "deadLetters"); + return actorRef is null || actorRef is Nobody || actorRef is DeadLetterActorRef + || actorRef.Path is null || (actorRef.Path.Uid == 0 && actorRef.Path.Name == "deadLetters"); } ///