public void WrapControlWithParentContainer_ThrowsIfNotInOnInit() { ControlReplacer replacer = new ControlReplacer(MemberCallerMock) { ID = "TheReplacer" }; var control = new ReplaceableControlMock(); MemberCallerMock.Stub(stub => stub.GetControlState(control)).Return(ControlState.Initialized); replacer.ReplaceAndWrap(control, control, new StateLoadingStrategy()); }
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 WrapControlWithParentContainer_ThrowsIfAlreadyInitialized() { ControlReplacer replacer = new ControlReplacer(MemberCallerMock) { ID = "TheReplacer" }; var control = new ReplaceableControlMock(); MemberCallerMock.Stub(stub => stub.GetControlState(control)).Return(ControlState.ChildrenInitialized); control.EnsureLazyInitializationContainer(); MockRepository.ReplayAll(); replacer.ReplaceAndWrap(control, control, new StateLoadingStrategy()); }