[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)
|
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.
|
||||||
|
|
|
||||||
|
|
@ -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 }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue