public void ProcessField_Always_ReturnExpectedValueForDateTime()
        {
            // Arrange
            SPWeb spWeb = new ShimSPWeb
            {
                LocaleGet = () => new CultureInfo("en-US")
            };
            SPListItem listItem = new ShimSPListItem
            {
                ItemGetGuid = guidValue => "2018-12-05 00:00:00"
            };
            SPField field = new ShimSPField
            {
                TypeGet      = () => SPFieldType.DateTime,
                SchemaXmlGet = () => "format=\"DATEONLY\""
            };

            // Act
            var result = _privateObject.Invoke(
                "ProcessField",
                spWeb,
                listItem,
                field) as string;

            // Assert
            this.ShouldSatisfyAllConditions(
                () => result.ShouldNotBeNull(),
                () => result.ShouldBe("12/5/2018"));
        }
Ejemplo n.º 2
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;
 }
        public void GetExtId_WhenListItemValueIsInvalid_ConfirmResult()
        {
            // Arrange
            var web = new ShimSPWeb
            {
                ListsGet = () => new ShimSPListCollection
                {
                    TryGetListString = _ => new ShimSPList
                    {
                        GetItemsSPQuery = query => new ShimSPListItemCollection
                        {
                            CountGet     = () => 1,
                            ItemGetInt32 = index => new ShimSPListItem
                            {
                                ItemGetString = item => DummyString
                            }
                        }
                    }
                }
            };

            // Act
            var result = ExtensionMethods.GetExtId(new ShimSPUser().Instance, web);

            // Assert
            result.ShouldBe(-3);
        }
        public void ProcessField_Always_ReturnExpectedValueForNumber()
        {
            // Arrange
            SPWeb spWeb = new ShimSPWeb
            {
                LocaleGet = () => new CultureInfo("en-US")
            };
            SPListItem listItem = new ShimSPListItem
            {
                ItemGetGuid = guidValue => "1"
            };
            SPField field = new ShimSPFieldNumber
            {
                ShowAsPercentageGet = () => true
            };

            new ShimSPField(field)
            {
                TypeGet = () => SPFieldType.Number
            };

            // Act
            var result = _privateObject.Invoke(
                "ProcessField",
                spWeb,
                listItem,
                field) as string;

            // Assert
            this.ShouldSatisfyAllConditions(
                () => result.ShouldNotBeNull(),
                () => result.ShouldBe("100%"));
        }
Ejemplo n.º 5
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);
            }
        }
        private void InitializeSharePoint()
        {
            var shimSpWeb = new ShimSPWeb()
            {
                ServerRelativeUrlGet = () => ServerRelativeUrl
            };

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

            ShimSPContext.CurrentGet                         = () => shimSpContext;
            ShimSPContext.AllInstances.SiteGet               = context => new ShimSPSite();
            ShimSPSite.AllInstances.OpenWebGuid              = (site, guid) => new ShimSPWeb();
            ShimSPWeb.AllInstances.RegionalSettingsGet       = web => new ShimSPRegionalSettings();
            ShimSPWeb.AllInstances.ListsGet                  = web => new ShimSPListCollection();
            ShimSPListCollection.AllInstances.ItemGetGuid    = (collection, guid) => new ShimSPList();
            ShimSPList.AllInstances.FieldsGet                = list => new ShimSPFieldCollection();
            ShimSPFieldCollection.AllInstances.ItemGetGuid   = (collection, s) => new ShimSPField();
            ShimSPFieldCollection.AllInstances.ItemGetString = (collection, s) => new ShimSPField();
            ShimSPFieldCollection.AllInstances.GetFieldByInternalNameString = (collection, s) => new ShimSPField();
            ShimSPField.AllInstances.IdGet    = field => Guid.Empty;
            ShimSPField.AllInstances.TitleGet = field => string.Empty;
            ShimSPBaseCollection.AllInstances.GetEnumerator                 = collection => Enumerable.Empty <SPField>().GetEnumerator();
            ShimSPRegionalSettings.AllInstances.IsRightToLeftGet            = settings => true;
            ShimGenericQueryControl.AllInstances.WebGet                     = control => new ShimSPWeb();
            ShimGenericEntityPickerPropertyBag.AllInstances.LookupListIDGet = bag => Guid.Empty;
            ShimCoreFunctions.getConfigSettingSPWebString                   = (web, s) => s;
        }
