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 LoadControlState() { var testPageHolder = new TestPageHolder(false, RequestMode.PostBack); IStateModificationStrategy stateModificationStrategy = new StateClearingStrategy(); var replacer = new ControlReplacer(MemberCallerMock); replacer.StateModificationStrategy = stateModificationStrategy; replacer.Controls.Add(testPageHolder.NamingContainer); MemberCallerMock.Expect(mock => mock.ClearChildControlState(replacer)); MockRepository.ReplayAll(); stateModificationStrategy.LoadControlState(replacer, MemberCallerMock); MockRepository.VerifyAll(); }