Beispiel #1
0
        public void should_pass_both_passed_and_relayed_arguments_with_variance_conversion(RaiseWay raiseWay)
        {
            var          expectedRelayedValue = new MemoryStream();
            const string expectedPassedValue  = "stringValue";

            ITuple <object, IDisposable> actual = null;

            // --arrange
            var builder = new Builder <string, int>(OnException);

            builder.DefineState(Initial).AddTransition(Event1, State1);

            builder.DefineState(State1)
            .OnEnter <Stream>(_ => { })
            .AddTransition(Event2, State2);

            builder.DefineState(State2)
            .OnEnter <ITuple <object, IDisposable> >(value => actual = value);

            var target = builder.Build(Initial);

            target.Raise(raiseWay, Event1, expectedRelayedValue); // attach an argument to State1

            // --act
            target.Relaying <Stream>().Raise(raiseWay, Event2, expectedPassedValue); // pass and relay arguments to State2

            // --assert
            actual.Should().NotBeNull();
            actual !.PassedArgument.Should().Be(expectedPassedValue);
            actual.RelayedArgument.Should().Be(expectedRelayedValue);
        }
Beispiel #2
0
        public void should_pass_relayed_passed_and_tuple_arguments_depending_on_enter_type(RaiseWay raiseWay)
        {
            var          expectedRelayed = new MemoryStream();
            const string expectedPassed  = "stringValue";

            IDisposable actualRelayed = null;
            object      actualPassed  = null;
            ITuple <object, IDisposable> actualTuple = null;

            // --arrange
            var builder = new Builder <string, int>(OnException);

            builder.DefineState(Initial).AddTransition(Event1, State1);

            builder.DefineState(State1)
            .OnEnter <MemoryStream>(_ => { })
            .AddTransition(Event2, Child);

            builder.DefineState(Root)
            .OnEnter <object>(value => actualPassed = value);

            builder.DefineState(Parent)
            .AsSubstateOf(Root)
            .OnEnter <ITuple <object, IDisposable> >(value => actualTuple = value);

            builder.DefineState(Child)
            .AsSubstateOf(Parent)
            .OnEnter <IDisposable>(value => actualRelayed = value);

            var target = builder.Build(Initial, true);

            target.Raise(raiseWay, Event1, expectedRelayed); // attach MemoryStream to State1

            // --act
            target.Relaying <MemoryStream>().Raise(raiseWay, Event2, expectedPassed); // pass string and relay MemoryStream to Child

            // --assert
            actualPassed.Should().Be(expectedPassed);
            actualRelayed.Should().Be(expectedRelayed);
            actualTuple !.PassedArgument.Should().Be(expectedPassed);
            actualTuple.RelayedArgument.Should().Be(expectedRelayed);
        }