public void Control_RestoreChildControlState_EnsureBeforeLoadAllState() { Page_Init_Load_Add_Ensure_SaveAllState("Parent Value", "Child Value", null); PageStatePersister pageStatePersisterBackup = Page.GetPageStatePersister(); TearDownPage(); SetUpPage(); Page.RegisterViewStateHandler(); Page.SetRequestValueCollection(new NameValueCollection()); NamingContainerInvoker.InitRecursive(); Page.SetPageStatePersister(pageStatePersisterBackup); Page.LoadAllState(); NamingContainerInvoker.LoadRecursive(); _lazyContainer.RealControls.Add(_parent); Page.SaveAllState(); pageStatePersisterBackup = Page.GetPageStatePersister(); Assert.That(pageStatePersisterBackup.ControlState is IDictionary, Is.True); IDictionary controlStates = (IDictionary)pageStatePersisterBackup.ControlState; Assert.That(controlStates.Count, Is.EqualTo(1)); Assert.That(controlStates.Contains(_lazyContainer.UniqueID), Is.True); TearDownPage(); SetUpPage(); Page.SetRequestValueCollection(new NameValueCollection()); _lazyContainer.Ensure(); }
private void Page_Init_Load_Add_Ensure_SaveAllState(string parentControlState, string childControlState, string childSecondControlState) { Page.RegisterViewStateHandler(); NamingContainerInvoker.InitRecursive(); NamingContainerInvoker.LoadRecursive(); _lazyContainer.RealControls.Add(_parent); _lazyContainer.Ensure(); _parent.ValueInControlState = parentControlState; _child.ValueInControlState = childControlState; _childSecond.ValueInControlState = childSecondControlState; Page.SaveAllState(); }
public void Control_Init_Load_Add_SaveViewState() { NamingContainerInvoker.InitRecursive(); NamingContainerInvoker.LoadRecursive(); _lazyContainer.RealControls.Add(_parent); _parent.ValueInViewState = "Parent Value"; _child.ValueInViewState = "Child Value"; object viewState = _lazyContainerInvoker.SaveViewState(); Assert.That(viewState, Is.Not.Null); Assert.That(viewState is Pair, Is.True); Pair values = (Pair)viewState; Assert.That(values.Second, Is.Null); }
public void Control_BackUpChildControlState() { Page_Init_Load_Add_Ensure_SaveAllState("Parent Value", "Child Value", null); PageStatePersister pageStatePersisterBackup = Page.GetPageStatePersister(); Dictionary <string, object> expectedControlStates = new Dictionary <string, object> (); expectedControlStates[_parent.UniqueID] = _parentInvoker.SaveControlStateInternal(); expectedControlStates[_child.UniqueID] = _childInvoker.SaveControlStateInternal(); TearDownPage(); SetUpPage(); Page.SetRequestValueCollection(new NameValueCollection()); NamingContainerInvoker.InitRecursive(); Page.SetPageStatePersister(pageStatePersisterBackup); Page.LoadAllState(); NamingContainerInvoker.LoadRecursive(); _lazyContainer.RealControls.Add(_parent); object controlState = _lazyContainerInvoker.SaveControlState(); Assert.That(controlState is Triplet, Is.True); Triplet values = (Triplet)controlState; Assert.IsInstanceOf((typeof(HybridDictionary)), values.Third); IDictionary actualControlStates = (IDictionary)values.Third; Assert.That(actualControlStates.Count, Is.EqualTo(2)); foreach (string expectedKey in expectedControlStates.Keys) { Pair expectedValues = (Pair)expectedControlStates[expectedKey]; object actualControlState = actualControlStates[expectedKey]; Assert.That(actualControlState is Pair, Is.True); Pair actualValues = (Pair)actualControlState; Assert.AreEqual(expectedValues.First, actualValues.First, expectedKey); Assert.AreEqual(expectedValues.Second, actualValues.Second, expectedKey); } }
public void Control_Init_Load_Ensure_Add() { StringCollection expectedEvents = new StringCollection(); expectedEvents.Add(FormatInitEvent(_lazyContainer)); expectedEvents.Add(FormatLoadEvent(_lazyContainer)); NamingContainerInvoker.InitRecursive(); NamingContainerInvoker.LoadRecursive(); _lazyContainer.RealControls.Add(_parent); CollectionAssert.AreEqual(expectedEvents, _actualEvents); expectedEvents.Add(FormatInitEvent(_child)); expectedEvents.Add(FormatInitEvent(_childSecond)); expectedEvents.Add(FormatInitEvent(_parent)); expectedEvents.Add(FormatLoadEvent(_parent)); expectedEvents.Add(FormatLoadEvent(_child)); expectedEvents.Add(FormatLoadEvent(_childSecond)); _lazyContainer.Ensure(); CollectionAssert.AreEqual(expectedEvents, _actualEvents); }