示例#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);
        }
示例#2
0
 public void ActorContext_must_be_usable_from_behavior_interpret_message()
 {
     var b = Behaviors.Receive <string>(async(context, message) =>
     {
         //TODO: Behavior.interpretMessage(b, context, message)
         return(Behaviors.Same <string>());
     });
 }
示例#3
0
        public AskSpec(ITestOutputHelper output) : base(output)
        {
            this.behavior = Behaviors.Receive <Msg>(async(ctx, msg) =>
            {
                switch (msg.Type)
                {
                case MessageType.Foo:
                    msg.ReplyTo.Tell("foo");
                    return(Behaviors.Same <Msg>());

                case MessageType.Stop:
                    msg.ReplyTo.Tell("stopped");
                    return(Behaviors.Stopped <Msg>());

                default: throw new NotImplementedException();
                }
                ;
            });
        }