Ejemplo n.º 7
0
        public void Constructor_ListWith1Item_FillPropertiesFromList()
        {
            // Arrange
            var spWeb = new ShimSPWeb()
            {
                SiteGet = () => new ShimSPSite()
                {
                    IDGet = () => DummySiteGuid
                }
            };

            ShimReportData.ConstructorGuid = (sender, guid) =>
            {
                var reportData = new ShimReportData(sender);
            };

            // Act
            _testObject = new RefreshLists(spWeb, DummyItemName);

            // Assert
            _privateObject = new PrivateObject(_testObject);
            var arrayListNames          = (string[])_privateObject.GetField(ArrayListNamesField);
            var arrayListTableNames     = (ArrayList)_privateObject.GetField(ArrayListTableNamesField);
            var dsLists                 = (DataSet)_privateObject.GetField(DsListsField);
            var dsMyWorkLists           = (DataSet)_privateObject.GetField(DsMyWorkListsField);
            var arrayListDefaultColumns = (ArrayList)_privateObject.GetField(ArrayListDefaultColumnsField);

            this.ShouldSatisfyAllConditions(
                () => arrayListNames[0].ShouldBe(DummyItemName),
                () => arrayListTableNames.ShouldNotBeNull(),
                () => dsLists.ShouldNotBeNull(),
                () => dsMyWorkLists.ShouldNotBeNull(),
                () => arrayListDefaultColumns.Count.ShouldBe(5));
        }
Ejemplo n.º 8
0
        private void InitRefreshLists()
        {
            var spWeb = new ShimSPWeb()
            {
                SiteGet = () => new ShimSPSite()
                {
                    IDGet = () => DummySiteGuid
                }
            };

            ShimReportData.ConstructorGuid = (sender, guid) =>
            {
                var reportData = new ShimReportData(sender)
                {
                    GetListMappings = () =>
                    {
                        var dataTable = new DataTable();
                        dataTable.Columns.Add(ListNameField);

                        var row = dataTable.NewRow();
                        row[ListNameField] = DummyItemName;
                        dataTable.Rows.Add(row);

                        return(dataTable);
                    }
                };
            };
            _testObject    = new RefreshLists(spWeb, string.Empty);
            _privateObject = new PrivateObject(_testObject);
        }
        private void SetupProcessSecurityGroupsShims()
        {
            var groupList                 = new List <SPGroup>();
            var shimSpGroupCollection     = new ShimSPGroupCollection();
            var shimSpBaseGroupCollection = new ShimSPBaseCollection(shimSpGroupCollection.Instance)
            {
                GetEnumerator = () => groupList.GetEnumerator()
            };

            var userList             = new List <SPUser>();
            var shimSpUserCollection = new ShimSPUserCollection()
            {
                GetByIDInt32 = userId => new ShimSPUser()
                {
                    IDGet     = () => userId,
                    GroupsGet = () => shimSpGroupCollection.Instance
                }
            };
            var shimSpBaseUserCollection = new ShimSPBaseCollection(shimSpUserCollection.Instance)
            {
                GetEnumerator = () => userList.GetEnumerator()
            };

            var shimRootWeb = new ShimSPWeb(_spShims.SiteShim.Instance.RootWeb)
            {
                SiteGroupsGet = () => shimSpGroupCollection.Instance,
                SiteUsersGet  = () => shimSpUserCollection.Instance
            };

            ShimSqlBulkCopy.AllInstances.WriteToServerDataTable = (_1, _2) => { };
        }
        public void GetReportingConnection_OnException_ReturnsEmpty()
        {
            // Arrange
            var spWeb = new ShimSPWeb
            {
                SiteGet = () => new ShimSPSite()
            }.Instance;

            ShimCollectJob.AllInstances.getReportingConnectionSPWeb = null;
            ShimBaseJob.AllInstances.CreateConnection = _ => new ShimSqlConnection
            {
                Open = () => { },
            };
            ShimSqlCommand.AllInstances.ExecuteReader = _ =>
            {
                throw new Exception();
            };
            privateObject.SetFieldOrProperty(StringBuilderFieldName, new StringBuilder());

            // Act
            var result = privateObject.Invoke(GetReportingConnectionMethodName, spWeb) as string;

            // Assert
            result.ShouldSatisfyAllConditions(
                () => result.ShouldBeNullOrEmpty());
        }
        public void GetReportingConnection_TrustedConnection_ReturnsExpectedValue()
        {
            // Arrange
            const string ExpectedValue = "Data Source=dummyString;Initial Catalog=dummyString;Trusted_Connection=True";
            var          spWeb         = new ShimSPWeb
            {
                SiteGet = () => new ShimSPSite()
            }.Instance;

            ShimCollectJob.AllInstances.getReportingConnectionSPWeb = null;
            ShimBaseJob.AllInstances.CreateConnection = _ => new ShimSqlConnection
            {
                Open = () => { },
            };
            ShimSqlCommand.AllInstances.ExecuteReader = _ => new ShimSqlDataReader
            {
                Read           = () => true,
                GetStringInt32 = i => DummyString,
                IsDBNullInt32  = i => true,
            };

            // Act
            var result = privateObject.Invoke(GetReportingConnectionMethodName, spWeb) as string;

            // Assert
            result.ShouldSatisfyAllConditions(
                () => result.ShouldNotBeNullOrEmpty(),
                () => result.ShouldBe(ExpectedValue));
        }
