[Fixes #3524] Handle negative long values in TempData correctly

This commit is contained in:
Ajay Bhargav Baaskaran 2015-12-14 12:16:51 -08:00
parent 900663bfdd
commit bbba9dcde6
2 changed files with 12 additions and 8 deletions

View File

@ -132,7 +132,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
else if (item.Value is long)
{
var longValue = (long)item.Value;
if (longValue < int.MaxValue)
if (longValue >= int.MinValue && longValue <= int.MaxValue)
{
// BsonReader casts all ints to longs. We'll attempt to work around this by force converting
// longs to ints when there's no loss of precision.

View File

@ -170,14 +170,17 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
Assert.Equal("value", stringVal);
}
[Fact]
public void SaveAndLoad_IntCanBeStoredAndLoaded()
[Theory]
[InlineData(10)]
[InlineData(int.MaxValue)]
[InlineData(int.MinValue)]
public void SaveAndLoad_IntCanBeStoredAndLoaded(int expected)
{
// Arrange
var testProvider = new SessionStateTempDataProvider();
var input = new Dictionary<string, object>
{
{ "int", 10 }
{ "int", expected }
};
var context = GetHttpContext();
@ -187,7 +190,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
// Assert
var intVal = Assert.IsType<int>(TempData["int"]);
Assert.Equal(10, intVal);
Assert.Equal(expected, intVal);
}
[Theory]
@ -277,13 +280,14 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
Assert.Equal(expected, actual);
}
[Fact]
public void SaveAndLoad_LongCanBeSavedAndLoaded()
[Theory]
[InlineData(3100000000L)]
[InlineData(-3100000000L)]
public void SaveAndLoad_LongCanBeSavedAndLoaded(long expected)
{
// Arrange
var key = "LongValue";
var testProvider = new SessionStateTempDataProvider();
var expected = 3100000000L;
var input = new Dictionary<string, object>
{
{ key, expected }