Example #1
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 #2
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 #3
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 #4
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 #5
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 #6
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
        })
            );
    }