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()); }
public void ReplaceAndWrap <T> (T controlToReplace, T controlToWrap, IStateModificationStrategy stateModificationStrategy) where T : Control, IReplaceableControl { ArgumentUtility.CheckNotNull("controlToReplace", controlToReplace); ArgumentUtility.CheckNotNull("controlToWrap", controlToWrap); ArgumentUtility.CheckNotNull("stateModificationStrategy", stateModificationStrategy); if (_memberCaller.GetControlState(controlToReplace) != ControlState.ChildrenInitialized) { throw new InvalidOperationException("Controls can only be wrapped during OnInit phase."); } if (controlToReplace.IsInitialized) { throw new InvalidOperationException("Controls can only be wrapped before they are initialized."); } controlToWrap.Replacer = this; _stateModificationStrategy = stateModificationStrategy; Control parent = controlToReplace.Parent; int index = parent.Controls.IndexOf(controlToReplace); //Mark parent collection as modifiable string errorMessage = _memberCaller.SetCollectionReadOnly(parent.Controls, null); parent.Controls.RemoveAt(index); parent.Controls.AddAt(index, this); //Mark parent collection as readonly _memberCaller.SetCollectionReadOnly(parent.Controls, errorMessage); _memberCaller.InitRecursive(this, parent); if (!parent.Page.IsPostBack) { _hasLoaded = true; Controls.Add(controlToWrap); } else { _controlToWrap = controlToWrap; } }
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); }
protected ControlReplacer SetupControlReplacerForIntegrationTest( ReplaceableControlMock wrappedControl, IStateModificationStrategy stateModificationStrategy) { return(SetupControlReplacer(new InternalControlMemberCaller(), wrappedControl, stateModificationStrategy)); }