Example #1
0
    public async Task ShouldCopyOptionalPropertiesToOptionNode()
    {
        var reader = A.Dummy <XmlReader>();

        A.CallTo(() => reader.LocalName).Returns("j");

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

        var enabledWhen = A.Dummy <ICondition>();
        var visibleWhen = A.Dummy <ICondition>();

        A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.Settings))
        .Invokes(i => {
            var ctx                 = i.GetArgument <ChoiceOptionParentParsingContext>(2);
            ctx.Option.Text         = "Alpha Beta Gamma";
            ctx.Option.DisabledText = "Disabled";
            ctx.Option.EnabledWhen  = enabledWhen;
            ctx.Option.VisibleWhen  = visibleWhen;
        });

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

        parentContext.Choice.Options.Should().ContainSingle()
        .Which.Should().BeEquivalentTo(new
        {
            Key          = "j",
            Text         = "Alpha Beta Gamma",
            DisabledText = "Disabled",
            EnabledWhen  = enabledWhen,
            VisibleWhen  = visibleWhen
        });
    }
Example #2
0
    public async Task ShouldIgnoreZeroOrEmptyText(string parsedText)
    {
        var reader        = A.Dummy <XmlReader>();
        var context       = A.Fake <IParsingContext>(i => i.Strict());
        var parentContext = new ChoiceParentParsingContext();

        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.Choice.TimeLimit.Should().BeNull();
    }
Example #3
0
    public async Task ShouldUpdateParentContextWithParsedText(string parsedValue)
    {
        var reader        = A.Dummy <XmlReader>();
        var context       = A.Fake <IParsingContext>(i => i.Strict());
        var parentContext = new ChoiceParentParsingContext();

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

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

        parentContext.Choice.Default.Should().Be(parsedValue);
    }
Example #4
0
    public async Task ShouldSetParentContextRandomOrderToTrue()
    {
        var reader        = A.Dummy <XmlReader>();
        var context       = A.Fake <IParsingContext>(i => i.Strict());
        var parentContext = new ChoiceParentParsingContext();

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

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

        parentContext.Choice.RandomOrder.Should().BeTrue();
    }
Example #5
0
    public async Task ParseAsync(XmlReader reader, IParsingContext parsingContext, IParentParsingContext parentParsingContext)
    {
        var myContext = new ChoiceParentParsingContext();
        await elementParser.ParseAsync(reader, parsingContext, myContext, Settings);

        if (myContext.Choice.Options.Count == 0)
        {
            parsingContext.LogError(reader, "Nenhuma opção informada.");
            return;
        }

        var ctx = (BalloonChildParsingContext)parentParsingContext;

        ctx.ChoiceNode = myContext.Choice;
    }
Example #6
0
    public async Task ShouldSetParentContextTimeLimit(string parsedText)
    {
        var reader        = A.Dummy <XmlReader>();
        var context       = A.Fake <IParsingContext>(i => i.Strict());
        var parentContext = new ChoiceParentParsingContext();

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

        var expected = TimeSpan.FromMilliseconds(int.Parse(parsedText));

        parentContext.Choice.TimeLimit.Should().Be(expected);
    }
Example #7
0
    public async Task ShouldLogErrorWhenParsedTimeIsBiggerThan30000()
    {
        const string message = "O limite de tempo não pode ser maior que 30 segundos.";

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

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

        var parentContext = new ChoiceParentParsingContext();

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

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

        parentContext.Choice.TimeLimit.Should().BeNull();
        A.CallTo(() => context.LogError(reader, message)).MustHaveHappenedOnceExactly();
    }
Example #8
0
    public async Task ShouldLogErrorWhenOptionTextIsNotDefined()
    {
        var errorMessage = "O texto da opção não foi informado.";

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

        A.CallTo(() => reader.LocalName).Returns("x");

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

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

        var parentContext = new ChoiceParentParsingContext();

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

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

        parentContext.Choice.Options.Should().BeEmpty();

        A.CallTo(() => context.LogError(reader, errorMessage)).MustHaveHappenedOnceExactly();
    }
Example #9
0
    public async Task ShoudCreateOptionInParentContext()
    {
        var reader = A.Dummy <XmlReader>();

        A.CallTo(() => reader.LocalName).Returns("n");

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

        A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.Settings))
        .Invokes(i => i.GetArgument <ChoiceOptionParentParsingContext>(2).Option.Text = "Loren Ipsum");

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

        parentContext.Choice.Options.Should().ContainSingle()
        .Which.Should().BeEquivalentTo(new
        {
            Key          = "n",
            Text         = "Loren Ipsum",
            DisabledText = (string)null,
            EnabledWhen  = (ICondition)null,
            VisibleWhen  = (ICondition)null
        });
    }
Example #10
0
    public void Initialization()
    {
        var sut = new ChoiceParentParsingContext();

        sut.Choice.Should().NotBeNull();
    }