Example #1
0
    public async Task ShouldLogTextSourceParsingError()
    {
        var errorMessage  = "Erro proposital.";
        var reader        = A.Dummy <XmlReader>();
        var parentContext = new FakeParentParsingContext();

        var parsingResult = A.Dummy <ITextSourceParserResult>();

        A.CallTo(() => parsingResult.IsError).Returns(true);
        A.CallTo(() => parsingResult.ErrorMessage).Returns(errorMessage);

        A.CallTo(() => textSourceParser.Parse("abc")).Returns(parsingResult);

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

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

        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);

        A.CallTo(() => context.LogError(reader, errorMessage)).MustHaveHappenedOnceExactly();
    }
Example #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();
    }
Example #3
0
    public BalloonChildNodeParserBaseTests()
    {
        textSource = A.Dummy <ITextSource>();
        var textSourceParserResult = A.Fake <ITextSourceParserResult>(i => i.Strict());

        A.CallTo(() => textSourceParserResult.IsError).Returns(false);
        A.CallTo(() => textSourceParserResult.TextSource).Returns(textSource);

        textSourceParser = A.Fake <ITextSourceParser>(i => i.Strict());
        A.CallTo(() => textSourceParser.Parse(A <string> .Ignored)).Returns(textSourceParserResult);

        elementParser         = A.Fake <IElementParser>(i => i.Strict());
        balloonTextNodeParser = Helper.FakeParser <IBalloonTextNodeParser>("xyz");
        A.CallTo(() => balloonTextNodeParser.BalloonType).Returns(balloonType);
        choiceNodeParser = Helper.FakeParser <IChoiceNodeParser>("choice");
        sut = new (elementParser, textSourceParser, balloonTextNodeParser, choiceNodeParser);
    }