public async Task TestGotoStateTransitionAfterRaise()
        {
            var configuration = GetConfiguration();
            var test          = new ActorTestKit <M3>(configuration: configuration);
            await test.StartActorAsync();

            test.AssertStateTransition("Final");
        }
Ejemplo n.º 2
0
        public async Task TestInvokeInternalAsyncMethod()
        {
            var configuration = GetConfiguration();
            var test          = new ActorTestKit <M2>(configuration: configuration);

            int result = await test.ActorInstance.AddAsync(3, 4);

            test.Assert(result == 7, $"Incorrect result '{result}'");
        }
Ejemplo n.º 3
0
        public void TestInvokeInternalMethod()
        {
            var configuration = GetConfiguration();
            var test          = new ActorTestKit <M1>(configuration: configuration);

            int result = test.ActorInstance.Add(3, 4);

            test.Assert(result == 7, $"Incorrect result '{result}'");
        }
Ejemplo n.º 4
0
        public async Task TestClassEventHandlerWildcardOverride()
        {
            var configuration = GetConfiguration();
            var test          = new ActorTestKit <M3>(configuration: configuration);

            await test.StartActorAsync();

            await test.SendEventAsync(new E1());

            test.Assert(test.ActorInstance.Count == 1, "HandleWildCard was not called");
        }
        public async Task TestGotoStateTransitionAfterSend()
        {
            var configuration = GetConfiguration();
            var test          = new ActorTestKit <M2>(configuration: configuration);
            await test.StartActorAsync();

            test.AssertStateTransition("Init");

            await test.SendEventAsync(new Message());

            test.AssertStateTransition("Final");
        }
Ejemplo n.º 6
0
        public void TestInvokePrivateMethod()
        {
            var configuration = GetConfiguration();
            var test          = new ActorTestKit <M3>(configuration: configuration);

            int result = (int)test.Invoke("Add", 3, 4);

            test.Assert(result == 7, $"Incorrect result '{result}'");

            result = (int)test.Invoke("Add", new Type[] { typeof(int), typeof(int) }, 3, 4);
            test.Assert(result == 7, $"Incorrect result '{result}'");
        }
Ejemplo n.º 7
0
        public async Task TestPushPopTransition()
        {
            var configuration = GetConfiguration();
            var test          = new ActorTestKit <M4>(configuration: configuration);
            await test.StartActorAsync();

            await test.SendEventAsync(new E1());

            await test.SendEventAsync(new E2());

            test.AssertStateTransition("Init");
            test.Assert(test.ActorInstance.Count == 1, "Did not reach Final state");
        }
Ejemplo n.º 8
0
        public async Task TestInvokePrivateAsyncMethod()
        {
            var configuration = GetConfiguration();
            var test          = new ActorTestKit <M4>(configuration: configuration);

            int result = (int)await test.InvokeAsync("AddAsync", 3, 4);

            test.Assert(result == 7, $"Incorrect result '{result}'");

            result = (int)await test.InvokeAsync("AddAsync", new Type[] { typeof(int), typeof(int) }, 3, 4);

            test.Assert(result == 7, $"Incorrect result '{result}'");
        }
Ejemplo n.º 9
0
        public async Task TestReceiveEventStatement()
        {
            var configuration = GetConfiguration();
            var test          = new ActorTestKit <M1>(configuration: configuration);

            await test.StartActorAsync();

            test.AssertIsWaitingToReceiveEvent(true);

            await test.SendEventAsync(new E1());

            test.AssertIsWaitingToReceiveEvent(false);
            test.AssertInboxSize(0);
        }
Ejemplo n.º 10
0
        public async Task TestHandleEventInStateMachine()
        {
            var result = new Result();

            var configuration = GetConfiguration();
            var test          = new ActorTestKit <M1>(configuration: configuration);

            await test.StartActorAsync(new SetupEvent(result));

            await test.SendEventAsync(new E1());

            test.AssertInboxSize(0);
            test.Assert(result.Value == 1, $"Incorrect result '{result.Value}'");
        }
Ejemplo n.º 11
0
        public async Task TestInheritedDuplicateDeferHandler()
        {
            // inherited state can re-define a DeferEvent, IgnoreEvent or a Goto if it wants to, this is not an error.
            var configuration = GetConfiguration();
            var test          = new ActorTestKit <M9>(configuration: configuration);
            await test.StartActorAsync();

            await test.SendEventAsync(new E1()); // should be deferred

            await test.SendEventAsync(new E2()); // should be ignored

            await test.SendEventAsync(new E3()); // should trigger goto, where deferred E1 can be handled.

            test.AssertStateTransition("Final");
        }
Ejemplo n.º 12
0
        public void TestInheritedDuplicateHandler()
        {
            string actual = null;

            try
            {
                var test = new ActorTestKit <M8>(GetConfiguration());
            }
            catch (Exception e)
            {
                string fullname = typeof(PushPopStateTests).FullName;
                actual = e.Message.Replace(fullname + "+", string.Empty);
            }

            Assert.Equal("M8(0) inherited multiple handlers for event 'E1' from state 'BaseState' in state 'M8+Init'.", actual);
        }
Ejemplo n.º 13
0
        public void TestDuplicateHandler2()
        {
            string actual = null;

            try
            {
                var test = new ActorTestKit <M7>(GetConfiguration());
            }
            catch (Exception e)
            {
                string fullname = typeof(PushPopStateTests).FullName;
                actual = e.Message.Replace(fullname + "+", string.Empty);
            }

            Assert.Equal("M7(0) declared multiple handlers for event 'E2' in state 'M7+Init'.", actual);
        }
Ejemplo n.º 14
0
        public async Task TestPushStateInheritance()
        {
            var configuration = GetConfiguration();
            var test          = new ActorTestKit <M5>(configuration: configuration);
            await test.StartActorAsync();

            await test.SendEventAsync(new E2()); // should be deferred

            await test.SendEventAsync(new E1()); // push

            await test.SendEventAsync(new E3()); // ignored

            await test.SendEventAsync(new E4()); // inherited handler

            test.AssertStateTransition("Final");
            string actual   = string.Join(", ", test.ActorInstance.Log);
            string expected = "E2 in state Final, E4 in state Final";

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 15
0
        public async Task TestMultipleReceiveEventStatementsUnordered()
        {
            var configuration = GetConfiguration();
            var test          = new ActorTestKit <M2>(configuration: configuration);

            await test.StartActorAsync();

            test.AssertIsWaitingToReceiveEvent(true);

            await test.SendEventAsync(new E2());

            test.AssertIsWaitingToReceiveEvent(true);
            test.AssertInboxSize(1);

            await test.SendEventAsync(new E3());

            test.AssertIsWaitingToReceiveEvent(true);
            test.AssertInboxSize(2);

            await test.SendEventAsync(new E1());

            test.AssertIsWaitingToReceiveEvent(false);
            test.AssertInboxSize(0);
        }