[Fixes #3524] Handle negative long values in TempData correctly
This commit is contained in:
parent
900663bfdd
commit
bbba9dcde6
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
Loading…
Reference in New Issue