Пример #1
0
        public void CleanTables_BulkInsertFRF_ExecutsCorrectly()
        {
            // Arrange
            var          destinationTable  = string.Empty;
            const string ExpectedTableNAme = "FRF";
            var          bulkInserted      = false;
            var          site    = new ShimSPSite();
            var          epmData = new ShimEPMData();

            ShimSqlBulkCopy.AllInstances.WriteToServerDataTable = (_, dataTable) =>
            {
                if (destinationTable == ExpectedTableNAme && dataTable.Rows.Count > 0 && !bulkInserted)
                {
                    bulkInserted = true;
                }
            };
            ShimSqlBulkCopy.AllInstances.DestinationTableNameSetString = (_, name) =>
            {
                destinationTable = name;
            };

            // Act
            DataScrubber.CleanTables(site, epmData, DummyGuid, ref ErrMsg);

            // Assert
            Assert.IsTrue(bulkInserted);
        }
 private void SetupVariables()
 {
     guid   = new Guid(GuidString);
     spList = new ShimSPList()
     {
         FieldsGet = () => new ShimSPFieldCollection(),
         ItemsGet  = () => new ShimSPListItemCollection()
     };
     spListItem = new ShimSPListItem()
     {
         IDGet       = () => DummyNumber,
         UniqueIdGet = () => guid
     };
     spListCollection = new ShimSPListCollection()
     {
         ItemGetString = _ => spList
     };
     spSite = new ShimSPSite()
     {
         IDGet = () => guid
     };
     spWeb = new ShimSPWeb()
     {
         ListsGet       = () => spListCollection,
         UrlGet         = () => DummyString,
         SiteGet        = () => spSite,
         CurrentUserGet = () => new ShimSPUser()
         {
             RegionalSettingsGet = () => null
         }
     };
 }
Пример #3
0
        public void CleanTables_Should_WipeTables()
        {
            // Arrange
            const string WipeReportListIds = "DELETE FROM ReportListIds";
            const string WipeRPTWeb        = "DELETE FROM RPTWeb";
            const string WipeRPTWebGroups  = "DELETE FROM RPTWEBGROUPS";
            var          commandsExecuted  = new List <string>();
            var          site = new ShimSPSite
            {
                IDGet = () => DummyGuid
            }.Instance;
            var epmData = new ShimEPMData().Instance;

            ShimDataTable.AllInstances.RowsGet = _ => new ShimDataRowCollection
            {
                AddObjectArray = parameters => new ShimDataRow().Instance,
                CountGet       = () => 0,
                GetEnumerator  = () => new List <DataRow>().GetEnumerator()
            };

            ShimSqlCommand.AllInstances.ExecuteNonQuery = instance =>
            {
                commandsExecuted.Add(instance.CommandText);
                return(1);
            };

            // Act
            DataScrubber.CleanTables(site, epmData, DummyGuid, ref ErrMsg);

            // Assert
            Assert.IsTrue(commandsExecuted.Contains(WipeReportListIds));
            Assert.IsTrue(commandsExecuted.Contains(WipeRPTWeb));
            Assert.IsTrue(commandsExecuted.Contains(WipeRPTWebGroups));
        }
Пример #4
0
        private void ShimSharePointContext()
        {
            ShimSPFieldCollectionMethods();
            ShimSPListMethods();
            ShimSPListCollectionMethods();
            ShimSPWebMethods();

            var site = new ShimSPSite
            {
                IDGet             = () => DummyGuid,
                RootWebGet        = () => _shimWeb.Instance,
                WebApplicationGet = () => new ShimSPWebApplication
                {
                    ApplicationPoolGet = () => new SPApplicationPool()
                }.Instance
            };

            _shimWeb.SiteGet         = () => site.Instance;
            ShimSPContext.CurrentGet = () => new ShimSPContext
            {
                WebGet  = () => _shimWeb.Instance,
                SiteGet = () => site.Instance
            }.Instance;

            ShimSPSite.ConstructorGuid          = (_, __) => { };
            ShimSPSite.AllInstances.OpenWebGuid = (_, __) => _shimWeb;
        }
 private void SetupVariables()
 {
     nonPublicInstance = BindingFlags.Instance | BindingFlags.NonPublic;
     sender            = new object();
     eventArgs         = EventArgs.Empty;
     now        = DateTime.Now;
     guid       = Guid.Parse(GuidString);
     dataReader = new ShimSqlDataReader()
     {
         Read             = () => true,
         Close            = () => { },
         IsDBNullInt32    = _ => false,
         GetInt32Int32    = _ => 1,
         GetStringInt32   = _ => DummyString,
         GetGuidInt32     = _ => guid,
         GetDateTimeInt32 = _ => now
     };
     spSite = new ShimSPSite()
     {
         WebApplicationGet = () => new ShimSPWebApplication(),
         IDGet             = () => guid
     };
     spWeb = new ShimSPWeb()
     {
         SiteGet = () => spSite,
         ServerRelativeUrlGet = () => DummyString,
         IDGet = () => guid,
         AllowUnsafeUpdatesSetBoolean = _ => { }
     };
 }