Ejemplo n.º 12
0
        private static void ShimSpSiteObject()
        {
            var shimRootWeb = new ShimSPWeb();

            shimRootWeb.TitleGet = () => RootWebTitle;

            var webList = new List <SPWeb>()
            {
                new ShimSPWeb()
                {
                    TitleGet = () => WebTitle01
                }.Instance
            };
            var shimAllWebs = new ShimSPWebCollection()
            {
                CountGet = () => webList.Count
            };
            var shimAllWebsBase = new ShimSPBaseCollection(shimAllWebs.Instance)
            {
                GetEnumerator = () => webList.GetEnumerator()
            };

            ShimSPSite.AllInstances.RootWebGet = _ => shimRootWeb.Instance;
            ShimSPSite.AllInstances.AllWebsGet = _ => shimAllWebs.Instance;
            ShimSPSite.AllInstances.UrlGet     = _ => SiteUrl;
        }
Ejemplo n.º 13
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;
        }
Ejemplo n.º 14
0
        public void GetListItemCount_OnException_ReturnsExpectedValue()
        {
            // Arrange
            var spWeb = new ShimSPWeb
            {
                ListsGet = () => null
            }.Instance;
            var field = new ShimSPField
            {
                GetCustomPropertyString = GetItem(new Hashtable
                {
                    ["AggType"]   = null,
                    ["AggColumn"] = null,
                    ["ListQuery"] = DummyString
                })
            }.Instance;

            // Act
            var result = privateObject.Invoke(getListItemCountMethodName, spWeb, field, DummyString) as double?;

            // Assert
            result.ShouldSatisfyAllConditions(
                () => result.ShouldNotBeNull(),
                () => result.Value.ShouldBe(0));
        }
