Skip to content

Commit

Permalink
Fixing bug throwing ArgumentOutOfRangeException if input is empty list
Browse files Browse the repository at this point in the history
ref : System.ArgumentOutOfRangeException : Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
  • Loading branch information
Thor Halvor Frivold committed Sep 17, 2018
1 parent eb2f170 commit a8da773
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public NLogMessageParameterList(IReadOnlyList<KeyValuePair<string, object>> para
/// </remarks>
public static NLogMessageParameterList TryParse(IReadOnlyList<KeyValuePair<string, object>> parameterList)
{
if (parameterList.Count > 1 || parameterList[0].Key != NLogLogger.OriginalFormatPropertyName)
if (parameterList.Count > 1 || (parameterList.Count == 1 && parameterList[0].Key != NLogLogger.OriginalFormatPropertyName))
{
return new NLogMessageParameterList(parameterList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,17 @@ public void CreateNLogMessageParameterDifferentCaptureTypes()
Assert.Equal(new MessageTemplateParameter("b", 2, null, CaptureType.Stringify), list[1]);
Assert.Equal(new MessageTemplateParameter("c", 3, null, CaptureType.Serialize), list[2]);
}

[Fact]
public void TryParseShouldReturnEmptyListWhenInputIsEmpty()
{

var items = new List<KeyValuePair<string, object>>{};
NLogMessageParameterList parsedList = NLogMessageParameterList.TryParse(items);

var expectedCount = 0;
Assert.NotNull(parsedList);
Assert.Equal(expectedCount, parsedList.Count);
}
}
}

0 comments on commit a8da773

Please sign in to comment.