Exemplo n.º 1
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);
        }
Exemplo n.º 2
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"));
        }
Exemplo n.º 3
0
        public void SetState_RaisesStateChangedEvent()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

            List<string> stateChangedKeys = new List<string>();
            navigationEntry.StateChanged += (sender, e) => { stateChangedKeys.Add(e.StateKey); };

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

            Assert.Equal(new[] { "MyKey" }, stateChangedKeys);
        }
Exemplo n.º 4
0
        public void SetState_Exception_KeyIsEmpty()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

            var e = Assert.Throws<ArgumentException>(() => navigationEntry.SetState<string>("", "Test"));

            Assert.Equal("The argument cannot be null or an empty string.\r\nParameter name: key", e.Message);
            Assert.Equal("key", e.ParamName);
        }
Exemplo n.º 5
0
        public void TryGetState_Exception_IncorrectType()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");
            navigationEntry.SetState<string>("MyKey", "Test State");

            int result;
            var e = Assert.Throws<InvalidCastException>(() => navigationEntry.TryGetState<int>("MyKey", out result));

            Assert.Equal("Specified cast is not valid.", e.Message);
        }
Exemplo n.º 6
0
        public void SetState_SameStateKeyOverwritesPreviousValue()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

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

            string result;
            bool success = navigationEntry.TryGetState<string>("MyKey", out result);

            Assert.Equal(true, success);
            Assert.Equal("State B", result);
        }
Exemplo n.º 7
0
        public void TryGetSetState_Class_StoresNullState()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

            navigationEntry.SetState<ClassState>("MyKey", null);
            ClassState result;
            bool success = navigationEntry.TryGetState<ClassState>("MyKey", out result);

            Assert.Equal(true, success);
            Assert.Equal(null, result);
        }
Exemplo n.º 8
0
        public void TryGetSetState_Struct_StoresState()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

            navigationEntry.SetState<StructState>("MyKey", new StructState() { Text = "Text Value", Number = 42 });
            StructState result;
            bool success = navigationEntry.TryGetState<StructState>("MyKey", out result);

            Assert.Equal(true, success);
            Assert.Equal("Text Value", result.Text);
            Assert.Equal(42, result.Number);
        }
Exemplo n.º 9
0
        public void TryGetSetState_String_StoresState()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

            navigationEntry.SetState<string>("MyKey", "Test State");
            string result;
            bool success = navigationEntry.TryGetState<string>("MyKey", out result);

            Assert.Equal(true, success);
            Assert.Equal("Test State", result);
        }
Exemplo n.º 10
0
        public void TryGetSetState_Int_StoresState()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

            navigationEntry.SetState<int>("MyKey", 42);
            int result;
            bool success = navigationEntry.TryGetState<int>("MyKey", out result);

            Assert.Equal(true, success);
            Assert.Equal(42, result);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
0
 /// <summary>
 /// Saves any state to be recreated in a future session.
 /// </summary>
 /// <param name="pageInfo">Object to store page state.</param>
 public void SaveState(PageInfo pageInfo)
 {
     if (SelectedItem != null)
         pageInfo.SetState<string>("SelectedItem", SelectedItem.UniqueId);
     else
         pageInfo.SetState<string>("SelectedItem", null);
 }