protected override sealed void OnInit(EventArgs e)
#pragma warning restore 0809
        {
            if (!_isWxeInfoInitialized)
            {
                _wxeInfo.Initialize(Context);
                _isWxeInfoInitialized = true;
            }

            if (_replacer == null)
            {
                var replacer = new ControlReplacer(new InternalControlMemberCaller());
                replacer.ID = ID + "_Parent";

                _permanentUniqueID = UniqueID.Insert(UniqueID.Length - ID.Length, replacer.ID + IdSeparator);

                IUserControlExecutor userControlExecutor = GetUserControlExecutor();

                WxeUserControl             control;
                IStateModificationStrategy stateModificationStrategy;
                if (!userControlExecutor.IsNull && !userControlExecutor.IsReturningPostBack)
                {
                    Assertion.IsTrue(userControlExecutor.UserControlID == _permanentUniqueID);
                    var currentUserControlStep = (WxeUserControlStep)userControlExecutor.Function.ExecutingStep;
                    control = (WxeUserControl)Page.LoadControl(currentUserControlStep.UserControl);

                    if (!currentUserControlStep.IsPostBack)
                    {
                        stateModificationStrategy = new StateClearingStrategy();
                    }
                    else
                    {
                        stateModificationStrategy = new StateLoadingStrategy();
                    }
                }
                else
                {
                    if (userControlExecutor.IsReturningPostBack)
                    {
                        control = (WxeUserControl)Page.LoadControl(userControlExecutor.BackedUpUserControl);
                        stateModificationStrategy = new StateReplacingStrategy(userControlExecutor.BackedUpUserControlState);
                    }
                    else
                    {
                        control = this;
                        stateModificationStrategy = new StateLoadingStrategy();
                    }
                }

                control.ID = ID;
                control._permanentUniqueID = _permanentUniqueID;
                replacer.ReplaceAndWrap(this, control, stateModificationStrategy);
            }
            else
            {
                CompleteInitialization();
            }
        }
Example #2
0
        protected ControlReplacer SetupControlReplacer(
            IInternalControlMemberCaller memberCaller, ReplaceableControlMock wrappedControl, IStateModificationStrategy stateModificationStrategy)
        {
            ControlReplacer replacer = new ControlReplacer(memberCaller)
            {
                ID = "TheReplacer"
            };

            wrappedControl.OnInitParameters = new Tuple <ControlReplacer, IStateModificationStrategy>  (replacer, stateModificationStrategy);
            return(replacer);
        }
Example #3
0
        public virtual void RemoveReplacer(ControlReplacer replacer)
        {
            var indexOf = controlReplacers.IndexOf(replacer);

            if (indexOf < 0)
            {
                return;
            }
            controlReplacers.RemoveAt(indexOf);
            replacer.InnerControlReplacementEnqueued -= ReplacerOnInnerControlReplacementEnqueued;
        }
Example #4
0
        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());
        }
Example #5
0
        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));
        }
Example #6
0
        public void GetWrappedControl()
        {
            ControlReplacer replacer = new ControlReplacer(MemberCallerMock)
            {
                ID = "TheReplacer"
            };
            Control control = new Control();

            Assert.That(replacer.WrappedControl, Is.Null);

            replacer.Controls.Add(control);

            Assert.That(replacer.WrappedControl, Is.SameAs(control));
        }
        public override void SetUp()
        {
            base.SetUp();

            _replacer = new ControlReplacer(MemberCallerMock);

            Pair         state     = new Pair(new Hashtable(), new object());
            LosFormatter formatter = new LosFormatter();
            StringWriter writer    = new StringWriter();

            formatter.Serialize(writer, state);

            _stateModificationStrategy = new StateReplacingStrategy(writer.ToString());
        }
Example #8
0
        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));
        }
Example #9
0
        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());
        }
        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();
        }
Example #11
0
        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 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);
        }
Example #13
0
 public virtual void RegisterReplacer(ControlReplacer replacer)
 {
     controlReplacers.Add(replacer);
     replacer.InnerControlReplacementEnqueued += ReplacerOnInnerControlReplacementEnqueued;
 }