Ejemplo n.º 15
0
        public void BuildProjectGrid_TaskCenterListNotFound_ReturnsExpectedMessage()
        {
            // Arrange
            const string ExpectedList    = "Task Center";
            const string ExpectedMessage = "In order to take advantage of the new EPM Live functionality, " +
                                           "please follow the instructions located <a href=\"http://www.projectpublisher.com/downloads/ProjectPublisherUpdateProcess.pdf\" " +
                                           "target=\"_blank\">here</a>.";
            var siteField = new ShimSPWeb
            {
                ListsGet = () => new ShimSPListCollection
                {
                    ItemGetString = name =>
                    {
                        if (name == ExpectedList)
                        {
                            throw new Exception();
                        }
                        else
                        {
                            return(new ShimSPList());
                        }
                    }
                }
            }.Instance;

            privateObject.SetFieldOrProperty("site", siteField);

            // Act
            var result = privateObject.Invoke(buildProjectGridMethodName) as string;

            // Assert
            dashboard.ShouldSatisfyAllConditions(
                () => result.ShouldNotBeNull(),
                () => result.ShouldBe(ExpectedMessage));
        }
 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
         }
     };
 }
Ejemplo n.º 17
0
        public void BuildProjectGrid_NoTaskListFound_ReturnsExpectedMessage()
        {
            // Arrange
            const string ExpectedList    = "Project Center";
            const string ExpectedMessage = "No Tasks List Found";
            var          siteField       = new ShimSPWeb
            {
                ListsGet = () => new ShimSPListCollection
                {
                    ItemGetString = name =>
                    {
                        if (name == ExpectedList)
                        {
                            return(new ShimSPList());
                        }
                        else
                        {
                            throw new Exception();
                        }
                    }
                }
            }.Instance;

            privateObject.SetFieldOrProperty("site", siteField);

            // Act
            var result = privateObject.Invoke(buildProjectGridMethodName) as string;

            // Assert
            dashboard.ShouldSatisfyAllConditions(
                () => result.ShouldNotBeNull(),
                () => result.ShouldBe(ExpectedMessage));
        }
        public void DisableTimesheets_Should_RemoveStringFromList()
        {
            // Arrange
            var actualEpmLiveTsLists = string.Empty;

            var list = new ShimSPList()
            {
                FieldsGet = () => new ShimSPFieldCollection()
                {
                    GetFieldByInternalNameString = internalName => new ShimSPField()
                },
                TitleGet = () => DummyTitle
            };

            var web = new ShimSPWeb()
            {
                SiteGet = () => new ShimSPSite()
                {
                    RootWebGet = () => new ShimSPWeb()
                }
            };

            ShimSPFieldLink.ConstructorSPField = (sender, spField) => new ShimSPFieldLink();

            ShimCoreFunctions.getConfigSettingSPWebString       = (rootWeb, setting) => $"{DummyTitle}\r\n{DummyInternalName}";
            ShimCoreFunctions.setConfigSettingSPWebStringString = (rootWeb, setting, value) => actualEpmLiveTsLists = value;

            // Act
            ListCommands.DisableTimesheets(list, web);

            // Assert
            actualEpmLiveTsLists.ShouldBe(DummyInternalName);
        }
Ejemplo n.º 19
0
        public void BaseProvision_ParentWebNotEqualWebNotUniquePermissionNotStandAlone_ConfirmResult()
        {
            // Arrange
            var standAlone         = false;
            var uniquePermission   = false;
            var userHavePermission = true;

            SetupForBaseProvision(standAlone, uniquePermission, userHavePermission);

            var web = new ShimSPWeb
            {
                IDGet   = () => Guid.NewGuid(),
                SiteGet = () => _site
            };

            // Act
            _testObj.BaseProvision(_site, web, _site, _web);

            // Assert
            this.ShouldSatisfyAllConditions(
                () => _webUpdated.ShouldBeTrue(),
                () => _createSiteFromItem.ShouldBeTrue(),
                () => _createSite.ShouldBeFalse(),
                () => _sendSignalToDB.ShouldBeFalse());
        }
 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 = _ => { }
     };
 }
