public void GridViewRowCommand_CommandDel_RemoveUserRedirect() { // Arrange var actualUrl = string.Empty; var actualRedirectFlag = SPRedirectFlags.Default; var actualRedirect = false; var actualUserRemoved = false; ShimSPContext.CurrentGet = () => new ShimSPContext() { WebGet = () => new ShimSPWeb() { AllUsersGet = () => new ShimSPUserCollection() { ItemGetString = itemName => new ShimSPUser() }, GroupsGet = () => new ShimSPGroupCollection().Bind( new SPGroup[] { new ShimSPGroup() { CanCurrentUserEditMembershipGet = () => true, RemoveUserSPUser = user => actualUserRemoved = true } }), UrlGet = () => DummyUrl } }; ShimSPUtility.RedirectStringSPRedirectFlagsHttpContext = (url, flags, context) => { actualUrl = url; actualRedirectFlag = flags; actualRedirect = true; return(true); }; var eventArgsSend = new ShimGridViewCommandEventArgs() { }; var commandEventArgs = new ShimCommandEventArgs(eventArgsSend) { CommandNameGet = () => "Del", CommandArgumentGet = () => DummyString }; // Act _privateObject.Invoke(GridView1RowCommandMethodName, this, eventArgsSend.Instance); // Assert this.ShouldSatisfyAllConditions( () => actualUrl.ShouldBe("epmlive/sitepermissions.aspx?"), () => actualRedirectFlag.ShouldBe(SPRedirectFlags.RelativeToLayoutsPage), () => actualRedirect.ShouldBeTrue()); }
public void GridView1RowCommand_OnValidCall_ConfirmResult() { // Arrange const string DelCommand = "Del"; var gridViewEventArg = new ShimGridViewCommandEventArgs().Instance; var sqlCommand = string.Empty; ShimCommandEventArgs.AllInstances.CommandNameGet = _ => DelCommand; Shimtimesheetadmin.AllInstances.loadTypesSqlConnection = (_, __) => _loadTypesCalled = true; ShimSqlCommand.ConstructorString = (instance, command) => instance.CommandText = command; ShimSqlCommand.AllInstances.ExecuteNonQuery = instance => { sqlCommand = instance.CommandText; return(DummyIntOne); }; // Act _privateObject.Invoke(GridView1RowCommandMethod, this, gridViewEventArg); // Assert this.ShouldSatisfyAllConditions( () => sqlCommand.ShouldBe("delete from TSTYPE where site_uid = @siteid and tstype_id=@tstype_id"), () => _loadTypesCalled.ShouldBeTrue()); }
public void GridViewRowCommand_CommandEdiIsAdminFalseCanEditFalse_RemoveUserRedirect() { // Arrange ShimSPContext.CurrentGet = () => new ShimSPContext() { WebGet = () => new ShimSPWeb() { AllUsersGet = () => new ShimSPUserCollection() { ItemGetString = itemName => new ShimSPUser() { IsSiteAdminGet = () => false, NameGet = () => DummyUserNameName, EmailGet = () => DummyUserEmail, GroupsGet = () => new ShimSPGroupCollection().Bind( new SPGroup[] { new ShimSPGroup() { NameGet = () => DummyGroupName } }) } }, UserIsSiteAdminGet = () => true, GroupsGet = () => new ShimSPGroupCollection().Bind( new SPGroup[] { new ShimSPGroup() { NameGet = () => DummyGroupName }, new ShimSPGroup() { NameGet = () => DummyGroupName2 } }), SiteGroupsGet = () => new ShimSPGroupCollection() { ItemGetString = itemName => new ShimSPGroup() { CanCurrentUserEditMembershipGet = () => false } } } }; _privateObject.SetField(HiddenUsernameFieldName, new HiddenField()); var eventArgsSend = new ShimGridViewCommandEventArgs() { }; var commandEventArgs = new ShimCommandEventArgs(eventArgsSend) { CommandNameGet = () => "Edi", CommandArgumentGet = () => DummyUserName }; // Act _privateObject.Invoke(GridView1RowCommandMethodName, this, eventArgsSend.Instance); // Assert LoadFields(); this.ShouldSatisfyAllConditions( () => _labelName.Text.ShouldBe(DummyUserNameName), () => _labelUserName.Text.ShouldBe(DummyUserName), () => _labelEmail.Text.ShouldBe(DummyUserEmail), () => ((LiteralControl)_panelGroups.Controls[0]).Text.ShouldBe("<input type=\"checkbox\" name=\"Groups\" value=\"@\"> Site Collection Administrator"), () => ((LiteralControl)_panelGroups.Controls[1]).Text.ShouldBe("<br>"), () => ((LiteralControl)_panelGroups.Controls[2]).Text.ShouldBe($"<input type=\"checkbox\" name=\"Groups\" checked value=\"{DummyGroupName}\" disabled>{DummyGroupName}"), () => ((LiteralControl)_panelGroups.Controls[3]).Text.ShouldBe("<br>"), () => ((LiteralControl)_panelGroups.Controls[4]).Text.ShouldBe($"<input type=\"checkbox\" name=\"Groups\" value=\"{DummyGroupName2}\" disabled>{DummyGroupName2}"), () => ((LiteralControl)_panelGroups.Controls[5]).Text.ShouldBe("<br>")); }