Example #1
0
    public async Task EnterAsyncShouldRaiseEvent()
    {
        var invoker = new TestInvoker(context);
        await sut.EnterAsync(context);

        invoker.ShouldContainSingle <IBackgroundChangeEvent>(i => i.State.Should().BeSameAs(newState));
    }
Example #2
0
    public async Task OnEnterAsyncShouldRaiseEvent(MoodType moodType, string personName, string protagonist)
    {
        var isProtagonist = personName == protagonist;

        var context = A.Dummy <INavigationContext>();

        context.State.PersonName      = personName;
        context.State.ProtagonistName = protagonist;
        context.State.MoodType        = null;

        var invoker = new TestInvoker(context);

        var sut = new MoodNode(moodType);

        var ret = await sut.EnterAsync(context);

        ret.Should().BeNull();

        invoker.ShouldContainSingle <IMoodChangeEvent>(
            i => i.Should().BeEquivalentTo(new
        {
            MoodType      = moodType,
            PersonName    = personName,
            IsProtagonist = isProtagonist
        })
            );
    }
Example #3
0
    public async Task ChoiceMustBeNullWhenAllOptionsAreInvisible()
    {
        var when = A.Fake <ICondition>(i => i.Strict());

        A.CallTo(() => when.Evaluate(variables)).Returns(false);

        var choiceNode = new TestChoiceNode
        {
            Options = new()
            {
                new TestChoiceOptionNode {
                    Key = "a", Text = "Opção1", VisibleWhen = when
                },
                new TestChoiceOptionNode {
                    Key = "b", Text = "Opção2", VisibleWhen = when
                }
            }
        };

        var sut     = new BalloonTextNode(textSource, BalloonType.Speech, choiceNode);
        var invoker = new TestInvoker(context);

        await sut.EnterAsync(context);

        invoker.ShouldContainSingle <IBalloonTextEvent>(
            i => i.Should().BeEquivalentTo(new
        {
            Text          = balloonText,
            BalloonType   = BalloonType.Speech,
            IsProtagonist = true,
            Choice        = (IChoice)null
        })
            );
    }
Example #4
0
    public async Task ChoiceMustBeNullWhenThereAreNoOptions()
    {
        var when = A.Fake <ICondition>(i => i.Strict());

        A.CallTo(() => when.Evaluate(variables)).Returns(false);

        var choiceNode = new TestChoiceNode {
            Options = new()
        };

        var sut     = new BalloonTextNode(textSource, BalloonType.Tutorial, choiceNode);
        var invoker = new TestInvoker(context);

        await sut.EnterAsync(context);

        invoker.ShouldContainSingle <IBalloonTextEvent>(
            i => i.Should().BeEquivalentTo(new
        {
            Text          = balloonText,
            BalloonType   = BalloonType.Tutorial,
            IsProtagonist = true,
            Choice        = (IChoice)null
        })
            );
    }
Example #5
0
    public async Task OnEnterAsyncShouldEvaluateOptionEnabledCondition()
    {
        var when1 = A.Fake <ICondition>(i => i.Strict());

        A.CallTo(() => when1.Evaluate(variables)).Returns(true);
        var when2 = A.Fake <ICondition>(i => i.Strict());

        A.CallTo(() => when2.Evaluate(variables)).Returns(false);
        var when3 = A.Fake <ICondition>(i => i.Strict());

        A.CallTo(() => when3.Evaluate(variables)).Returns(false);

        var choiceNode = new TestChoiceNode
        {
            Options = new()
            {
                new TestChoiceOptionNode {
                    Key = "a", Text = "Opção1", DisabledText = "Inativa", EnabledWhen = when1
                },
                new TestChoiceOptionNode {
                    Key = "b", Text = "Opção2", DisabledText = "Não ativa", EnabledWhen = when2
                },
                new TestChoiceOptionNode {
                    Key = "c", Text = "Opção3", EnabledWhen = when3
                }
            }
        };

        var sut     = new BalloonTextNode(textSource, BalloonType.Speech, choiceNode);
        var invoker = new TestInvoker(context);

        await sut.EnterAsync(context);

        invoker.ShouldContainSingle <IBalloonTextEvent>(
            i => i.Should().BeEquivalentTo(new
        {
            Text          = balloonText,
            BalloonType   = BalloonType.Speech,
            IsProtagonist = true,
            Choice        = new
            {
                TimeLimit = (TimeSpan?)null,
                Default   = (string)null,
                Options   = new[]
                {
                    new { Key = "a", Text = "Opção1", IsEnabled = true, ImageName = (string)null, HelpText = (string)null },
                    new { Key = "b", Text = "Não ativa", IsEnabled = false, ImageName = (string)null, HelpText = (string)null },
                    new { Key = "c", Text = "Opção3", IsEnabled = false, ImageName = (string)null, HelpText = (string)null }
                }
            }
        })
            );

        A.CallTo(() => when1.Evaluate(variables)).MustHaveHappenedOnceExactly();
        A.CallTo(() => when2.Evaluate(variables)).MustHaveHappenedOnceExactly();
        A.CallTo(() => when3.Evaluate(variables)).MustHaveHappenedOnceExactly();
    }
