Esempio n. 1
0
        public void AddGroup_FirstTimeNotNull_ReturnsString()
        {
            // Arrange
            var expected  = $"{DummyString} {DummyString} 9";
            var spGroup   = new ShimSPGroup();
            var methodHit = 0;

            ShimSPGroupCollection.AllInstances.ItemGetString = (_, __) =>
            {
                methodHit = methodHit + 1;
                if (methodHit == 10)
                {
                    throw new Exception();
                }
                return(spGroup);
            };
            ShimSPGroupCollection.AllInstances.AddStringSPMemberSPUserString = (_, _1, _2, _3, _4) => { };

            // Act
            var actual = (string)privateObject.Invoke(
                AddGroupMethodName,
                BindingFlags.Static | BindingFlags.Public,
                new object[] { spWeb.Instance, DummyString, DummyString, null, spUser.Instance, DummyString });

            // Assert
            actual.ShouldBe(expected);
        }
        public void Button2Click_SetSiteAdminFalse_SetUserSiteAdminTrueRedirect()
        {
            // Arrange
            var actualUrl          = string.Empty;
            var actualRedirectFlag = SPRedirectFlags.Default;
            var actualRedirect     = false;
            var actualUserAdded    = false;
            var actualSiteAdmin    = false;

            var siteGroup = new ShimSPGroup()
            {
                NameGet = () => DummyGroupName2,
                CanCurrentUserEditMembershipGet = () => true
            };

            ShimSPContext.CurrentGet = () => new ShimSPContext()
            {
                WebGet = () => new ShimSPWeb()
                {
                    AllUsersGet = () => new ShimSPUserCollection()
                    {
                        ItemGetString = itemName => new ShimSPUser()
                        {
                            GroupsGet = () => new ShimSPGroupCollection().Bind(
                                new SPGroup[]
                            {
                                new ShimSPGroup()
                                {
                                    NameGet = () => DummyGroupName
                                }
                            }),
                            IsSiteAdminSetBoolean = siteAdmin => actualSiteAdmin = siteAdmin
                        }
                    },
                    GroupsGet = () => new ShimSPGroupCollection()
                    {
                        ItemGetString = itemName => new ShimSPGroup()
                        {
                            NameGet       = () => DummyGroupName,
                            AddUserSPUser = user => actualUserAdded = true
                        }
                    },
                    SiteGroupsGet = () => new ShimSPGroupCollection()
                    {
                        ItemGetString = itemName => siteGroup
                    }.Bind(
                        new SPGroup[]
                    {
                        siteGroup
                    }),
                    UserIsSiteAdminGet = () => true
                },
                SiteGet = () => new ShimSPSite()
                {
                    UrlGet = () => DummyUrl
                }
            };

            ShimPage.AllInstances.RequestGet = sender => new ShimHttpRequest()
            {
                ItemGetString = itemName => $"{DummyGroupName}"
            };


            _privateObject.SetField(HiddenUsernameFieldName, new HiddenField()
            {
                Value = DummyUserName
            });

            ShimSPUtility.RedirectStringSPRedirectFlagsHttpContext = (url, flags, context) =>
            {
                actualUrl          = url;
                actualRedirectFlag = flags;
                actualRedirect     = true;
                return(true);
            };

            // Act
            _privateObject.Invoke(Button2ClickMethodName, this, EventArgs.Empty);

            // Assert
            this.ShouldSatisfyAllConditions(
                () => actualUserAdded.ShouldBeTrue(),
                () => actualSiteAdmin.ShouldBeFalse(),
                () => actualUrl.ShouldBe("epmlive/sitepermissions.aspx?"),
                () => actualRedirectFlag.ShouldBe(SPRedirectFlags.RelativeToLayoutsPage),
                () => actualRedirect.ShouldBeTrue());
        }