public void find_default_header_for_property_that_is_not_decorated_should_just_return_null()
        {
            var token = new PropertyToken
            {
                ParentType = typeof(PropertyTokenTarget),
                PropertyName = "NotDecorated"
            };

            token.FindDefaultHeader(new CultureInfo("en-US")).ShouldBeNull();
        }
        public string FindMissingProperty(PropertyToken property, CultureInfo culture)
        {
            var defaultValue = culture.Equals(_defaultCulture)
                                   ? property.Header ?? property.DefaultHeaderText(culture) ?? BreakUpCamelCase(property.PropertyName)
                                   : property.DefaultHeaderText(culture) ?? culture.Name + "_" + property.PropertyName;

            _storage.WriteMissing(property.StringTokenKey, defaultValue, culture);

            return defaultValue;
        }
        public void find_default_header_for_the_attribute()
        {
            var token = new PropertyToken
            {
                ParentType = typeof(PropertyTokenTarget),
                PropertyName = "Name"
            };

            token.FindDefaultHeader(new CultureInfo("en-US")).ShouldEqual("The Name");
            token.FindDefaultHeader(new CultureInfo("en-CA")).ShouldEqual("Different");
            token.FindDefaultHeader(new CultureInfo("ja-JP")).ShouldBeNull();
        }
 public void TestSetup()
 {
     token  = new PropertyToken("prop", "D5");
     @event = new LogEvent(LogLevel.Info, DateTimeOffset.Now, null);
 }
