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