Пример #6
0
        private void InitializeSharePoint()
        {
            var shimSpWebApplication  = new ShimSPWebApplication();
            var shimSpPersistedObject = new ShimSPPersistedObject(shimSpWebApplication)
            {
                IdGet = () => SpWebApplicationId
            };

            var shimSpSite = new ShimSPSite()
            {
                IDGet             = () => SpSiteId,
                WebApplicationGet = () => shimSpWebApplication.Instance
            };

            var shimSpWeb = new ShimSPWeb()
            {
                IDGet  = () => SpWebId,
                UrlGet = () => WebUrl,
                ServerRelativeUrlGet = () => ServerRelativeUrl,
                CurrentUserGet       = () => new ShimSPUser()
                {
                    IDGet = () => UserId
                }
            };

            var shimSpContext = new ShimSPContext()
            {
                SiteGet = () => shimSpSite,
                WebGet  = () => shimSpWeb
            };

            ShimSPContext.CurrentGet = () => shimSpContext;
            _spContextCurrent        = shimSpContext.Instance;
        }
Пример #7
0
 private void SetupShims()
 {
     _web = new ShimSPWeb
     {
         UserIsSiteAdminGet = () => true,
         ListsGet           = () => new ShimSPListCollection
         {
             TryGetListString = _ => new ShimSPList(),
             ItemGetString    = _ => new ShimSPList()
         }.Bind(new SPList[]
         {
             new ShimSPList
             {
                 TitleGet = () => DummyString
             }
         }),
         SiteGet = () => _site
     };
     _site = new ShimSPSite
     {
         UrlGet            = () => DummyUrl,
         RootWebGet        = () => _web,
         WebApplicationGet = () => new ShimSPWebApplication()
     };
     ShimSPSite.ConstructorString       = (_, __) => { };
     ShimSPSite.AllInstances.OpenWeb    = _ => _web;
     ShimSPContext.CurrentGet           = () => new ShimSPContext();
     ShimSPContext.AllInstances.WebGet  = _ => _web;
     ShimSPContext.AllInstances.SiteGet = _ => _site;
     ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = action => action();
     ShimSqlConnection.ConstructorString  = (_, __) => { };
     ShimSqlConnection.AllInstances.Open  = _ => { };
     ShimSqlConnection.AllInstances.Close = _ => { };
     ShimPath.GetDirectoryNameString      = _ => string.Empty;
 }
