public void GetSiteNameReturnsWebTitle()
        {
            // Arrange.
            string title = "Test Site";
            using (new SharePointEmulationScope())
            {
                ShimSPWeb web = new ShimSPWeb() {TitleGet = () => title};
                ShimSPSite.ConstructorString = (instance, url) =>
                    {
                        ShimSPSite moledSite = new ShimSPSite(instance);
                        moledSite.Dispose = () => { };
                        moledSite.OpenWeb = () => web;
                    };
                WebSiteManager manager = new WebSiteManager("http://test");

                // Act.
                string returnedTitle = manager.GetSiteName();

                // Assert.
                Assert.AreEqual(title, returnedTitle);
            }
        }
        public void TestGetUsersForSiteReturnsLoginNamesOfAllDefinedUsers()
        {
            // Arrange.
            using (new SharePointEmulationScope())
            {
                ShimSPUser user1 = new ShimSPUser() {LoginNameGet = () => @"DOMAIN\user1"};
                ShimSPUser user2 = new ShimSPUser() {LoginNameGet = () => @"EXTERNAL\some.user"};
                ShimSPUser user3 = new ShimSPUser() {LoginNameGet = () => "*****@*****.**"};
                ShimSPUser user4 = new ShimSPUser() {LoginNameGet = () => "mike.test"};
                List<ShimSPUser> masterUsers = new List<ShimSPUser>() { user1, user2, user3, user4 };

                ShimSPWeb web = new ShimSPWeb();
                ShimSPUserCollection coll = new ShimSPUserCollection();
                coll.CountGet = () => masterUsers.Count;
                coll.GetByIDInt32 = (id) => masterUsers.ElementAt(id);
                coll.ItemGetInt32 = (id) => masterUsers.ElementAt(id);
                coll.ItemAtIndexInt32 = (id) => masterUsers.ElementAt(id);
                web.UsersGet = () => coll;
                ShimSPSite.ConstructorString = (instance, url) =>
                    {
                        ShimSPSite site = new ShimSPSite(instance);
                        site.Dispose = () => { };
                        site.OpenWeb = () => web;
                    };
                WebSiteManager manager = new WebSiteManager("http://test");

                // Act.
                IEnumerable<string> users = manager.GetUsersForSite();

                // Assert.
                Assert.IsTrue(users.Contains(user1.Instance.LoginName));
                Assert.IsTrue(users.Contains(user2.Instance.LoginName));
                Assert.IsTrue(users.Contains(user3.Instance.LoginName));
                Assert.IsTrue(users.Contains(user4.Instance.LoginName));
            }
        }
        public void TestShowingMoreRealisticCollectionExpectations()
        {
            // Arrange.
            int count = 4;
            using (new SharePointEmulationScope())
            {
                ShimSPWeb web = new ShimSPWeb();
                ShimSPWebCollection webCollection = new ShimSPWebCollection();
                webCollection.CountGet = () => count;
                web.WebsGet = () => webCollection;
                ShimSPSite.ConstructorString = (instance, url) =>
                    {
                        ShimSPSite site = new ShimSPSite(instance);
                        site.Dispose = () => { };
                        site.OpenWeb = () => web;
                    };
                WebSiteManager manager = new WebSiteManager("http://test");

                // Act.
                int resultCount = manager.GetNumberOfSubSites();

                // Assert.
                Assert.AreEqual(count, resultCount);
            }
        }
        public void TestWhenNoSubwebsDefinedShouldReturnZeroSubSites()
        {
            // Arrange.
            using (new SharePointEmulationScope())
            {
                ShimSPWeb web = new ShimSPWeb();
                web.WebsGet = () => new Microsoft.SharePoint.Fakes.ShimSPWebCollection() {CountGet = () => 0};
                ShimSPSite.ConstructorString = (instance, url) =>
                    {
                        ShimSPSite site = new ShimSPSite(instance);
                        site.Dispose = () => { };
                        site.OpenWeb = () => web;
                    };
                WebSiteManager manager = new WebSiteManager("http://test");

                // Act.
                int number = manager.GetNumberOfSubSites();

                // Assert.
                Assert.AreEqual(0, number);
            }
        }