Exemplo n.º 1
0
    public async Task ShouldDoNothingIfTextParserReturnsNull()
    {
        A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.Settings))
        .DoesNothing();

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

        parentContext.ShouldBeEmpty();
    }
Exemplo n.º 2
0
    public async Task ShouldLogErrorWhenHasMoodIsTrue()
    {
        var message = "Mais de uma definição de humor para a mesma cena.";

        var reader        = A.Dummy <XmlReader>();
        var parentContext = new FakeParentParsingContext();

        var sceneContext = A.Fake <IParsingSceneContext>(i => i.Strict());

        A.CallTo(() => sceneContext.HasMood).Returns(true);

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

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

        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.ShouldBeEmpty();

        A.CallTo(() => context.LogError(reader, message)).MustHaveHappenedOnceExactly();
    }
Exemplo n.º 3
0
    public async Task ParseAsyncShouldReturnNullIfParsedTextIsNull()
    {
        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)).DoesNothing();

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

        parentContext.ShouldBeEmpty();
    }
Exemplo n.º 4
0
    public async Task ParseAsyncShouldLogErrorIfParsedTextIsEmpty()
    {
        var errorMessage  = "Era esperado o nome do personagem.";
        var reader        = A.Dummy <XmlReader>();
        var context       = A.Fake <IParsingContext>(i => i.Strict());
        var parentContext = new FakeParentParsingContext();

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

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

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

        parentContext.ShouldBeEmpty();

        A.CallTo(() => context.LogError(reader, errorMessage)).MustHaveHappenedOnceExactly();
    }
Exemplo n.º 5
0
    public async Task InvalidContent(string xmlContent, string message)
    {
        using var reader = Helper.CreateReader(xmlContent);
        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());

        var settings = FakeSettings(textParser);

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

        parentContext.ShouldBeEmpty();

        A.CallTo(() => context.LogError(reader, message)).MustHaveHappenedOnceExactly();
    }
Exemplo n.º 6
0
    public async Task UnconfiguredText()
    {
        const string message = "Este elemento não permite texto.";

        using var reader = Helper.CreateReader("<t>Pindamonhangaba</t>");

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

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

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

        parentContext.ShouldBeEmpty();

        A.CallTo(() => context.LogError(reader, message)).MustHaveHappenedOnceExactly();
    }
Exemplo n.º 7
0
    public async Task ShouldNotCreateNodeWhenThereAreNoMoreElements()
    {
        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 = "lorenipsum");

        // Se depois do elementParser.ParseAsync o ReadState for EndOfFile significa que não há mais elementos
        // dentro do elemento atual
        A.CallTo(() => reader.ReadState).Returns(ReadState.EndOfFile);

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

        parentContext.ShouldBeEmpty();

        A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.Settings))
        .MustHaveHappenedOnceExactly();
    }
Exemplo n.º 8
0
    public async Task ShouldNotCreateNodeWhenThereAreNoAggregatableElements()
    {
        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 = "lorenipsum");

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

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

        parentContext.ShouldBeEmpty();

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