Example #6
0
    public async Task ShouldRaiseEventWithStateArg(string stateArg)
    {
        var context = A.Dummy <INavigationContext>();

        context.State.MusicName = "theme";

        var invoker = new TestInvoker(context);

        var sut = new MusicNode("goodbye", null);
        await sut.EnterAsync(context, stateArg);

        invoker.ShouldContainSingle <IMusicChangeEvent>(
            i => i.Should().BeEquivalentTo(new { MusicName = stateArg })
            );
    }
Example #7
0
    public async Task OnEnterShouldRaiseEvent(string currentValue, string newValue)
    {
        var context = A.Dummy <INavigationContext>();

        context.State.ProtagonistName = currentValue;

        var invoker = new TestInvoker(context);

        var sut = new ProtagonistNode(newValue, null);
        await sut.EnterAsync(context);

        invoker.ShouldContainSingle <IProtagonistChangeEvent>(
            i => i.Should().BeEquivalentTo(new { PersonName = newValue })
            );
    }
Example #8
0
    public async Task RandomOrder()
    {
        var choiceNode = new TestChoiceNode
        {
            RandomOrder = true,
            Options     = new()
            {
                new TestChoiceOptionNode {
                    Key = "a", Text = "Opção1"
                },
                new TestChoiceOptionNode {
                    Key = "b", Text = "Opção2"
                }
            }
        };

        var shuffled = new List <IChoiceOption>
        {
            A.Fake <IChoiceOption>(i => i.ConfigureFake(i => {
                A.CallTo(() => i.IsEnabled).Returns(true);
            }))
        };

        var randomizer = A.Fake <IRandomizer>(i => i.Strict());

        A.CallTo(() => randomizer.Shuffle(A <List <IChoiceOption> > .Ignored)).Returns(shuffled);
        A.CallTo(() => context.Randomizer).Returns(randomizer);

        var sut     = new BalloonTextNode(textSource, BalloonType.Speech, choiceNode);
        var invoker = new TestInvoker(context);

        await sut.EnterAsync(context);

        invoker.ShouldContainSingle <IBalloonTextEvent>(
            i => i.Should().BeEquivalentTo(new
        {
            Text          = balloonText,
            BalloonType   = BalloonType.Speech,
            IsProtagonist = true,
            Choice        = new
            {
                TimeLimit = (TimeSpan?)null,
                Default   = (string)null,
                Options   = shuffled
            }
        })
            );
    }
Example #9
0
    public async Task EnterAsync()
    {
        var context = A.Dummy <INavigationContext>();
        var invoker = new TestInvoker(context);

        var duration = TimeSpan.FromMilliseconds(234567);

        var sut = new TimedPauseNode(duration, null);
        var ret = await sut.EnterAsync(context);

        ret.Should().BeNull();

        invoker.ShouldContainSingle <ITimedPauseEvent>(
            i => i.Should().BeEquivalentTo(new { Duration = duration })
            );
    }
Example #10
0
    public async Task ShouldRaiseEventWithStateArg(string stageArg)
    {
        var context = A.Dummy <INavigationContext>();

        context.State.ProtagonistName = "alpha";

        var invoker = new TestInvoker(context);

        var sut = new ProtagonistNode("beta", null);
        await sut.EnterAsync(context, stageArg);

        invoker.ShouldContainSingle <IProtagonistChangeEvent>(
            i => i.Should().BeEquivalentTo(new { PersonName = stageArg })
            );

        context.State.ProtagonistName.Should().Be(stageArg);
    }
