예제 #1
0
        public void GetState_Exception_KeyIsUndefined()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

            var e = Assert.Throws <KeyNotFoundException>(() => navigationEntry.GetState <string>("Undefined"));

            Assert.Equal("The given key was not present in the dictionary.", e.Message);
        }
예제 #2
0
        public void GetState_Exception_KeyIsEmpty()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

            var e = Assert.Throws <ArgumentException>(() => navigationEntry.GetState <string>(""));

            Assert.Equal("The argument cannot be null or an empty string.\r\nParameter name: key", e.Message);
            Assert.Equal("key", e.ParamName);
        }
예제 #3
0
        public void GetSetState_Class_StoresNullState()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

            navigationEntry.SetState <ClassState>("MyKey", null);
            var result = navigationEntry.GetState <ClassState>("MyKey");

            Assert.Equal(null, result);
        }
예제 #4
0
        public void GetSetState_Int_StoresState()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

            navigationEntry.SetState <int>("MyKey", 42);
            var result = navigationEntry.GetState <int>("MyKey");

            Assert.Equal(42, result);
        }
예제 #5
0
        public void GetSetState_String_StoresState()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

            navigationEntry.SetState <string>("MyKey", "Test State");
            var result = navigationEntry.GetState <string>("MyKey");

            Assert.Equal("Test State", result);
        }
예제 #6
0
        public void GetState_Exception_IncorrectType()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

            navigationEntry.SetState <string>("MyKey", "Test State");

            var e = Assert.Throws <InvalidCastException>(() => navigationEntry.GetState <int>("MyKey"));

            Assert.Equal("Specified cast is not valid.", e.Message);
        }
예제 #7
0
        public void Serialization_PersistsState_NullClass()
        {
            PageInfo sourceEntry = new PageInfo("Page Name", "Arguments");

            sourceEntry.SetState <ClassState>("MyKey", null);

            byte[]   data     = SerializationHelper.SerializeToArray(sourceEntry);
            PageInfo newEntry = SerializationHelper.DeserializeFromArray <PageInfo>(data);

            Assert.Equal(null, newEntry.GetState <ClassState>("MyKey"));
        }
예제 #8
0
        public void GetSetState_Struct_StoresState()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

            navigationEntry.SetState <StructState>("MyKey", new StructState()
            {
                Text = "Text Value", Number = 42
            });
            var result = navigationEntry.GetState <StructState>("MyKey");

            Assert.Equal("Text Value", result.Text);
            Assert.Equal(42, result.Number);
        }
예제 #9
0
        public void Serialization_PersistsState_Struct()
        {
            PageInfo sourceEntry = new PageInfo("Page Name", "Arguments");

            sourceEntry.SetState <StructState>("MyKey", new StructState()
            {
                Text = "Text Value", Number = 42
            });

            byte[]   data     = SerializationHelper.SerializeToArray(sourceEntry);
            PageInfo newEntry = SerializationHelper.DeserializeFromArray <PageInfo>(data);

            var state = newEntry.GetState <StructState>("MyKey");

            Assert.Equal("Text Value", state.Text);
            Assert.Equal(42, state.Number);
        }