private GridViewRowEventArgs SetupForGridView1RowDataBoundMethod(string typeCount) { const string TypeCount = "TypeCount"; var gridViewEventArg = new ShimGridViewRowEventArgs { RowGet = () => new ShimGridViewRow { RowTypeGet = () => DataControlRowType.DataRow } }.Instance; _linkButton = new ShimLinkButton().Instance; ShimControl.AllInstances.FindControlString = (_, __) => _linkButton; ShimWebControl.AllInstances.AttributesGet = _ => new ShimAttributeCollection { AddStringString = (key, value) => _attributes.Add($"{key}|{value}") }; ShimDataBinder.EvalObjectString = (_, expression) => { if (expression == TypeCount) { return(typeCount); } return(DummyString); }; return(gridViewEventArg); }
public void GridView1RowDataBound_Should_AddAtrributeInTheRow() { // Arrange var actualVisible = false; var actualAttributeKey = string.Empty; var actualAttibuteValue = string.Empty; ShimSPContext.CurrentGet = () => new ShimSPContext(); var linkButton = new ShimLinkButton() { CommandArgumentGet = () => DummyUserId.ToString() }; var webControlLinkButton = new ShimWebControl(linkButton) { AttributesGet = () => new ShimAttributeCollection() { AddStringString = (keyParam, valueParam) => { actualAttributeKey = keyParam; actualAttibuteValue = valueParam; } } }; var controlLinkButton = new ShimControl(linkButton) { VisibleSetBoolean = visible => actualVisible = visible }; var gridViewRow = new ShimGridViewRow() { RowTypeGet = () => DataControlRowType.DataRow, }; var controlGridViewRow = new ShimControl(gridViewRow) { FindControlString = controlName => linkButton }; var eventArgSend = new ShimGridViewRowEventArgs() { RowGet = () => gridViewRow }; _privateObject.SetField(HiddenUserIdFieldName, new HiddenField() { Value = DummyUserId.ToString() }); // Act _privateObject.Invoke(GridView1RowDataBoundMethodName, this, eventArgSend.Instance); // Assert this.ShouldSatisfyAllConditions( () => actualVisible.ShouldBeFalse(), () => actualAttributeKey.ShouldBe("onclick"), () => actualAttibuteValue.ShouldBe("javascript:return confirm('Are you sure you want to delete from your site?')")); }