Пример #8
0
        public void ShouldReturnCachedList()
        {
            var          siteMock       = new ShimSPSite();
            const string TestUrl        = "test/url";
            var          listMock       = new ShimSPList();
            var          listCollection = new ShimSPListCollection {
                ItemGetGuid = _ => listMock
            };

            var webMock = new ShimSPWeb {
                ServerRelativeUrlGet = () => TestUrl, ListsGet = () => listCollection
            };

            siteMock.OpenWebGuid = guid => webMock;

            using (var cache = SaveDataJobExecuteCache.InitializeCache(siteMock))
            {
                var properties = new ShimSPItemEventProperties {
                    RelativeWebUrlGet = () => TestUrl
                };
                var webById = cache.GetWeb(Guid.Empty.ToString());
                var list    = SaveDataJobExecuteCache.GetList(properties);

                webById.ShouldNotBeNull();
                list.ShouldBe(listMock);
            }
        }
        public void SetRPTSettings_OnException_ExecuteCorrectly()
        {
            // Arrange
            var stringBuilder = new StringBuilder();
            var epm           = new ShimEPMData().Instance;
            var spSite        = new ShimSPSite
            {
                RootWebGet = () => new ShimSPWeb
                {
                    RegionalSettingsGet = () =>
                    {
                        throw new Exception();
                    }
                }
            }.Instance;

            ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = code => code();
            ShimEPMData.AllInstances.UpdateRPTSettingsStringInt32StringOut      = UpdateRPTSettings;
            privateObject.SetFieldOrProperty(StringBuilderFieldName, new StringBuilder());

            // Act
            privateObject.Invoke(SetRPTSettingsMethodName, epm, spSite);
            var errors = privateObject.GetFieldOrProperty(StringBuilderFieldName) as StringBuilder;

            // Assert
            this.ShouldSatisfyAllConditions(
                () => errors.ShouldNotBeNull(),
                () => errors.ToString().ShouldNotBeNullOrEmpty(),
                () => errors.ToString().ShouldContain("Error Updating RPTSettings"));
        }
        private void SetupShims()
        {
            _web = new ShimSPWeb
            {
                IDGet    = () => Guid.NewGuid(),
                SiteGet  = () => _site,
                ListsGet = () => new ShimSPListCollection
                {
                    TryGetListString = _ => new ShimSPList
                    {
                        FieldsGet = () => new ShimSPFieldCollection
                        {
                            GetFieldByInternalNameString = __ => new ShimSPField
                            {
                                TitleGet = () => DummyString
                            }
                        },
                        GetItemsSPQuery = __ => new ShimSPListItemCollection
                        {
                            CountGet     = () => DummyInt,
                            ItemGetInt32 = index => new ShimSPListItem
                            {
                                ItemGetString = name => DummyInt,
                                IDGet         = () => DummyInt
                            }
                        }
                    }
                }.Bind(new SPList[]
                {
                    new ShimSPList()
                }),
                CurrentUserGet = () => new ShimSPUser
                {
                    RegionalSettingsGet = () => new ShimSPRegionalSettings
                    {
                        LocaleIdGet = () => LocaleId,
                        TimeZoneGet = () => new ShimSPTimeZone
                        {
                            UTCToLocalTimeDateTime = date => date
                        }
                    }
                }
            };

            _site = new ShimSPSite
            {
                RootWebGet = () => _web,
                UrlGet     = () => DummyString
            };

            ShimSPSite.ConstructorString        = (_, __) => { };
            ShimSPSite.ConstructorGuid          = (_, __) => { };
            ShimSPSite.AllInstances.Dispose     = _ => { };
            ShimSPSite.AllInstances.OpenWebGuid = (_, __) => _web;

            ShimSPWeb.AllInstances.Dispose = _ => { };
        }
Пример #11
0
        private void SetupShims()
        {
            _web = new ShimSPWeb
            {
                IDGet   = () => Guid.NewGuid(),
                SiteGet = () => _site,
                ServerRelativeUrlGet = () => RelativeUrl,
                UrlGet   = () => DummyUrl,
                ListsGet = () => new ShimSPListCollection
                {
                    ItemGetGuid = guid => new ShimSPList
                    {
                        TitleGet         = () => DummyString,
                        GetItemByIdInt32 = id => new ShimSPListItem
                        {
                            ItemGetString = item => DummyString
                        }
                    }
                },
                CurrentUserGet = () => new ShimSPUser
                {
                    LoginNameGet = () => DummyString
                },
                DoesUserHavePermissionsStringSPBasePermissions = (_, __) => true,
                AllPropertiesGet = () => new Hashtable {
                    [CompLevel] = DummyString
                }
            };

            _site = new ShimSPSite
            {
                IDGet       = () => Guid.NewGuid(),
                UrlGet      = () => DummyUrl,
                HostNameGet = () => DummyString,
                AllWebsGet  = () => new ShimSPWebCollection
                {
                    ItemGetString = item => _web
                }
            };

            ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = action => action();

            ShimSPContext.CurrentGet = () => new ShimSPContext
            {
                SiteGet = () => _site,
                WebGet  = () => _web
            };

            ShimSPSite.AllInstances.Dispose = _ => { };
            ShimSPWeb.AllInstances.Dispose  = _ => { };

            ShimSPSite.ConstructorGuid          = (instance, guid) => instance = _site.Instance;
            ShimSPSite.AllInstances.OpenWebGuid = (_, __) => _web;

            ShimUnsecuredLayoutsPageBase.AllInstances.WebGet  = _ => _web;
            ShimUnsecuredLayoutsPageBase.AllInstances.SiteGet = _ => _site;
        }
