コード例 #1
0
    public void InitializeChoiceNode()
    {
        var choiceNode = A.Dummy <IChoiceNode>();
        var sut        = new BalloonTextNode(textSource, BalloonType.Narration, choiceNode);

        sut.ChoiceNode.Should().BeSameAs(choiceNode);
    }
コード例 #2
0
    public async Task ParseAsync(XmlReader reader, IParsingContext parsingContext, IParentParsingContext parentParsingContext)
    {
        var myContext = new BalloonChildParsingContext();
        await elementParser.ParseAsync(reader, parsingContext, myContext, Settings);

        if (myContext.ParsedText is null)
        {
            return;
        }

        var textSourceParsingResult = textSourceParser.Parse(myContext.ParsedText);

        if (textSourceParsingResult.IsError)
        {
            parsingContext.LogError(reader, textSourceParsingResult.ErrorMessage);
            return;
        }
        var textSource = textSourceParsingResult.TextSource;

        if (reader.ReadState != ReadState.EndOfFile)
        {
            await elementParser.ParseAsync(reader, parsingContext, myContext, AggregationSettings);
        }

        var node = new BalloonTextNode(textSource, BalloonType, myContext.ChoiceNode);

        parentParsingContext.AddNode(node);

        parsingContext.SceneContext.Reset();
    }
コード例 #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
        })
            );
    }
コード例 #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
        })
            );
    }
コード例 #5
0
    public void Initialization(BalloonType balloonType)
    {
        var sut = new BalloonTextNode(textSource, balloonType, null);

        sut.TextSource.Should().Be(textSource);
        sut.BalloonType.Should().Be(balloonType);
        sut.ChoiceNode.Should().BeNull();
    }
コード例 #6
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();
    }
コード例 #7
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
            }
        })
            );
    }
コード例 #8
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" }
                }
            }
        })
            );
    }
コード例 #9
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
        })
            );
    }