Ejemplo n.º 21
0
        public void ProcessWeb_OnSuccess_ExecutesCorrectly()
        {
            // Arrange
            var spWeb = new ShimSPWeb
            {
                ListsGet = () => new ShimSPListCollection
                {
                    TryGetListString = listName => new ShimSPList
                    {
                        FieldsGet = () =>
                        {
                            var list = new List <SPField>
                            {
                                new ShimSPField
                                {
                                    TypeAsStringGet = () => "TotalRollup"
                                }
                            };
                            return(new ShimSPFieldCollection().Bind(list));
                        }
                    }
                },
                FeaturesGet = () => new ShimSPFeatureCollection
                {
                    ItemGetGuid = guid => new ShimSPFeature()
                }
            }.Instance;
            const string FixList = "task center";
            var          counter = 0F;
            var          args    = new object[] { spWeb, FixList, counter };
            var          systemUpdateWasCalled = false;

            ShimTimerFix.AllInstances.processWebSPWebStringSingleRef = null;
            ShimSPList.AllInstances.GetItemsSPQuery = (_, query) => new ShimSPListItemCollection
            {
                GetEnumerator = () => new List <SPListItem>
                {
                    new ShimSPListItem
                    {
                        ItemGetString = name => DummyString,
                    }
                }.GetEnumerator()
            };
            ShimTimerFix.AllInstances.getListItemCountSPWebSPFieldString = (_, web, field, project) => 1D;
            ShimSPFieldCollection.AllInstances.ContainsFieldString       = (_, name) => true;
            privateObject.SetFieldOrProperty("sbErrors", new StringBuilder());
            ShimSPListItem.AllInstances.SystemUpdate = _ =>
            {
                systemUpdateWasCalled = true;
            };

            // Act
            privateObject.Invoke(ProcessWebMethodName, args);
            counter = ((float?)args[2]).GetValueOrDefault(0);

            // Assert
            this.ShouldSatisfyAllConditions(
                () => counter.ShouldBeGreaterThan(0),
                () => systemUpdateWasCalled.ShouldBeTrue());
        }
        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 = _ => { };
        }
Ejemplo n.º 23
0
        public void BuildProjectGrid_DdlProjectSelectedItemNotEmpty_ExecutesCorrectly()
        {
            // Arrange
            var siteField = new ShimSPWeb
            {
                ListsGet = () => new ShimSPListCollection
                {
                    ItemGetString = name => new ShimSPList
                    {
                        ItemsGet = () => new ShimSPListItemCollection
                        {
                            GetEnumerator = () => new List <SPListItem>
                            {
                                new ShimSPListItem
                                {
                                    TitleGet    = () => "Dummy",
                                    UniqueIdGet = () => Guid.NewGuid(),
                                    ItemGetGuid = guid => "Dummy"
                                }
                            }.GetEnumerator()
                        },
                        FieldsGet = () => new ShimSPFieldCollection
                        {
                            GetFieldByInternalNameString = internalName => new ShimSPField
                            {
                                IdGet        = () => Guid.Empty,
                                SchemaXmlGet = () => "Dummy"
                            }
                        }
                    }
                }
            }.Instance;

            privateObject.SetFieldOrProperty("site", siteField);
            ShimDashboard.AllInstances.processProjectSummaryItemSPListItem = (_, listItem) => { };
            ShimListControl.AllInstances.SelectedItemGet    = _ => new ListItem("Dummy", Guid.NewGuid().ToString());
            ShimXmlDocument.AllInstances.LoadXmlString      = (_, content) => { };
            ShimXmlNode.AllInstances.SelectSingleNodeString = (_, node) =>
            {
                throw new Exception();
            };

            // Act
            privateObject.Invoke(buildProjectGridMethodName);
            var gridView = privateObject.GetFieldOrProperty("gvPJSummary") as SPGridView;
            var arrRisks = privateObject.GetFieldOrProperty("arrRisks") as SortedList;

            // Assert
            dashboard.ShouldSatisfyAllConditions(
                () => gridView.ShouldNotBeNull(),
                () => gridView.AutoGenerateColumns.ShouldBeFalse(),
                () => gridView.Columns.Count.ShouldBeGreaterThan(0),
                () => gridView.DataSource.ShouldNotBeNull(),
                () => ddlProject.Items.Count.ShouldBe(0),
                () => arrRisks.ShouldNotBeNull(),
                () => arrRisks.Count.ShouldBe(0));
        }