Пример #12
0
        public override void ConstructorArgRun(ShimSPSite site, string constructorArg)
        {
            FarmSpSiteSubstitute.Sites[constructorArg].Shim = site;

            foreach (var action in FarmSpSiteSubstitute.Sites[constructorArg].Actions)
            {
                action.Invoke(site);
            }
        }
        public void SetUp()
        {
            _shimsContext = ShimsContext.Create();

            _testEntity    = new ListCommands();
            _privateObject = new PrivateObject(_testEntity);
            _privateType   = new PrivateType(typeof(ListCommands));

            ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = codeToRun =>
            {
                codeToRun();
            };

            _spSiteConstructor = new ShimSPSite();

            ShimSPSite.ConstructorGuid   = (sender, guid) => new ShimSPSite();
            ShimSPSite.ConstructorString = (sender, guid) => new ShimSPSite();

            ShimSPSite.AllInstances.OpenWebGuid = (sender, guid) => new ShimSPWeb();
            ShimSPContext.CurrentGet            = () => new ShimSPContext()
            {
                WebGet = () => new ShimSPWeb()
                {
                    UrlGet = () => string.Empty
                }
            };

            ShimCoreFunctions.getLockConfigSettingSPWebStringBoolean = (web, setting, isRelative) => setting;
            ShimCoreFunctions.getConfigSettingSPWebString            = (web, setting) =>
            {
                switch (setting)
                {
                case "EPMLiveDisablePublishing":
                case "EPMLiveDisablePlanners":
                    return("true");

                case "EPKLists":
                    return(DummyTitle);

                case "EPKDummyTitle_nonactivexs":
                case "EPKDummyTitle_menus":
                    return(string.Empty);

                case "EPKMenus":
                    return("EPKMenus");

                case "epknonactivexs":
                    return("epknonactivexs");

                default:
                    break;
                }

                return(null);
            };
        }
Пример #14
0
        public void ShouldReloadListItemOnRequest()
        {
            var       webId  = Guid.NewGuid();
            var       listId = Guid.NewGuid();
            const int ItemId = 1;

            var siteMock = new ShimSPSite();

            var listItemMock = new ShimSPListItem {
                IDGet = () => ItemId
            };
            var listItemMockNew = new ShimSPListItem {
                IDGet = () => ItemId
            };
            var listItemCollection = new ShimSPListItemCollection {
                GetEnumerator = () => Enumerable.Repeat <SPListItem>(listItemMock, 1).GetEnumerator()
            };
            var listMock = new ShimSPList
            {
                GetItemsSPQuery = _ => listItemCollection, IDGet = () => listId, GetItemByIdInt32 = _ => listItemMockNew
            };
            var listCollection = new ShimSPListCollection {
                ItemGetGuid = _ => listMock
            };

            const string TestUrl = "test/url";
            var          webMock = new ShimSPWeb {
                ServerRelativeUrlGet = () => TestUrl, ListsGet = () => listCollection
            };

            siteMock.OpenWebGuid = guid => webMock;

            using (var cache = SaveDataJobExecuteCache.InitializeCache(siteMock))
            {
                string preloadErrors;
                var    preloadHasErrors =
                    cache.PreloadListItems(new[]
                {
                    new SaveDataJobExecuteCache.ListItemInfo
                    {
                        WebId      = webId.ToString(),
                        ListId     = listId.ToString(),
                        ListItemId = ItemId.ToString()
                    }
                }, out preloadErrors);

                preloadHasErrors.ShouldBe(false);
                preloadErrors.ShouldBe(string.Empty);

                var listItem = SaveDataJobExecuteCache.Cache.GetListItem(TestUrl, listId, ItemId, refresh: true);
                listItem.ShouldBe(listItemMockNew);

                listItem = SaveDataJobExecuteCache.Cache.GetListItem(TestUrl, listId, ItemId);
                listItem.ShouldBe(listItemMockNew);
            }
        }
Пример #15
0
        public void ShouldCallCallbackIfNoCache()
        {
            var siteMock = new ShimSPSite();
            var site     = SaveDataJobExecuteCache.GetSiteFromCache(Guid.Empty, false, () => siteMock);

            site.ShouldBe(siteMock);

            site = SaveDataJobExecuteCache.GetSiteFromCache(Guid.Empty, true, () => siteMock);
            site.ShouldBe(siteMock);
        }
