public void LoadViewStateRecursive_ReplaceViewState() { object originalViewState = CreateViewState(); var testPageHolderWithChangedState = new TestPageHolder(false, RequestMode.Get); var replacerWithChangedState = SetupControlReplacerForIntegrationTest(testPageHolderWithChangedState.NamingContainer, new StateLoadingStrategy()); testPageHolderWithChangedState.PageInvoker.InitRecursive(); testPageHolderWithChangedState.Parent.ValueInViewState = "NewParentValue"; testPageHolderWithChangedState.NamingContainer.ValueInViewState = "NewNamingContainerValue"; string backedUpState = replacerWithChangedState.SaveAllState(); var testPageHolderWithoutState = new TestPageHolder(false, RequestMode.PostBack); var replacer = SetupControlReplacerForIntegrationTest(testPageHolderWithoutState.NamingContainer, new StateReplacingStrategy(backedUpState)); testPageHolderWithoutState.Page.SetRequestValueCollection(new NameValueCollection()); testPageHolderWithoutState.PageInvoker.InitRecursive(); Assert.That(testPageHolderWithoutState.OtherControl.ValueInViewState, Is.Null); Assert.That(testPageHolderWithoutState.NamingContainer.ValueInViewState, Is.Null); Assert.That(testPageHolderWithoutState.Parent.ValueInViewState, Is.Null); testPageHolderWithoutState.PageInvoker.LoadViewStateRecursive(originalViewState); Assert.That(testPageHolderWithoutState.OtherControl.ValueInViewState, Is.EqualTo("OtherValue")); Assert.That(testPageHolderWithoutState.NamingContainer.ValueInViewState, Is.Null); Assert.That(testPageHolderWithoutState.Parent.ValueInViewState, Is.Null); replacer.LoadPostData(null, null); Assert.That(testPageHolderWithoutState.OtherControl.ValueInViewState, Is.EqualTo("OtherValue")); Assert.That(testPageHolderWithoutState.NamingContainer.ValueInViewState, Is.EqualTo("NewNamingContainerValue")); Assert.That(testPageHolderWithoutState.Parent.ValueInViewState, Is.EqualTo("NewParentValue")); }
public void LoadControlStateRecursive_RegularPostBack() { object controlState = CreateControlState(); var testPageHolderWithoutState = new TestPageHolder(false, RequestMode.PostBack); var replacer = SetupControlReplacerForIntegrationTest(testPageHolderWithoutState.NamingContainer, new StateLoadingStrategy()); testPageHolderWithoutState.PageInvoker.InitRecursive(); testPageHolderWithoutState.Page.SetPageStatePersister( new HiddenFieldPageStatePersister(testPageHolderWithoutState.Page) { ControlState = controlState }); Assert.That(testPageHolderWithoutState.OtherControl.ValueInControlState, Is.Null); Assert.That(testPageHolderWithoutState.NamingContainer.ValueInControlState, Is.Null); Assert.That(testPageHolderWithoutState.Parent.ValueInControlState, Is.Null); testPageHolderWithoutState.Page.LoadAllState(); Assert.That(testPageHolderWithoutState.OtherControl.ValueInControlState, Is.EqualTo("OtherValue")); Assert.That(testPageHolderWithoutState.NamingContainer.ValueInControlState, Is.Null); Assert.That(testPageHolderWithoutState.Parent.ValueInControlState, Is.Null); replacer.LoadPostData(null, null); Assert.That(testPageHolderWithoutState.OtherControl.ValueInControlState, Is.EqualTo("OtherValue")); Assert.That(testPageHolderWithoutState.NamingContainer.ValueInControlState, Is.EqualTo("NamingContainerValue")); Assert.That(testPageHolderWithoutState.Parent.ValueInControlState, Is.EqualTo("ParentValue")); }
public void LoadControlStateRecursive_ClearControlState_InitializedAfterLoadControlState() { object originalControlState = CreateControlState(); var testPageHolderWithoutState = new TestPageHolder(false, RequestMode.PostBack); var replacer = SetupControlReplacerForIntegrationTest(testPageHolderWithoutState.NamingContainer, new StateClearingStrategy()); testPageHolderWithoutState.Page.Controls.Remove(testPageHolderWithoutState.NamingContainer); testPageHolderWithoutState.PageInvoker.InitRecursive(); testPageHolderWithoutState.Page.SetPageStatePersister( new HiddenFieldPageStatePersister(testPageHolderWithoutState.Page) { ControlState = originalControlState }); testPageHolderWithoutState.Page.LoadAllState(); testPageHolderWithoutState.Page.Controls.Add(testPageHolderWithoutState.NamingContainer); Assert.That(testPageHolderWithoutState.OtherControl.ValueInControlState, Is.EqualTo("OtherValue")); Assert.That(testPageHolderWithoutState.NamingContainer.ValueInControlState, Is.Null); Assert.That(testPageHolderWithoutState.Parent.ValueInControlState, Is.Null); replacer.LoadPostData(null, null); Assert.That(testPageHolderWithoutState.OtherControl.ValueInControlState, Is.EqualTo("OtherValue")); Assert.That(testPageHolderWithoutState.NamingContainer.ValueInControlState, Is.Null); Assert.That(testPageHolderWithoutState.Parent.ValueInControlState, Is.Null); }
protected object CreateViewState(TestPageHolder testPageHolder) { ControlReplacer replacer = SetupControlReplacerForIntegrationTest(testPageHolder.NamingContainer, new StateLoadingStrategy()); testPageHolder.PageInvoker.InitRecursive(); if (testPageHolder.Page.IsPostBack) { new ControlInvoker(testPageHolder.NamingContainer).LoadControlState(null); } Assertion.IsTrue(replacer.Controls.Count == 1); return(testPageHolder.PageInvoker.SaveViewStateRecursive(ViewStateMode.Enabled)); }
public void LoadControlState() { var testPageHolder = new TestPageHolder(false, RequestMode.PostBack); _replacer.StateModificationStrategy = _stateModificationStrategy; _replacer.Controls.Add(testPageHolder.NamingContainer); MemberCallerMock.Expect(mock => mock.SetChildControlState(Arg <ControlReplacer> .Is.Same(_replacer), Arg <Hashtable> .Is.NotNull)); MockRepository.ReplayAll(); _stateModificationStrategy.LoadControlState(_replacer, MemberCallerMock); MockRepository.VerifyAll(); }
public void WrapControlWithParentContainer_ReplacesControl_WithPostRequest() { var testPageHolder = new TestPageHolder(true, RequestMode.PostBack); ControlReplacer replacer = new ControlReplacer(MemberCallerMock) { ID = "TheReplacer" }; var controlToReplace = new ReplaceableControlMock(); var controlToWrap = new ReplaceableControlMock(); MemberCallerMock.Stub(stub => stub.GetControlState(controlToReplace)).Return(ControlState.ChildrenInitialized); using (MockRepository.Ordered()) { MemberCallerMock.Expect(mock => mock.SetCollectionReadOnly(testPageHolder.Page.Controls, null)).Return("error"); MemberCallerMock.Expect(mock => mock.SetCollectionReadOnly(testPageHolder.Page.Controls, "error")).Return(null).WhenCalled( invocation => Assert.That( testPageHolder.Page.Controls, Is.EqualTo(new Control[] { testPageHolder.OtherNamingContainer, testPageHolder.NamingContainer, replacer }))); MemberCallerMock.Expect(mock => mock.InitRecursive(replacer, testPageHolder.Page)); } Assert.That(replacer.Controls, Is.Empty); MockRepository.ReplayAll(); testPageHolder.Page.Controls.Add(controlToReplace); replacer.ReplaceAndWrap(controlToReplace, controlToWrap, new StateLoadingStrategy()); MockRepository.VerifyAll(); Assert.That( testPageHolder.Page.Controls, Is.EqualTo(new Control[] { testPageHolder.OtherNamingContainer, testPageHolder.NamingContainer, replacer })); Assert.That(replacer.Controls, Is.Empty); MockRepository.BackToRecordAll(); MemberCallerMock.Stub(stub => stub.SetControlState(controlToWrap, ControlState.Constructed)); MockRepository.ReplayAll(); replacer.LoadPostData(null, null); MockRepository.VerifyAll(); Assert.That( testPageHolder.Page.Controls, Is.EqualTo(new Control[] { testPageHolder.OtherNamingContainer, testPageHolder.NamingContainer, replacer })); Assert.That(replacer.Controls, Is.EqualTo(new[] { controlToWrap })); Assert.That(controlToReplace.Replacer, Is.Null); Assert.That(controlToWrap.Replacer, Is.SameAs(replacer)); Assert.That(replacer.WrappedControl, Is.SameAs(controlToWrap)); }
public void LoadViewState() { var testPageHolder = new TestPageHolder(false, RequestMode.PostBack); IStateModificationStrategy stateModificationStrategy = new StateLoadingStrategy(); var replacer = new ControlReplacer(MemberCallerMock); replacer.StateModificationStrategy = stateModificationStrategy; replacer.Controls.Add(testPageHolder.NamingContainer); MockRepository.ReplayAll(); stateModificationStrategy.LoadViewState(replacer, MemberCallerMock); MockRepository.VerifyAll(); }
public void SaveAllState_ControlState() { var testPageHolder = new TestPageHolder(true, RequestMode.Get); var replacer = SetupControlReplacerForIntegrationTest(testPageHolder.NamingContainer, new StateLoadingStrategy()); testPageHolder.PageInvoker.InitRecursive(); var formatter = new LosFormatter(); var state = (Pair)formatter.Deserialize(replacer.SaveAllState()); IDictionary controlState = (IDictionary)state.First; Assert.That(controlState[replacer.UniqueID], Is.Null); Assert.That(controlState[testPageHolder.NamingContainer.UniqueID], new PairConstraint(new Pair("NamingContainerValue", null))); Assert.That(controlState[testPageHolder.Parent.UniqueID], new PairConstraint(new Pair("ParentValue", null))); }
public void SaveControlStateRecursive() { var testPageHolder = new TestPageHolder(true, RequestMode.Get); var replacer = SetupControlReplacerForIntegrationTest(testPageHolder.NamingContainer, new StateLoadingStrategy()); testPageHolder.PageInvoker.InitRecursive(); testPageHolder.Page.SaveAllState(); var controlStateObject = testPageHolder.Page.GetPageStatePersister().ControlState; Assert.That(controlStateObject, Is.InstanceOf(typeof(IDictionary))); IDictionary controlState = (IDictionary)controlStateObject; Assert.That(controlState[replacer.UniqueID], new PairConstraint(new Pair("value", null))); Assert.That(controlState[testPageHolder.NamingContainer.UniqueID], new PairConstraint(new Pair("NamingContainerValue", null))); Assert.That(controlState[testPageHolder.Parent.UniqueID], new PairConstraint(new Pair("ParentValue", null))); }
public void SaveViewStateRecursive() { var testPageHolder = new TestPageHolder(true, RequestMode.Get); SetupControlReplacerForIntegrationTest(testPageHolder.NamingContainer, new StateLoadingStrategy()); testPageHolder.PageInvoker.InitRecursive(); object viewState = testPageHolder.PageInvoker.SaveViewStateRecursive(ViewStateMode.Enabled); Assert.That(viewState, Is.InstanceOf(typeof(Pair))); var replacerViewState = (Pair)((IList)((Pair)viewState).Second)[3]; Assert.That(replacerViewState.First, Is.EqualTo("value")); var namingContainerViewState = (Pair)((IList)(replacerViewState).Second)[1]; Assert.That(namingContainerViewState.First, Is.EqualTo("NamingContainerValue")); var parentViewState = (Pair)((IList)(namingContainerViewState).Second)[1]; Assert.That(parentViewState.First, Is.EqualTo("ParentValue")); }
public void SaveAllState_ViewState() { var testPageHolder = new TestPageHolder(true, RequestMode.Get); ControlReplacer replacer = SetupControlReplacerForIntegrationTest(testPageHolder.NamingContainer, new StateLoadingStrategy()); testPageHolder.PageInvoker.InitRecursive(); var formatter = new LosFormatter(); var state = (Pair)formatter.Deserialize(replacer.SaveAllState()); Pair replacerViewState = (Pair)state.Second; Assert.That(replacerViewState.First, Is.EqualTo("value")); var namingContainerViewState = (Pair)((IList)(replacerViewState).Second)[1]; Assert.That(namingContainerViewState.First, Is.EqualTo("NamingContainerValue")); var parentViewState = (Pair)((IList)(namingContainerViewState).Second)[1]; Assert.That(parentViewState.First, Is.EqualTo("ParentValue")); }
public void LoadViewStateRecursive_RegularPostBack_InitializedAfterLoadViewState() { object viewState = CreateViewState(); var testPageHolderWithoutState = new TestPageHolder(false, RequestMode.PostBack); var replacer = SetupControlReplacerForIntegrationTest(testPageHolderWithoutState.NamingContainer, new StateLoadingStrategy()); testPageHolderWithoutState.Page.Controls.Remove(testPageHolderWithoutState.NamingContainer); testPageHolderWithoutState.PageInvoker.InitRecursive(); testPageHolderWithoutState.PageInvoker.LoadViewStateRecursive(viewState); testPageHolderWithoutState.Page.Controls.Add(testPageHolderWithoutState.NamingContainer); Assert.That(testPageHolderWithoutState.OtherControl.ValueInViewState, Is.EqualTo("OtherValue")); Assert.That(testPageHolderWithoutState.NamingContainer.ValueInViewState, Is.Null); Assert.That(testPageHolderWithoutState.Parent.ValueInViewState, Is.Null); replacer.LoadPostData(null, null); Assert.That(testPageHolderWithoutState.OtherControl.ValueInViewState, Is.EqualTo("OtherValue")); Assert.That(testPageHolderWithoutState.NamingContainer.ValueInViewState, Is.EqualTo("NamingContainerValue")); Assert.That(testPageHolderWithoutState.Parent.ValueInViewState, Is.EqualTo("ParentValue")); }
public void LoadViewState() { var testPageHolder = new TestPageHolder(false, RequestMode.PostBack); IStateModificationStrategy stateModificationStrategy = new StateClearingStrategy(); var replacer = new ControlReplacer(MemberCallerMock); replacer.StateModificationStrategy = stateModificationStrategy; testPageHolder.Page.Controls.Add(replacer); ControlInvoker replacerInvoker = new ControlInvoker(replacer); replacerInvoker.LoadViewStateRecursive(new Pair(null, new ArrayList { 0, new Pair("ChildState", null) })); stateModificationStrategy.LoadViewState(replacer, MemberCallerMock); var newControl = new ControlMock(); replacer.Controls.Add(newControl); Assert.That(newControl.ValueInViewState, Is.Null); }