Ejemplo n.º 24
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;
        }
Ejemplo n.º 25
0
        public void ProcessProjectSummaryItem_WithParams_ExecutesCorrectly()
        {
            // Arrange
            const string ExpectedRiskStatus     = "<img src=\"/_layouts/images/green.gif\">";
            const string ExpectedIssueStatus    = "<img src=\"/_layouts/images/green.gif\">";
            const string ExpectedScheduleStatus = "<img src=\"/_layouts/images/red.gif\">";
            var          title            = string.Empty;
            var          startDate        = string.Empty;
            var          finishDate       = string.Empty;
            var          porcentCompleted = string.Empty;
            var          scheduleStatus   = string.Empty;

            var rowValues = new object[] { };
            var listItem  = new ShimSPListItem
            {
                TitleGet      = () => " Title",
                IDGet         = () => 1,
                ItemGetString = GetValue(new Hashtable
                {
                    ["Start"]           = DateTime.Now,
                    ["Finish"]          = DateTime.Now,
                    ["PercentComplete"] = 1,
                    ["Status"]          = "Late",
                    ["Projects"]        = "Late"
                })
            }.Instance;
            var site = new ShimSPWeb
            {
                UrlGet = () => "Url"
            }.Instance;
            var dataTable = new DataTable();

            privateObject.SetFieldOrProperty("site", site);
            privateObject.SetFieldOrProperty("dt", dataTable);
            ShimDashboard.AllInstances.getTaskCountString     = (_, name) => 1;
            ShimDataRowCollection.AllInstances.AddObjectArray = (_, parameters) =>
            {
                rowValues = parameters;
                return(null);
            };
            ShimDashboard.AllInstances.getRiskStatusString  = (_, name) => "green";
            ShimDashboard.AllInstances.getIssueStatusString = (_, name) => "green";

            // Act
            privateObject.Invoke(ProcessProjectSummaryItemMethodName, listItem);

            // Assert
            rowValues.ShouldSatisfyAllConditions(
                () => rowValues.Count().ShouldBe(8),
                () => rowValues[1].ShouldBe(DateTime.Now.ToShortDateString()),
                () => rowValues[2].ShouldBe(DateTime.Now.ToShortDateString()),
                () => rowValues[3].ShouldBe("100%"),
                () => rowValues[4].ShouldBe("1"),
                () => rowValues[5].ShouldBe(ExpectedScheduleStatus),
                () => rowValues[6].ShouldBe(ExpectedIssueStatus),
                () => rowValues[7].ShouldBe(ExpectedRiskStatus));
        }
Ejemplo n.º 26
0
        public void ProcessData_ResourceUrlNotEqualToServerUrl_NoActionTaken()
        {
            // Arrange
            var          dataRow = new object[] { };
            const string Url     = "/url";
            var          web     = new ShimSPWeb
            {
                TitleGet = () => DummyString,
                ListsGet = () => new ShimSPListCollection
                {
                    ItemGetString = name => new ShimSPList
                    {
                        GetItemsSPQuery = query => new ShimSPListItemCollection
                        {
                            GetEnumerator = () => new List <SPListItem>
                            {
                                new ShimSPListItem
                                {
                                    ItemGetString = _ => DummyString
                                }
                            }.GetEnumerator()
                        }
                    }
                },
                WebsGet = () =>
                {
                    var list = new List <SPWeb>
                    {
                        new ShimSPWeb()
                    }.AsEnumerable();
                    return(new ShimSPWebCollection().Bind(list));
                }
            }.Instance;
            var resWeb = new ShimSPWeb
            {
                ServerRelativeUrlGet = () => Url
            }.Instance;

            ShimCoreFunctions.getConfigSettingSPWebString     = (_, setting) => DummyString;
            ShimDataRowCollection.AllInstances.AddObjectArray = (_, row) =>
            {
                dataRow = row;
                return(new ShimDataRow());
            };
            ShimPage.AllInstances.RequestGet = _ => new ShimHttpRequest
            {
                ItemGetString = name => bool.TrueString.ToLower()
            };
            ShimLoggingService.WriteTraceStringStringTraceSeverityString =
                (area, category, severity, message) => { };

            // Act
            privateObject.Invoke(ProcessDataMethodName, web, resWeb);

            // Assert
            dataRow.ShouldBeEmpty();
        }