Пример #16
0
        public void ShouldReturnListItemFromPropertiesIfListIsNotInCache()
        {
            var       webId   = Guid.NewGuid();
            var       listId  = Guid.NewGuid();
            var       list2Id = Guid.NewGuid();
            const int ItemId  = 1;

            var siteMock = new ShimSPSite();

            var listMock = new ShimSPList
            {
                GetItemsSPQuery = _ => new ShimSPListItemCollection {
                    GetEnumerator = () => Enumerable.Empty <SPListItem>().GetEnumerator()
                },
                IDGet = () => listId
            };
            var listCollection = new ShimSPListCollection {
                ItemGetGuid = _ => listMock
            };

            const string TestUrl = "test/url";
            var          webMock = new ShimSPWeb {
                ServerRelativeUrlGet = () => TestUrl, ListsGet = () => listCollection
            };

            siteMock.OpenWebGuid = guid => webMock;

            using (var cache = SaveDataJobExecuteCache.InitializeCache(siteMock))
            {
                string preloadErrors;
                var    preloadHasErrors = cache.PreloadListItems(new[]
                {
                    new SaveDataJobExecuteCache.ListItemInfo
                    {
                        WebId      = webId.ToString(),
                        ListId     = listId.ToString(),
                        ListItemId = ItemId.ToString()
                    }
                }, out preloadErrors);

                preloadHasErrors.ShouldBe(false);
                preloadErrors.ShouldBe(string.Empty);

                var listItemMock = new ShimSPListItem();
                var properties   = new ShimSPItemEventProperties
                {
                    RelativeWebUrlGet = () => TestUrl,
                    ListIdGet         = () => list2Id,
                    ListItemIdGet     = () => ItemId,
                    ListItemGet       = () => listItemMock
                };
                var listItem = SaveDataJobExecuteCache.GetListItem(properties);
                listItem.ShouldBe(listItemMock);
            }
        }
Пример #17
0
        public void ShouldDisposeSiteIfNotCached()
        {
            var siteMock = new ShimSPSite();
            var disposed = false;

            siteMock.Dispose = () => disposed = true;

            SaveDataJobExecuteCache.DisposeSite(siteMock);

            disposed.ShouldBe(true);
        }
Пример #18
0
        public void Execute_InitiJobFalse_NoActionTaken()
        {
            // Arrange
            var executedCommands = new List <string>();
            var site             = new ShimSPSite
            {
                WebApplicationGet = () => new ShimSPWebApplication(),
                RootWebGet        = () => new ShimSPWeb
                {
                    RegionalSettingsGet = () => new ShimSPRegionalSettings
                    {
                        WorkDayStartHourGet = () => 1,
                        WorkDayEndHourGet   = () => 2,
                        WorkDaysGet         = () => 2
                    }
                },
                AllWebsGet = () =>
                {
                    var list = new List <SPWeb>
                    {
                        new ShimSPWeb()
                    }.AsEnumerable();
                    return(new ShimSPWebCollection().Bind(list));
                }
            };
            var web = new ShimSPWeb();

            ShimBaseJob.AllInstances.initJobSPSite = (_, spSite) => false;
            ShimTimerFix.AllInstances.processWebSPWebStringSingleRef           = ProcessWeb;
            ShimTimerFix.AllInstances.processResPlanSPWebStringGuidInt32String =
                (_, spWeb, lists, id, hours, days) => { };
            ShimSPWebCollection.AllInstances.CountGet = _ => 1;

            ShimSqlCommand.AllInstances.ExecuteNonQuery = command =>
            {
                executedCommands.Add(command.CommandText);
                return(1);
            };
            ShimSqlCommand.AllInstances.ExecuteReader = command =>
            {
                executedCommands.Add(command.CommandText);
                return(new ShimSqlDataReader
                {
                    Read = () => true,
                    GetGuidInt32 = index => Guid.NewGuid()
                });
            };

            // Act
            timerFix.execute(site, web, string.Empty);

            // Assert
            executedCommands.ShouldBeEmpty();
        }
