示例#1
0
        public void SaveAndLoad_GuidCanBeStoredAndLoaded()
        {
            // Arrange
            var testProvider = new SessionStateTempDataProvider();
            var inputGuid    = Guid.NewGuid();
            var input        = new Dictionary <string, object>
            {
                { "Guid", inputGuid }
            };
            var context = GetHttpContext();

            // Act
            testProvider.SaveTempData(context, input);
            var TempData = testProvider.LoadTempData(context);

            // Assert
            var guidVal = Assert.IsType <Guid>(TempData["Guid"]);

            Assert.Equal(inputGuid, guidVal);
        }
示例#2
0
        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 <string, object>
            {
                { "DateTime", inputDatetime }
            };
            var context = GetHttpContext();

            // Act
            testProvider.SaveTempData(context, input);
            var TempData = testProvider.LoadTempData(context);

            // Assert
            var datetime = Assert.IsType <DateTime>(TempData["DateTime"]);

            Assert.Equal(inputDatetime, datetime);
        }
示例#3
0
        public void SaveAndLoad_LongCanBeSavedAndLoaded(long expected)
        {
            // Arrange
            var key          = "LongValue";
            var testProvider = new SessionStateTempDataProvider();
            var input        = new Dictionary <string, object>
            {
                { key, expected }
            };
            var context = GetHttpContext();

            // Act
            testProvider.SaveTempData(context, input);
            var TempData = testProvider.LoadTempData(context);
            var result   = TempData[key];

            // Assert
            var actual = Assert.IsType <long>(result);

            Assert.Equal(expected, actual);
        }
示例#4
0
        public void SaveAndLoad_EnumCanBeSavedAndLoaded()
        {
            // Arrange
            var key          = "EnumValue";
            var testProvider = new SessionStateTempDataProvider();
            var expected     = DayOfWeek.Friday;
            var input        = new Dictionary <string, object>
            {
                { key, expected }
            };
            var context = GetHttpContext();

            // Act
            testProvider.SaveTempData(context, input);
            var TempData = testProvider.LoadTempData(context);
            var result   = TempData[key];

            // Assert
            var actual = (DayOfWeek)result;

            Assert.Equal(expected, actual);
        }
示例#5
0
        public void SaveAndLoad_DictionaryCanBeStoredAndLoaded()
        {
            // Arrange
            var testProvider    = new SessionStateTempDataProvider();
            var inputDictionary = new Dictionary <string, string>
            {
                { "Hello", "World" },
            };
            var input = new Dictionary <string, object>
            {
                { "Dictionary", inputDictionary }
            };
            var context = GetHttpContext();

            // Act
            testProvider.SaveTempData(context, input);
            var TempData = testProvider.LoadTempData(context);

            // Assert
            var dictionary = Assert.IsType <Dictionary <string, string> >(TempData["Dictionary"]);

            Assert.Equal("World", dictionary["Hello"]);
        }
示例#6
0
        public void SaveAndLoad_ListCanBeStoredAndLoaded()
        {
            // Arrange
            var testProvider = new SessionStateTempDataProvider();
            var input        = new Dictionary <string, object>
            {
                { "List`string", new List <string> {
                      "one", "two"
                  } }
            };
            var context = GetHttpContext();

            // Act
            testProvider.SaveTempData(context, input);
            var TempData = testProvider.LoadTempData(context);

            // Assert
            var list = (IList <string>)TempData["List`string"];

            Assert.Equal(2, list.Count);
            Assert.Equal("one", list[0]);
            Assert.Equal("two", list[1]);
        }