Beispiel #5
0
        public void Render_NullFormatter_ThrowsNullArgumentException()
        {
            var property = new PropertyToken(Some.String(), Mock.Of <IPropertyToken>());

            Assert.Throws <ArgumentNullException>(() => property.Render(null));
        }
        /// <summary>
        /// Replaces chained property tokens with expression property tokens
        /// </summary>
        /// <param name="tokens">tokens input</param>
        /// <returns>tokens</returns>
        private static List <FilterExpressionToken> ReplacePropertyTokens(List <FilterExpressionToken> tokens)
        {
            List <PrimitiveExpressionToken> @symbols = tokens
                                                       .Where(x => x is PrimitiveExpressionToken pet && pet.Token.IsSymbolToken('@'))
                                                       .Cast <PrimitiveExpressionToken>()
                                                       .ToList();

            if (!symbols.Any())
            {
                return(tokens);
            }

            List <(PropertyExpressionToken prop, List <FilterExpressionToken> primitives)> replacements = new List <(PropertyExpressionToken, List <FilterExpressionToken>)>();

            foreach (PrimitiveExpressionToken st in @symbols)
            {
                List <PrimitiveExpressionToken> tokensForReplacement = new List <PrimitiveExpressionToken>();
                tokensForReplacement.Add(st);

                int index = tokens.IndexOf(st);
                index++;

                bool isPreviousDot = false;

                while (index < tokens.Count)
                {
                    FilterExpressionToken t = tokens[index];

                    isPreviousDot = index > 0 && (tokens[index - 1] is PrimitiveExpressionToken pet3 && pet3.Token.IsSymbolToken('.'));

                    bool isDot = t is PrimitiveExpressionToken pet && pet.Token.IsSymbolToken('.');
                    if (isDot)
                    {
                        if (isPreviousDot)
                        {
                            throw new UnexpectedTokenException((t as PrimitiveExpressionToken).Token);
                        }

                        index++;
                        continue;
                    }

                    if (t is PrimitiveExpressionToken pet2 && pet2.Token.IsPropertyToken())
                    {
                        PropertyToken prop = pet2.Token.CastToPropertyToken();

                        if (prop.Escaped && isPreviousDot)
                        {
                            throw new UnexpectedTokenException(prop, "Unexpected token after \".\" symbol");
                        }

                        tokensForReplacement.Add(t as PrimitiveExpressionToken);
                        index++;
                        continue;
                    }

                    if (t is PrimitiveExpressionToken pet4 && (pet4.Token.IsChildPropertiesToken() || pet4.Token.IsRecursivePropertiesToken()))
                    {
                        tokensForReplacement.Add(t as PrimitiveExpressionToken);
                        index++;
                        continue;
                    }

                    break;
                }

                List <PrimitiveExpressionToken> tokensToRemove = tokensForReplacement.ToList();
                if (tokensForReplacement.First().Token.IsSymbolToken('@'))
                {
                    tokensForReplacement = tokensForReplacement.Skip(1).ToList();
                }

                for (int i = 0; i < tokensForReplacement.Count - 1; i++)
                {
                    if (tokensForReplacement[i].Token.IsChildPropertiesToken() || tokensForReplacement[i].Token.IsRecursivePropertiesToken())
                    {
                        // only last property can be wildcard * or recursive ..
                        string accessor = tokensForReplacement[i].Token.IsChildPropertiesToken() ? "\"*\"" : "\"..\"";
                        throw new ParsingException($"Unexpected token accessor {accessor} at {tokensForReplacement[i].Token.StartIndex}" +
                                                   ", this kind of token is expected to be last in property chain");
                    }
                }

                PropertyExpressionToken propEx;
                Token last = tokensForReplacement.Last().Token;

                if (last.IsRecursivePropertiesToken())
                {
                    List <PrimitiveExpressionToken> props = tokensForReplacement.Where(x => !x.Token.IsSymbolToken('@')).ToList();
                    props = tokensForReplacement.Take(props.Count - 1).ToList();

                    propEx = new PropertyExpressionToken(
                        props.Select(x => x.Token.CastToPropertyToken()).ToArray(),
                        tokensForReplacement.Last().Token.CastToRecursivePropertiesToken(),
                        tokensForReplacement.First().StartIndex
                        );
                }
                else if (last.IsChildPropertiesToken())
                {
                    List <PrimitiveExpressionToken> props = tokensForReplacement.Where(x => !x.Token.IsSymbolToken('@')).ToList();
                    props = tokensForReplacement.Take(props.Count - 1).ToList();

                    propEx = new PropertyExpressionToken(
                        props.Select(x => x.Token.CastToPropertyToken()).ToArray(),
                        tokensForReplacement.Last().Token.CastToChildPropertiesToken(),
                        tokensForReplacement.First().StartIndex
                        );
                }
                else
                {
                    propEx = new PropertyExpressionToken(
                        tokensForReplacement.Where(x => !x.Token.IsSymbolToken('@')).Select(x => x.Token.CastToPropertyToken()).ToArray(),
                        tokensForReplacement.First().StartIndex
                        );
                }

                replacements.Add((propEx, tokensToRemove.Cast <FilterExpressionToken>().ToList()));
            }

            List <FilterExpressionToken> ret = tokens.ToList();

            foreach ((PropertyExpressionToken prop, List <FilterExpressionToken> primitives)r in replacements)
            {
                List <int> indexes = r.primitives.Select(x => ret.IndexOf(x)).ToList();

                for (int i = indexes.First(); i <= indexes.Last(); i++)
                {
                    ret[i] = null;
                }

                ret[indexes[0]] = r.prop;
            }

            return(ret.Where(x => x != null).ToList());
        }
 public string GetHeader(PropertyToken property)
 {
     var localizationKey = new LocalizationKey(property.StringTokenKey);
     return _localeCache
         .Retrieve(localizationKey, () => _missingHandler.FindMissingProperty(property, _localeCache.Culture));
 }
 public PropertiesTokenRenderer(PropertyToken token, MessageTemplate outputTemplate)
 {
     _outputTemplate = outputTemplate;
     _token          = token;
 }
 public LevelTokenRenderer(PropertyToken levelToken)
 {
     _levelToken = levelToken;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultPropertyRenderer"/> class.
 /// </summary>
 /// <param name="propertyToken">The property token.</param>
 public DefaultPropertyRenderer(PropertyToken propertyToken)
 {
     this.propertyToken = propertyToken;
 }
Beispiel #11
0
 public LevelTokenRenderer(ConsoleTheme theme, PropertyToken levelToken)
 {
     _theme      = theme;
     _levelToken = levelToken;
 }
Beispiel #12
0
 public AddDestructuringToMessageTemplatePropertyFix([NotNull] ComplexObjectDestructuringWarning error)
 {
     _range         = error.Range;
     _stringLiteral = error.StringLiteral;
     _namedProperty = error.NamedProperty;
 }
Beispiel #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LogLevelRenderer"/> class.
 /// </summary>
 /// <param name="propertyToken">The property token.</param>
 internal LogLevelRenderer(PropertyToken propertyToken)
 {
     this.propertyToken = propertyToken;
 }
Beispiel #14
0
 public LevelTokenRenderer(RichTextBoxTheme theme, PropertyToken levelToken)
 {
     _theme      = theme;
     _levelToken = levelToken;
 }
Beispiel #15
0
 public ExceptionTokenRenderer(ConsoleTheme theme, PropertyToken pt)
 {
     _theme = theme;
 }
Beispiel #16
0
 public EventPropertyTokenRenderer(ConsoleTheme theme, PropertyToken token, IFormatProvider formatProvider)
 {
     _theme          = theme;
     _token          = token;
     _formatProvider = formatProvider;
 }
 public string GetDefaultText(PropertyToken property)
 {
     return Culture.Name + "_" + property.PropertyName;
 }
Beispiel #18
0
 public TimestampTokenRenderer(HtmlTheme theme, PropertyToken token)
 {
     _theme = theme;
     _token = token;
 }
 public bool Equals(PropertyToken obj)
 {
 }
 public NewLineTokenFormatter(PropertyToken propertyToken)
 {
     _propertyToken = propertyToken;
 }
Beispiel #21
0
 public void VisitProperty(PropertyToken property)
 {
     Property = property;
 }
 private static MemberInfo GetMemberInfoFromPropertyToken(PropertyToken token, Type targetType)
 {
     return(targetType.FindPropertyOrField(token.PropertyName));
 }
Beispiel #23
0
 /// <inheritdoc />
 public LevelRenderer(PropertyToken token, LogEventLevel body, ConsoleThemeStyle style, TextWriter writer)
     : base(body, style, writer)
 {
 }
Beispiel #24
0
 public TimestampTokenRenderer(PropertyToken token, IFormatProvider formatProvider)
 {
     _token          = token;
     _formatProvider = formatProvider;
 }
Beispiel #25
0
 public bool Equals(PropertyToken obj) => obj.Token == Token;
Beispiel #26
0
 public ExceptionTokenFormatter(PropertyToken propertyToken)
 {
     _propertyToken = propertyToken;
 }
Beispiel #27
0
 TemplateProperty ConstructProperty(PropertyToken propertyToken, object value)
 {
     return(new TemplateProperty(
                propertyToken.PropertyName,
                _valueConverter.CreatePropertyValue(value, propertyToken.Destructuring)));
 }
Beispiel #28
0
 public LevelTokenRenderer(KonsoleTheme theme, PropertyToken levelToken, ConcurrentWriter concurrentWriter)
 {
     _theme            = theme;
     _levelToken       = levelToken;
     _concurrentWriter = concurrentWriter;
 }
 public static LocalizationKey ToLocalizationKey(this PropertyToken propertyInfo)
 {
     return(new LocalizationKey(propertyInfo.PropertyName, propertyInfo.ParentTypeName));
 }
Beispiel #30
0
 public bool Equals(PropertyToken obj)
 {
 }
        public void Should_not_insert_surrounding_spaces_around_missing_property()
        {
            token = new PropertyToken("prop", "wW");

            Render().Should().BeEmpty();
        }
Beispiel #32
0
 public static bool op_Inequality(PropertyToken a, PropertyToken b)
 {
 }
Beispiel #33
0
 public EventPropertyTokenRenderer(RichTextBoxTheme theme, PropertyToken token, IFormatProvider formatProvider)
 {
     _theme          = theme;
     _token          = token;
     _formatProvider = formatProvider;
 }
 public LevelTokenFormatter(PropertyToken propertyToken)
 {
     _propertyToken = propertyToken;
 }
 public string GetHeader(PropertyToken property)
 {
     return Culture.Name + "_" + property.PropertyName;
 }
 public EventPropertyTokenRenderer(PropertyToken token, IFormatProvider formatProvider)
 {
     _token          = token;
     _formatProvider = formatProvider;
 }
Beispiel #37
0
 public ExceptionTokenRenderer(HtmlTheme theme, PropertyToken pt)
 {
     _theme = theme;
 }
 public static bool op_Inequality(PropertyToken a, PropertyToken b)
 {
 }