Пример #19
0
 private void SetupShims()
 {
     _web = new ShimSPWeb
     {
         ListsGet = () => new ShimSPListCollection
         {
             ItemGetString = _ => new ShimSPList(),
             ItemGetGuid   = _ => new ShimSPList()
         },
         SiteGet        = () => _site,
         CurrentUserGet = () => new ShimSPUser
         {
             LoginNameGet = () => DummyString,
             NameGet      = () => DummyString
         }
     };
     _site = new ShimSPSite
     {
         RootWebGet        = () => _web,
         WebApplicationGet = () => new ShimSPWebApplication()
     };
     ShimSPList.AllInstances.GetItemByIdInt32 = (_, __) => new ShimSPListItem();
     ShimPage.AllInstances.RequestGet         = _ => new ShimHttpRequest();
     ShimPage.AllInstances.ResponseGet        = _ => new ShimHttpResponse();
     ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = action => action();
     ShimSPContext.CurrentGet                  = () => new ShimSPContext();
     ShimSPContext.AllInstances.SiteGet        = _ => _site;
     ShimSPContext.AllInstances.WebGet         = _ => _web;
     ShimSPSite.ConstructorGuid                = (_, __) => { };
     ShimSPSite.AllInstances.IDGet             = _ => Guid.NewGuid();
     ShimSPSite.AllInstances.OpenWebGuid       = (_, __) => _web;
     ShimSPListItem.AllInstances.SystemUpdate  = _ => _systemUpdate = true;
     ShimSPListItem.AllInstances.Update        = _ => _listItemUpdated = true;
     ShimSPWeb.AllInstances.IDGet              = _ => Guid.NewGuid();
     ShimCoreFunctions.getConnectionStringGuid = _ => DummyString;
     ShimSqlConnection.ConstructorString       = (_, __) => { };
     ShimSqlConnection.AllInstances.Open       = _ => { };
     ShimSqlConnection.AllInstances.Close      = _ => { };
     ShimSharedFunctions.canUserImpersonateStringStringSPWebStringOut =
         (string _1, string _2, SPWeb _3, out string resName) =>
     {
         resName = DummyString;
         return(true);
     };
     ShimSharedFunctions.getProjectCenterListSPList = _ => new ShimSPList();
     ShimSqlCommand.ConstructorStringSqlConnection  = (instance, command, _2) =>
     {
         instance.CommandText = command;
     };
     ShimSqlCommand.AllInstances.ExecuteReader = _ => new ShimSqlDataReader();
     ShimSqlDataReader.AllInstances.Close      = _ => { };
 }
Пример #20
0
        public void ShouldInitializeCacheAndClearOnDispose()
        {
            var siteMock = new ShimSPSite();

            using (var cache = SaveDataJobExecuteCache.InitializeCache(siteMock))
            {
                cache.ShouldSatisfyAllConditions(
                    () => cache.ShouldNotBeNull(),
                    () => cache.ShouldBe(SaveDataJobExecuteCache.Cache),
                    () => cache.Site.ShouldBe(siteMock));
            }

            SaveDataJobExecuteCache.Cache.ShouldBeNull();
        }
Пример #21
0
        public void ShouldNotDisposeCachedSite()
        {
            var siteMock = new ShimSPSite();
            var disposed = false;

            siteMock.Dispose = () => disposed = true;

            using (SaveDataJobExecuteCache.InitializeCache(siteMock))
            {
                SaveDataJobExecuteCache.DisposeSite(siteMock);
            }

            disposed.ShouldBe(false);
        }
Пример #22
0
        public void ShouldReturnOriginalSiteForNonElevated()
        {
            var siteMock = new ShimSPSite();

            using (SaveDataJobExecuteCache.InitializeCache(siteMock))
            {
                var site = SaveDataJobExecuteCache.GetSiteFromCache(Guid.Empty, false, () =>
                {
                    Assert.Fail();
                    return(null);
                });

                site.ShouldBe(siteMock);
            }
        }
Пример #23
0
        public void ShouldCallCallbackIfSiteOfDifferentId()
        {
            using (SaveDataJobExecuteCache.InitializeCache(new ShimSPSite()))
            {
                var siteId   = Guid.NewGuid();
                var siteMock = new ShimSPSite {
                    IDGet = () => siteId
                };
                var site = SaveDataJobExecuteCache.GetSiteFromCache(siteId, false, () => siteMock);
                site.ShouldBe(siteMock);

                site = SaveDataJobExecuteCache.GetSiteFromCache(siteId, true, () => siteMock);
                site.ShouldBe(siteMock);
            }
        }
