Beispiel #1
0
        public void TokenStringBuilder_WithTokens()
        {
            // arrange
            const string configKey   = "configKey";
            const string configValue = "A";
            const string tokenKey    = "season";
            const string raw         = "  assets/{{configKey}}_{{season}}_{{ invalid  }}.png  ";
            var          context     = new GenericTokenContext(modId => false);

            context.Save(new ImmutableToken(configKey, new InvariantHashSet {
                configValue
            }));
            context.Save(new ImmutableToken(tokenKey, new InvariantHashSet {
                "A"
            }));

            // act
            TokenString      tokenStr        = new TokenString(raw, context);
            IContextualState diagnosticState = tokenStr.GetDiagnosticState();

            // assert
            tokenStr.Raw.Should().Be("assets/{{configKey}}_{{season}}_{{invalid}}.png");
            tokenStr.GetTokenPlaceholders(recursive: false).Should().HaveCount(3);
            tokenStr.GetTokenPlaceholders(recursive: false).Select(name => name.Text).Should().BeEquivalentTo(new[] { "{{configKey}}", "{{season}}", "{{invalid}}" });
            tokenStr.IsReady.Should().BeFalse();
            tokenStr.HasAnyTokens.Should().BeTrue();
            tokenStr.IsSingleTokenOnly.Should().BeFalse();
            diagnosticState.IsReady.Should().BeFalse();
            diagnosticState.UnreadyTokens.Should().BeEmpty();
            diagnosticState.InvalidTokens.Should().HaveCount(1).And.BeEquivalentTo("invalid");
            diagnosticState.Errors.Should().BeEmpty();
        }
Beispiel #2
0
        public void TokenStringBuilder_WithTokens()
        {
            // arrange
            const string configKey   = "configKey";
            const string configValue = "A";
            const string tokenKey    = "season";
            const string raw         = "  assets/{{configKey}}_{{season}}_{{invalid}}.png  ";
            var          context     = new GenericTokenContext();

            context.Save(new ImmutableToken(configKey, new InvariantHashSet {
                configValue
            }));
            context.Save(new ImmutableToken(tokenKey, new InvariantHashSet {
                "A"
            }));

            // act
            TokenString tokenStr = new TokenString(raw, context);

            // assert
            tokenStr.Raw.Should().Be(raw.Trim());
            tokenStr.Tokens.Should().HaveCount(2);
            tokenStr.Tokens.Select(name => name.ToString()).Should().BeEquivalentTo(new[] { configKey, tokenKey });
            tokenStr.InvalidTokens.Should().HaveCount(1).And.BeEquivalentTo("invalid");
            tokenStr.HasAnyTokens.Should().BeTrue();
            tokenStr.IsSingleTokenOnly.Should().BeFalse();
        }
Beispiel #3
0
        public void TokenStringBuilder_WithSingleToken(string raw, string parsed)
        {
            // arrange
            const string configKey = "tokenKey";
            var          context   = new GenericTokenContext(modId => false);

            context.Save(new ImmutableToken(configKey, new InvariantHashSet {
                "value"
            }));

            // act
            TokenString      tokenStr        = new TokenString(raw, context);
            IContextualState diagnosticState = tokenStr.GetDiagnosticState();

            // assert
            tokenStr.Raw.Should().Be(parsed);
            tokenStr.GetTokenPlaceholders(recursive: false).Should().HaveCount(1);
            tokenStr.GetTokenPlaceholders(recursive: false).Select(p => p.Text).Should().BeEquivalentTo("{{" + configKey + "}}");
            tokenStr.HasAnyTokens.Should().BeTrue();
            tokenStr.IsSingleTokenOnly.Should().BeTrue();
            diagnosticState.IsReady.Should().BeTrue();
            diagnosticState.UnreadyTokens.Should().BeEmpty();
            diagnosticState.InvalidTokens.Should().BeEmpty();
            diagnosticState.Errors.Should().BeEmpty();
        }
Beispiel #4
0
        public void TokenStringBuilder_WithSingleToken(string raw)
        {
            // arrange
            const string configKey = "tokenKey";
            var          context   = new GenericTokenContext();

            context.Save(new ImmutableToken(configKey, new InvariantHashSet {
                "value"
            }));

            // act
            TokenString tokenStr = new TokenString(raw, context);

            // assert
            tokenStr.Raw.Should().Be(raw.Trim());
            tokenStr.Tokens.Should().HaveCount(1);
            tokenStr.Tokens.Select(p => p.ToString()).Should().BeEquivalentTo(configKey);
            tokenStr.InvalidTokens.Should().BeEmpty();
            tokenStr.HasAnyTokens.Should().BeTrue();
            tokenStr.IsSingleTokenOnly.Should().BeTrue();
        }