diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/SessionStateTempDataProviderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/SessionStateTempDataProviderTest.cs index 5edcd031af..54a8ef1527 100644 --- a/test/Microsoft.AspNet.Mvc.Core.Test/SessionStateTempDataProviderTest.cs +++ b/test/Microsoft.AspNet.Mvc.Core.Test/SessionStateTempDataProviderTest.cs @@ -172,25 +172,13 @@ namespace Microsoft.AspNet.Mvc } [Fact] - public void SaveAndLoad_SimpleTypesCanBeStoredAndLoaded() + public void SaveAndLoad_StringCanBeStoredAndLoaded() { // Arrange var testProvider = new SessionStateTempDataProvider(); - var inputGuid = Guid.NewGuid(); - var inputDictionary = new Dictionary - { - { "Hello", "World" }, - }; var input = new Dictionary { - { "string", "value" }, - { "int", 10 }, - { "bool", false }, - { "DateTime", new DateTime() }, - { "Guid", inputGuid }, - { "List`string", new List { "one", "two" } }, - { "Dictionary", inputDictionary }, - { "EmptyDictionary", new Dictionary() } + { "string", "value" } }; var context = GetHttpContext(new TestSessionCollection(), true); @@ -201,20 +189,154 @@ namespace Microsoft.AspNet.Mvc // Assert var stringVal = Assert.IsType(TempData["string"]); Assert.Equal("value", stringVal); + } + + [Fact] + public void SaveAndLoad_IntCanBeStoredAndLoaded() + { + // Arrange + var testProvider = new SessionStateTempDataProvider(); + var input = new Dictionary + { + { "int", 10 } + }; + var context = GetHttpContext(new TestSessionCollection(), true); + + // Act + testProvider.SaveTempData(context, input); + var TempData = testProvider.LoadTempData(context); + + // Assert var intVal = Convert.ToInt32(TempData["int"]); Assert.Equal(10, intVal); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public void SaveAndLoad_BoolCanBeStoredAndLoaded(bool value) + { + // Arrange + var testProvider = new SessionStateTempDataProvider(); + var input = new Dictionary + { + { "bool", value } + }; + var context = GetHttpContext(new TestSessionCollection(), true); + + // Act + testProvider.SaveTempData(context, input); + var TempData = testProvider.LoadTempData(context); + + // Assert var boolVal = Assert.IsType(TempData["bool"]); - Assert.Equal(false, boolVal); - var datetimeVal = Assert.IsType(TempData["DateTime"]); - Assert.Equal(new DateTime().ToString(), datetimeVal.ToString()); + Assert.Equal(value, boolVal); + } + + [Fact] + public void SaveAndLoad_DateTimeCanBeStoredAndLoaded() + { + // Arrange + var testProvider = new SessionStateTempDataProvider(); + var inputDatetime = new DateTime(2010, 12, 12, 1, 2, 3, DateTimeKind.Local); + var input = new Dictionary + { + { "DateTime", inputDatetime } + }; + var context = GetHttpContext(new TestSessionCollection(), true); + + // Act + testProvider.SaveTempData(context, input); + var TempData = testProvider.LoadTempData(context); + + // Assert + var datetime = Assert.IsType(TempData["DateTime"]); + Assert.Equal(inputDatetime, datetime); + } + + [Fact] + public void SaveAndLoad_GuidCanBeStoredAndLoaded() + { + // Arrange + var testProvider = new SessionStateTempDataProvider(); + var inputGuid = Guid.NewGuid(); + var input = new Dictionary + { + { "Guid", inputGuid } + }; + var context = GetHttpContext(new TestSessionCollection(), true); + + // Act + testProvider.SaveTempData(context, input); + var TempData = testProvider.LoadTempData(context); + + // Assert var guidVal = Assert.IsType(TempData["Guid"]); - Assert.Equal(inputGuid.ToString(), guidVal.ToString()); + Assert.Equal(inputGuid, guidVal); + } + + [Fact] + public void SaveAndLoad_ListCanBeStoredAndLoaded() + { + // Arrange + var testProvider = new SessionStateTempDataProvider(); + var input = new Dictionary + { + { "List`string", new List { "one", "two" } } + }; + var context = GetHttpContext(new TestSessionCollection(), true); + + // Act + testProvider.SaveTempData(context, input); + var TempData = testProvider.LoadTempData(context); + + // Assert var list = (IList)TempData["List`string"]; Assert.Equal(2, list.Count); Assert.Equal("one", list[0]); Assert.Equal("two", list[1]); + } + + [Fact] + public void SaveAndLoad_DictionaryCanBeStoredAndLoaded() + { + // Arrange + var testProvider = new SessionStateTempDataProvider(); + var inputDictionary = new Dictionary + { + { "Hello", "World" }, + }; + var input = new Dictionary + { + { "Dictionary", inputDictionary } + }; + var context = GetHttpContext(new TestSessionCollection(), true); + + // Act + testProvider.SaveTempData(context, input); + var TempData = testProvider.LoadTempData(context); + + // Assert var dictionary = Assert.IsType>(TempData["Dictionary"]); Assert.Equal("World", dictionary["Hello"]); + } + + [Fact] + public void SaveAndLoad_EmptyDictionary_RoundTripsAsNull() + { + // Arrange + var testProvider = new SessionStateTempDataProvider(); + var input = new Dictionary + { + { "EmptyDictionary", new Dictionary() } + }; + var context = GetHttpContext(new TestSessionCollection(), true); + + // Act + testProvider.SaveTempData(context, input); + var TempData = testProvider.LoadTempData(context); + + // Assert var emptyDictionary = (IDictionary)TempData["EmptyDictionary"]; Assert.Null(emptyDictionary); }