Example #11
0
    public async Task OnEnterAsyncWithChoice()
    {
        state.PersonName      = "mu";
        state.ProtagonistName = "pi";

        var choiceNode = new TestChoiceNode
        {
            TimeLimit = TimeSpan.FromSeconds(3),
            Default   = "a",
            Options   = new()
            {
                new TestChoiceOptionNode {
                    Key = "a", Text = "Opção1"
                },
                new TestChoiceOptionNode {
                    Key = "b", Text = "Opção2", ImageName = "abc", HelpText = "help"
                }
            }
        };

        var sut     = new BalloonTextNode(textSource, BalloonType.Speech, choiceNode);
        var invoker = new TestInvoker(context);

        await sut.EnterAsync(context);

        invoker.ShouldContainSingle <IBalloonTextEvent>(
            i => i.Should().BeEquivalentTo(new
        {
            Text          = balloonText,
            BalloonType   = BalloonType.Speech,
            IsProtagonist = false,
            Choice        = new
            {
                TimeLimit = TimeSpan.FromSeconds(3),
                Default   = "a",
                Options   = new[]
                {
                    new { Key = "a", Text = "Opção1", IsEnabled = true, ImageName = (string)null, HelpText = (string)null },
                    new { Key = "b", Text = "Opção2", IsEnabled = true, ImageName = "abc", HelpText = "help" }
                }
            }
        })
            );
    }
Example #12
0
    public async Task OnLeaveAsyncShouldRaiseEvent(string personName, string protagonist)
    {
        var isProtagonist = personName == protagonist;

        var context = A.Dummy <INavigationContext>();

        context.State.ProtagonistName = protagonist;

        var invoker = new TestInvoker(context);

        var childBlock = A.Dummy <IBlock>();
        var sut        = new PersonNode(personName, childBlock);

        await sut.LeaveAsync(context);

        invoker.ShouldContainSingle <IPersonLeaveEvent>(
            i => i.Should().BeEquivalentTo(new { PersonName = personName, IsProtagonist = isProtagonist })
            );
    }
Example #13
0
    public async Task OnEnterAsyncShouldRaiseEvent(BalloonType balloonType, bool isProtagonist)
    {
        state.PersonName      = "alpha";
        state.ProtagonistName = isProtagonist ? "alpha" : "beta";

        var sut     = new BalloonTextNode(textSource, balloonType, null);
        var invoker = new TestInvoker(context);

        var ret = await sut.EnterAsync(context);

        ret.Should().BeNull();

        invoker.ShouldContainSingle <IBalloonTextEvent>(
            i => i.Should().BeEquivalentTo(new
        {
            Text          = balloonText,
            BalloonType   = balloonType,
            IsProtagonist = isProtagonist,
            Choice        = (IChoice)null
        })
            );
    }
Example #14
0
    public async Task OnEnterShouldReturnPreviousMood()
    {
        var context = A.Dummy <INavigationContext>();

        context.State.MoodType   = MoodType.Surprised;
        context.State.PersonName = "abc";

        var invoker = new TestInvoker(context);

        var sut = new MoodNode(MoodType.Happy);
        var ret = await sut.EnterAsync(context);

        ret.Should().Be(MoodType.Surprised);

        invoker.ShouldContainSingle <IMoodChangeEvent>(
            i => i.Should().BeEquivalentTo(new
        {
            MoodType      = MoodType.Happy,
            PersonName    = "abc",
            IsProtagonist = false
        })
            );
    }
Example #15
0
    public async Task ShouldRaiseEventWithStateArg(MoodType moodType)
    {
        var context = A.Dummy <INavigationContext>();

        context.State.PersonName      = "alpha";
        context.State.ProtagonistName = "alpha";
        context.State.MoodType        = MoodType.Happy;

        var invoker = new TestInvoker(context);

        var sut = new MoodNode(MoodType.Happy);

        await sut.EnterAsync(context, moodType);

        invoker.ShouldContainSingle <IMoodChangeEvent>(
            i => i.Should().BeEquivalentTo(new
        {
            MoodType      = moodType,
            PersonName    = "alpha",
            IsProtagonist = true
        })
            );
    }
Example #16
0
    public async Task EnterAsync(BackgroundPosition oldPosition, BackgroundPosition newPosition)
    {
        var oldState = new BackgroundState("alpha", BackgroundType.Image, oldPosition);
        var newState = new BackgroundState("alpha", BackgroundType.Image, newPosition);

        var when = A.Dummy <ICondition>();

        var context = A.Dummy <INavigationContext>();

        context.State.Background = oldState;
        var invoker = new TestInvoker(context);

        var sut = new ScrollNode(when);
        var ret = await sut.EnterAsync(context);

        ret.Should().BeNull();

        invoker.ShouldContainSingle <IBackgroundScrollEvent>(
            i => i.Should().BeEquivalentTo(new { Position = newPosition })
            );

        context.State.Background.Should().Be(newState);
    }