Exemple #1
0
    public async Task Aggregation()
    {
        var parentContext = new FakeParentParsingContext();
        var context       = Helper.FakeParsingContext();
        var reader        = A.Dummy <XmlReader>();

        A.CallTo(() => reader.ReadState).Returns(ReadState.Interactive);

        var dummyNode1 = A.Dummy <IPauseNode>();

        A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.Settings))
        .Invokes(i => i.Arguments.Get <IParentParsingContext>(2).AddNode(dummyNode1));

        var dummyNode2 = A.Dummy <IPauseNode>();

        A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.AggregationSettings))
        .Invokes(i => i.Arguments.Get <IParentParsingContext>(2).AddNode(dummyNode2));

        await sut.ParseAsync(reader, context, parentContext);

        parentContext.ShouldContainSingle <BalloonNode>(i =>
        {
            i.BallonType.Should().Be(BalloonType.Speech);
            i.ChildBlock.ShouldBeEquivalentTo(dummyNode1, dummyNode2);
        });

        A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.Settings)).MustHaveHappenedOnceExactly();
        A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.AggregationSettings)).MustHaveHappenedOnceExactly();
    }
Exemple #2
0
    public async Task ParseAsyncShouldReturnAPersonNode()
    {
        var reader        = A.Dummy <XmlReader>();
        var context       = Helper.FakeParsingContext();
        var parentContext = new FakeParentParsingContext();

        var sceneContext = A.Dummy <IParsingSceneContext>();

        A.CallTo(() => context.SceneContext).Returns(sceneContext);

        A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.Settings))
        .Invokes(i => i.Arguments.Get <IParentParsingContext>(2).ParsedText = "lorenipsum");

        var dummyNode = A.Dummy <INode>();

        A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.AggregationSettings))
        .Invokes(i => i.Arguments.Get <IParentParsingContext>(2).AddNode(dummyNode));

        await sut.ParseAsync(reader, context, parentContext);

        parentContext.ShouldContainSingle <PersonNode>(i =>
        {
            i.PersonName.Should().Be("lorenipsum");
            i.ChildBlock.ShouldBeEquivalentTo(sut.InitializeMoodNode, dummyNode, sut.DismissMoodNode);
        }
                                                       );

        A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.Settings))
        .MustHaveHappenedOnceExactly();
        A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.AggregationSettings))
        .MustHaveHappenedOnceExactly();
    }
Exemple #3
0
    public async Task ParseAsyncShouldReturnProtagonistNode(string parsedValue, string protagonistName)
    {
        var reader        = A.Dummy <XmlReader>();
        var context       = A.Dummy <IParsingContext>();
        var parentContext = new FakeParentParsingContext();

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

        A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.Settings))
        .Invokes(i =>
        {
            var ctx        = i.GetArgument <IParentParsingContext>(2);
            ctx.ParsedText = parsedValue;
            ctx.When       = when;
        });

        await sut.ParseAsync(reader, context, parentContext);

        parentContext.ShouldContainSingle <ProtagonistNode>(i =>
        {
            i.ProtagonistName.Should().Be(protagonistName);
            i.When.Should().BeSameAs(when);
        });

        A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.Settings)).MustHaveHappenedOnceExactly();
    }
Exemple #4
0
    public async Task ParseAsyncShouldReturnMoodNode()
    {
        var reader        = A.Dummy <XmlReader>();
        var context       = A.Dummy <IParsingContext>();
        var parentContext = new FakeParentParsingContext();

        A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.Settings))
        .Invokes(i => i.GetArgument <IParentParsingContext>(2).ParsedText = "Happy");

        await sut.ParseAsync(reader, context, parentContext);

        parentContext.ShouldContainSingle <MoodNode>(i => i.MoodType.Should().Be(MoodType.Happy));
    }
Exemple #5
0
    public async Task ShouldReturnVarSetNodeWhenParsingIsSuccessful()
    {
        const string parsedText = "alpha=1";

        var varSet = A.Dummy <IVarSet>();

        A.CallTo(() => varSetParser.Parse(parsedText)).Returns(varSet);

        A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.Settings))
        .Invokes(i => i.GetArgument <IParentParsingContext>(2).ParsedText = parsedText);

        await sut.ParseAsync(reader, context, parentContext);

        parentContext.ShouldContainSingle <VarSetNode>(i => i.VarSet.Should().BeSameAs(varSet));
    }
Exemple #6
0
    public async Task ShouldReturnVarSetNodeWhenParsingIsSuccessful()
    {
        const string parsedText = "alpha";

        A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.Settings))
        .Invokes(i => i.GetArgument <IParentParsingContext>(2).ParsedText = parsedText);

        await sut.ParseAsync(reader, context, parentContext);

        parentContext.ShouldContainSingle <VarSetNode>(
            i => i.VarSet.Should().BeOfType <VarSet>().Which.Should().BeEquivalentTo(new
        {
            Name  = parsedText,
            Value = (object)null
        })
            );
    }
Exemple #7
0
    public async Task AggregateNodeParser()
    {
        using var reader = Helper.CreateReader("<t><a /></t>");

        var parentContext = new FakeParentParsingContext();
        var context       = A.Fake <IParsingContext>(i => i.Strict());

        var node       = A.Dummy <INode>();
        var nodeParser = new FakeNodeParser("a", node);

        var sut      = new ElementParser();
        var settings = FakeSettings(new FakeAggregatedNodeParser(sut, nodeParser));

        await sut.ParseAsync(reader, context, parentContext, settings);

        parentContext.ShouldContainSingle(node);
    }
Exemple #8
0
    public async Task ShouldReturnNodeWhenParsedTextIsNotNull()
    {
        var reader        = A.Dummy <XmlReader>();
        var context       = A.Dummy <IParsingContext>();
        var parentContext = new FakeParentParsingContext();

        A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.Settings))
        .Invokes(i => i.Arguments.Get <IParentParsingContext>(2).ParsedText = "abc");

        A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.AggregationSettings))
        .DoesNothing();

        await sut.ParseAsync(reader, context, parentContext);

        parentContext.ShouldContainSingle <BalloonTextNode>(i => {
            i.TextSource.Should().BeSameAs(textSource);
            i.BalloonType.Should().Be(balloonType);
        });
    }
Exemple #9
0
    public async Task TextAndElementSimultaneouslyIsNotAllowed(string xml, bool textFirst)
    {
        const string message = "Não é permitido texto dentro de elemento que tenha elementos filhos.";

        using var reader = Helper.CreateReader(xml);

        var parentContext = new FakeParentParsingContext();
        var context       = A.Fake <IParsingContext>(i => i.Strict());

        A.CallTo(() => context.LogError(reader, message)).DoesNothing();

        var textParser = A.Fake <ITextParser>(i => i.Strict());

        A.CallTo(() => textParser.Parse(reader, context, "abc")).Returns("def");

        var node     = A.Dummy <INode>();
        var settings = FakeSettings(textParser, new FakeNodeParser("a", node));

        var sut = new ElementParser();
        await sut.ParseAsync(reader, context, parentContext, settings);

        parentContext.When.Should().BeNull();
        parentContext.While.Should().BeNull();
        if (textFirst)
        {
            parentContext.Nodes.Should().BeEmpty();
            parentContext.ParsedText.Should().Be("def");
        }
        else
        {
            parentContext.ShouldContainSingle(node);
            parentContext.ParsedText.Should().BeNull();
        }

        A.CallTo(() => context.LogError(reader, message)).MustHaveHappenedOnceExactly();
    }