Beispiel #1
0
        public async Task ActorContext_must_canonicalize_behaviors()
        {
            var probe = new TestProbe <Event>();

            var behavior = Behaviors.Receive <Command>(async(context, message) =>
            {
                switch (message.Type)
                {
                case Command.CommandType.Ping:
                    probe.Ref.Tell(Event.Pong);
                    return(Behaviors.Same <Command>());

                case Command.CommandType.Miss:
                    probe.Ref.Tell(Event.Missed);
                    return(Behaviors.Unhandled <Command>());

                case Command.CommandType.Renew:
                    var aref = ((Command <Event>)message).Ref;
                    aref.Tell(Event.Renewed);
                    return(Behaviors.Same <Command>());

                default:
                    throw new Exception($"Unexpected message {message}");
                }
            });

            var actor = this.SpawnAnonymous(behavior);

            actor.Tell(Command.Ping);

            await probe.MoveNext();

            probe.Current.Should().Be(Event.Pong);
        }