Ejemplo n.º 27
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);
            }
        }
Ejemplo n.º 28
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);
            }
        }
        public void EnableTimesheets_Should_UpdateFields()
        {
            // Arrange
            var countUpdatedField       = 0;
            var countUpdatedContentType = 0;
            var countUpdatedList        = 0;
            var actualEpmLiveTsLists    = string.Empty;

            var list = new ShimSPList()
            {
                FieldsGet = () => new ShimSPFieldCollection()
                {
                    GetFieldByInternalNameString = internalName => new ShimSPField()
                    {
                        Update = () => countUpdatedField++
                    }
                },
                ContentTypesGet = () => new ShimSPContentTypeCollection()
                {
                    ItemGetString = itemName => new ShimSPContentType()
                    {
                        FieldLinksGet = () => new ShimSPFieldLinkCollection()
                        {
                            ItemGetGuid = guid => null
                        },
                        Update = () => countUpdatedContentType++
                    }
                },
                Update   = () => countUpdatedList++,
                TitleGet = () => DummyTitle
            };

            var web = new ShimSPWeb()
            {
                SiteGet = () => new ShimSPSite()
                {
                    RootWebGet = () => new ShimSPWeb()
                }
            };

            ShimSPFieldLink.ConstructorSPField = (sender, spField) => new ShimSPFieldLink();

            ShimCoreFunctions.getConfigSettingSPWebString       = (rootWeb, setting) => string.Empty;
            ShimCoreFunctions.setConfigSettingSPWebStringString = (rootWeb, setting, value) => actualEpmLiveTsLists = value;

            // Act
            ListCommands.EnableTimesheets(list, web);

            // Assert
            this.ShouldSatisfyAllConditions(
                () => countUpdatedField.ShouldBe(2),
                () => countUpdatedContentType.ShouldBe(2),
                () => countUpdatedList.ShouldBe(1),
                () => actualEpmLiveTsLists.ShouldBe($"\r\n{DummyTitle}"));
        }
        public void SetUp()
        {
            _shimsContext = ShimsContext.Create();

            _resourceUrl = "http://test.test";

            _webServerRelativeUrl = "http://test.test";

            _resourcePlanListsString = "1,2,3";
            _siteId   = Guid.NewGuid();
            _hours    = 1;
            _workdays = "1";

            _listItemShim = new ShimSPListItem
            {
                ItemGetGuid = id => new object()
            };

            var listItemCollection = new ShimSPListItemCollection();

            var webList = new ShimSPList
            {
                GetItemsSPQuery = query =>
                {
                    return(listItemCollection.Bind(new[] { _listItemShim.Instance }));
                },
                FieldsGet = () => new ShimSPFieldCollection
                {
                    GetFieldByInternalNameString = name => new ShimSPField()
                }
            };

            var webListCollectionShim = new ShimSPListCollection
            {
                ItemGetString = (name) => webList.Instance
            };

            _webShim = new ShimSPWeb
            {
                ServerRelativeUrlGet = () => _webServerRelativeUrl,
                ListsGet             = () => webListCollectionShim.Instance
            };

            ShimSPFieldLookupValue.ConstructorString = (element, name) =>
                                                       new ShimSPFieldLookupValue();

            _spFieldUserValues = new List <SPFieldUserValue>
            {
                new SPFieldUserValue(_webShim.Instance, "1"),
                new SPFieldUserValue(_webShim.Instance, "2"),
            };

            // (CC-76656, 2018-07-18) Sadly, can not shim SPFieldUserValueCollection constructor to be able to contain elements, due to SP limitations
            // Therefore, can not test ResourceInfo generation
        }
        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 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);
            }
        }
        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);
            }
        }