Пример #24
0
        public void ShouldReturnListFromPropertiesIfItIsNotFoundInCache()
        {
            var          siteMock = new ShimSPSite();
            const string TestUrl  = "test/url";
            var          listMock = new ShimSPList();

            using (SaveDataJobExecuteCache.InitializeCache(siteMock))
            {
                var properties = new ShimSPItemEventProperties {
                    RelativeWebUrlGet = () => TestUrl, ListGet = () => listMock
                };
                var list = SaveDataJobExecuteCache.GetList(properties);

                list.ShouldBe(listMock);
            }
        }
        private static ShimSPItemEventProperties CreateProperties()
        {
            var webApplication = new SPWebApplication()
            {
                Id = Guid.Empty
            };
            var shimSPSite = new ShimSPSite()
            {
                WebApplicationGet = () => webApplication
            };

            return(new ShimSPItemEventProperties()
            {
                SiteGet = () => shimSPSite
            });
        }
Пример #26
0
        public void Run(Microsoft.SharePoint.SPSite site, TConstructorArg constructorArg)
        {
            var shimSite = new ShimSPSite(site);

            if (Args != null)
            {
                FarmSpSiteSubstitute.Sites[Args].Shim = shimSite;
                foreach (var action in FarmSpSiteSubstitute.Sites[Args].Actions)
                {
                    action.Invoke(shimSite);
                }
            }
            else
            {
                ConstructorArgRun(shimSite, constructorArg);
            }
        }
        private ShimSPSite ShimSPSiteMethods()
        {
            var site = new ShimSPSite
            {
                IDGet             = () => DummyGuid,
                RootWebGet        = () => _shimWeb.Instance,
                WebApplicationGet = () => new ShimSPWebApplication
                {
                    ApplicationPoolGet               = () => new SPApplicationPool(),
                    CurrentUserIgnoreThrottle        = () => false,
                    MaxItemsPerThrottledOperationGet = () => 5
                }.Instance
            };

            _shimWeb.SiteGet = () => site.Instance;
            return(site);
        }
Пример #28
0
 private void SetupVariables()
 {
     validations       = 0;
     publicInstance    = BindingFlags.Instance | BindingFlags.Public;
     nonPublicInstance = BindingFlags.Instance | BindingFlags.NonPublic;
     guid  = Guid.Parse(SampleGuidString1);
     spWeb = new ShimSPWeb()
     {
         IDGet    = () => guid,
         ListsGet = () => spListCollection,
         AllowUnsafeUpdatesSetBoolean = _ => { },
         AllUsersGet        = () => new ShimSPUserCollection(),
         SiteGroupsGet      = () => new ShimSPGroupCollection(),
         RoleDefinitionsGet = () => new ShimSPRoleDefinitionCollection()
     };
     spSite = new ShimSPSite()
     {
         IDGet = () => guid
     };
     spListCollection = new ShimSPListCollection()
     {
         ItemGetGuid = _ => spList
     };
     spList = new ShimSPList()
     {
         IDGet            = () => guid,
         FieldsGet        = () => spFieldCollection,
         GetItemByIdInt32 = _ => spListItem
     };
     spListItemCollection = new ShimSPListItemCollection();
     spListItem           = new ShimSPListItem()
     {
         IDGet         = () => DummyInt,
         TitleGet      = () => DummyString,
         ItemGetString = _ => DummyString
     };
     spFieldCollection = new ShimSPFieldCollection();
     spField           = new ShimSPField();
     spUser            = new ShimSPUser();
     dataReader        = new ShimSqlDataReader()
     {
         Close = () => { }
     };
 }
Пример #29
0
        public void Execute_OnGeneralException_ShoudlThrowException()
        {
            // Arrange
            var executedCommands = new List <string>();
            var site             = new ShimSPSite
            {
                WebApplicationGet = () =>
                {
                    throw new Exception();
                }
            };
            var web = new ShimSPWeb();

            // Act
            Action action = () => timerFix.execute(site, web, string.Empty);

            // Assert
            action.ShouldThrow <Exception>();
        }
Пример #30
0
        public void IsFirstAttempt_ExecuteScalarReturns1_ReturnsFalse()
        {
            // Arrange
            var site = new ShimSPSite
            {
                IDGet             = () => DummyGuid,
                WebApplicationGet = () => new ShimSPWebApplication()
            };
            var web = new ShimSPWeb
            {
                IDGet = () => DummyGuid
            };

            ShimSqlCommand.AllInstances.ExecuteScalar = _ => 1;

            // Act
            var result = WorkspaceData.IsFirstAttempt(site, web, DummyString, DummyString);

            // Assert
            Assert.IsFalse(result);
        }
        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);
            }
        }