Exemplo n.º 1
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();
    }
Exemplo n.º 2
0
    public async Task OptionalPropertiesInformed()
    {
        var reader        = A.Dummy <XmlReader>();
        var context       = A.Fake <IParsingContext>(i => i.Strict());
        var parentContext = new BalloonChildParsingContext();

        var optionNode1 = A.Dummy <IChoiceOptionNode>();

        A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.Settings))
        .Invokes(i => {
            var ctx = i.GetArgument <ChoiceParentParsingContext>(2);
            ctx.Choice.Options.Add(optionNode1);
            ctx.Choice.TimeLimit   = TimeSpan.FromSeconds(8);
            ctx.Choice.Default     = "a";
            ctx.Choice.RandomOrder = true;
        });

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

        parentContext.ChoiceNode.Should().NotBeNull();
        parentContext.ChoiceNode.TimeLimit.Should().Be(TimeSpan.FromSeconds(8));
        parentContext.ChoiceNode.Default.Should().Be("a");
        parentContext.ChoiceNode.RandomOrder.Should().BeTrue();
        parentContext.ChoiceNode.Options.Count.Should().Be(1);
        parentContext.ChoiceNode.Options[0].Should().BeSameAs(optionNode1);
    }
Exemplo n.º 3
0
    public async Task ShouldLogErrorWhenNoOptionWasParsed()
    {
        var message = "Nenhuma opção informada.";

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

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

        var parentContext = new BalloonChildParsingContext();

        var optionNode1 = A.Dummy <IChoiceOptionNode>();

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

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

        parentContext.ChoiceNode.Should().BeNull();

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