Exemplo n.º 1
0
            public void When_receiving_behavior_messages_directly()
            {
                Behavior behavior = new BehaviorTester(events)
                                    .State("Initial");

                behavior.Initial("Initial");

                Assert.ThrowsAsync <InvalidOperationException>(() => behavior.Receive(Become.Message));
                Assert.ThrowsAsync <InvalidOperationException>(() => behavior.Receive(Unbecome.Message));

                Assert.That(behavior.Current.Name, Is.EqualTo("Initial"));
                Assert.That(events, Has.Count.EqualTo(0));
            }
Exemplo n.º 2
0
            public async Task When_receiving_message()
            {
                Task <object> Receive(object x) => x is string
                ?Task.FromResult <object>("foo")
                    : Task.FromResult <object>("bar");

                Behavior behavior = new BehaviorTester(events)
                                    .State("A", Receive);

                behavior.Initial("A");

                Assert.That(await behavior.Receive("1"), Is.EqualTo("foo"));
                Assert.That(await behavior.Receive(1), Is.EqualTo("bar"));
            }
            public async Task When_composed_via_state()
            {
                Task <object> Base(object message)
                {
                    events.Add("base");
                    return(TaskResult.Unhandled);
                }

                Task <object> XTrait(object message)
                {
                    events.Add("x");
                    return(TaskResult.Unhandled);
                }

                Task <object> YTrait(object message)
                {
                    events.Add("y");
                    return(TaskResult.From("y"));
                }

                Receive[] Cast(params Receive[] args) => args;

                Behavior behavior = new BehaviorTester(events)
                                    .State(Base, trait: Cast(XTrait, YTrait))
                                    .Initial(Base);

                var result = await behavior.Receive("foo");

                AssertEqual(new[] { "base", "x", "y" }, events);
                Assert.AreEqual("y", result);
            }
Exemplo n.º 4
0
            public async Task When_receiving_deactivate_message_initial()
            {
                Behavior behavior = new BehaviorTester(events)
                                    .State("Initial");

                behavior.Initial("Initial");

                var result = await behavior.Receive(Deactivate.Message);

                Assert.That(result, Is.SameAs(Done.Result));

                Assert.That(behavior.Current.Name, Is.EqualTo("Initial"));
                AssertEvents("OnDeactivate_Initial");
            }
Exemplo n.º 5
0
            public void When_returns_null_task()
            {
                Behavior behavior = new BehaviorTester(events)
                                    .State("A", x => null)
                                    .Initial("A");

                var exception = Assert.ThrowsAsync <InvalidOperationException>(async() => await behavior.Receive("foo"));

                Assert.That(exception.Message, Is.EqualTo("Behavior returns null task on handling 'foo' message"));
            }