Exemple #1
0
 private void ShimSPFieldCollectionMethods()
 {
     _shimFields = new ShimSPFieldCollection
     {
         GetFieldByInternalNameString = _ => new ShimSPField()
         {
             TitleGet = () => DummyString
         }.Instance,
           AddStringSPFieldTypeBoolean = (field, _, __) =>
         {
             _addedFields.Add(field);
             return(field);
         },
         AddFieldAsXmlString = field =>
         {
             _addedFields.Add(field);
             return(field);
         },
         AddLookupStringGuidBoolean = (field, _, __) =>
         {
             _lookupFields.Add(field);
             return(field);
         }
     };
 }
        public void WSSLoadFields_AllowCustomFieldTypeOnly_ExecutesCorrectly()
        {
            // Arrange
            var dropDown = new DropDownList();
            var fields   = new List <SPField>
            {
                new ShimSPField
                {
                    TypeAsStringGet = () => "CascadingLookupField",
                    InternalNameGet = () => DummyString,
                    TitleGet        = () => DummyString
                },
                new ShimSPField
                {
                    TypeAsStringGet = () => DummyString,
                    InternalNameGet = () => DummyString,
                    TitleGet        = () => DummyString
                }
            };
            var fieldsCollection = new ShimSPFieldCollection().Bind(fields).Instance;
            var args             = new object[] { fieldsCollection, dropDown, DummyString, new object(), true };

            // Act
            privateObject.Invoke(WSSLoadFieldsMethodName, args);

            // Assert
            dropDown.ShouldSatisfyAllConditions(
                () => dropDown.Items.Count.ShouldBe(2),
                () => dropDown.Items.FindByValue(DummyString).ShouldNotBeNull());
        }
        private void ShimSPFieldCollectionMethods()
        {
            _shimFields = new ShimSPFieldCollection
            {
                GetFieldByInternalNameString = _ => new ShimSPField()
                {
                    TitleGet        = () => DummyString,
                    InternalNameGet = () => DummyString
                }.Instance
            };

            _shimFieldLookup = new ShimSPFieldLookup
            {
                LookupFieldGet = () => DummyGuid.ToString(),
                LookupWebIdGet = () => DummyGuid,
                LookupListGet  = () => DummyGuid.ToString()
            };
            ShimSPField.AllInstances.TitleGet            = _ => DummyString;
            ShimSPField.AllInstances.InternalNameGet     = _ => DummyString;
            ShimFieldMetadata.AllInstances.FieldGet      = _ => _shimFieldLookup.Instance;
            ShimLookupField.AllInstances.OnInitEventArgs = (_, __) => { _baseOnInitCalled = true; };
            ShimFormComponent.AllInstances.ListItemGet   = _ => GetListItem();
            ShimSPFieldLookupValue.ConstructorString     = (_, key) =>
            {
                ShimSPFieldLookupValue.AllInstances.ToString01 = __ => key;
            };
            _testObject.LookupField = _shimFieldLookup;
        }
        public void WSSLoadFields_NoUsableFieldOnList_ThrowsException()
        {
            // Arrange
            var dropDown         = new DropDownList();
            var fields           = new List <SPField>();
            var fieldsCollection = new ShimSPFieldCollection().Bind(fields).Instance;
            var args             = new object[] { fieldsCollection, dropDown, DummyString, new object(), false };

            // Act
            Action action = () => privateObject.Invoke(WSSLoadFieldsMethodName, args);

            // Assert
            action.ShouldThrow <Exception>();
        }
        private void PrepareSpContext()
        {
            ShimSPContext.CurrentGet          = () => new ShimSPContext();
            ShimSPContext.AllInstances.WebGet = _ => new ShimSPWeb();

            ShimSPWebCollection.AllInstances.ItemGetGuid = (_, __) => new ShimSPWeb();
            var listCollection = new ShimSPListCollection();

            ShimSPWeb.AllInstances.ListsGet       = _ => listCollection.Bind(new SPList[] { new ShimSPList() });
            ShimSPWeb.AllInstances.SiteGet        = _ => new ShimSPSite();
            ShimSPWeb.AllInstances.CurrentUserGet = _ => new ShimSPUser();
            ShimSPWeb.AllInstances.Close          = _ => { };
            ShimSPUser.AllInstances.IDGet         = _ => Id;

            ShimSPSite.ConstructorGuid                 = (_, __) => { };
            ShimSPSite.AllInstances.OpenWeb            = _ => new ShimSPWeb();
            ShimSPSite.AllInstances.OpenWebGuid        = (_, __) => new ShimSPWeb();
            ShimSPSite.AllInstances.AllWebsGet         = _ => new ShimSPWebCollection();
            ShimSPSite.AllInstances.ContentDatabaseGet = _ => new ShimSPContentDatabase();
            ShimSPSite.AllInstances.SiteIdGet          = _ => DefaultSiteId;
            ShimSPSite.AllInstances.IDGet              = _ => DefaultSiteId;
            ShimSPSite.AllInstances.Close              = _ => { };

            ShimSPListCollection.AllInstances.ItemGetString = (_, __) => new ShimSPList();
            ShimSPListCollection.AllInstances.ItemGetGuid   = (_, __) => new ShimSPList();
            ShimSPList.AllInstances.TitleGet = _ => ListTitle;
            var listItemCollection = new ShimSPListItemCollection();

            ShimSPList.AllInstances.GetItemsSPQuery = (_, __) => listItemCollection.Bind(new SPListItem[] { new ShimSPListItem() });
            var fieldCollection = new ShimSPFieldCollection();

            ShimSPList.AllInstances.FieldsGet    = _ => fieldCollection.Bind(new SPField[] { new ShimSPField() });
            ShimSPListItem.AllInstances.TitleGet = _ => DummyString;

            ShimSPFieldCollection.AllInstances.ItemGetString = (_, __) => new ShimSPField();
            ShimSPFieldCollection.AllInstances.GetFieldByInternalNameString = (_, __) => new ShimSPField();
            ShimSPFieldCollection.AllInstances.ContainsFieldString          = (_, __) => true;
            ShimSPField.AllInstances.TypeGet         = _ => SPFieldType.Text;
            ShimSPField.AllInstances.TitleGet        = _ => FieldTitle;
            ShimSPField.AllInstances.InternalNameGet = _ => Title;
            ShimSPField.AllInstances.ReorderableGet  = _ => true;

            ShimSPFieldMultiChoice.AllInstances.ChoicesGet = _ => new StringCollection {
                DummyString
            };
            ShimSPFieldLookup.AllInstances.LookupWebIdGet = _ => DefaultWebId;

            ShimSPDatabase.AllInstances.DatabaseConnectionStringGet             = _ => DummyString;
            ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = code => code?.Invoke();
        }
Exemple #6
0
        private void PrepareSpContext()
        {
            ShimSPContext.CurrentGet               = () => new ShimSPContext();
            ShimSPContext.AllInstances.WebGet      = _ => new ShimSPWeb();
            ShimSPContext.AllInstances.ListItemGet = _ => new ShimSPListItem();

            ShimCoreFunctions.getLockedWebSPWeb = web => DefaultWebId;
            ShimCoreFunctions.iGetConfigSettingSPWebStringBooleanBoolean = (a, b, c, d) => string.Empty;
            ShimUtils.GetConfigWebSPWebGuid = (_, __) => new ShimSPWeb();
            var listCollection = new ShimSPListCollection();

            ShimSPWeb.AllInstances.ListsGet            = _ => listCollection.Bind(new SPList[] { new ShimSPList() });
            ShimSPWeb.AllInstances.CurrentUserGet      = _ => new ShimSPUser();
            ShimSPWeb.AllInstances.RegionalSettingsGet = _ => new ShimSPRegionalSettings();
            ShimSPWeb.AllInstances.Close = _ => { };

            ShimSPSite.ConstructorString = (_, __) =>
            {
                ShimSPSite.AllInstances.OpenWeb = x => new ShimSPWeb();
                ShimSPSite.AllInstances.Close   = x => { };
            };

            ShimSPListCollection.AllInstances.GetListGuidBoolean = (a, b, c) => new ShimSPList();
            ShimSPListCollection.AllInstances.ItemGetString      = (_, __) => new ShimSPList();
            var fieldCollection = new ShimSPFieldCollection();

            ShimSPList.AllInstances.FieldsGet = _ => fieldCollection.Bind(new SPField[] { new ShimSPField() });
            var listItemCollection = new ShimSPListItemCollection();

            ShimSPList.AllInstances.ItemsGet          = _ => listItemCollection.Bind(new SPListItem[] { new ShimSPListItem().Instance });
            ShimSPListItem.AllInstances.IDGet         = _ => Id;
            ShimSPListItem.AllInstances.TitleGet      = _ => "LITitle";
            ShimSPListItem.AllInstances.ItemGetString = (_, key) => GetListItemValue(key);

            ShimSPFieldCollection.AllInstances.GetFieldByInternalNameString = (_, __) => new ShimSPFieldLookup();
            ShimSPField.AllInstances.GetCustomPropertyString = (_, key) => key;

            ShimSPFieldLookup.AllInstances.LookupListGet = _ => DefaultListId.ToString();

            ShimSPFieldUserValue.ConstructorSPWebString = (a, b, c) => { };
            ShimSPFieldUserValue.AllInstances.UserGet   = _ => new ShimSPUser();
            ShimSPUser.AllInstances.IDGet = _ => Id;

            ShimSPFieldLookupValue.ConstructorString        = (_, __) => { };
            ShimSPFieldLookupValue.AllInstances.LookupIdGet = _ => Id;

            ShimSPRegionalSettings.AllInstances.LocaleIdGet = _ => (uint)CultureInfo.InvariantCulture.LCID;
        }
Exemple #7
0
        private ShimSPFieldCollection InitializeSPFieldsShim()
        {
            var result = new ShimSPFieldCollection
            {
                GetFieldByInternalNameString = (internalName) =>
                {
                    var fieldShim = InitializeSPFieldShim();
                    fieldShim.InternalNameGet = () => internalName;
                    return(fieldShim);
                }
            };

            result.Bind(new SPField[] { FieldShim });

            return(result);
        }
        private void PrepareSpContext()
        {
            ShimSPContext.CurrentGet               = () => new ShimSPContext();
            ShimSPContext.AllInstances.WebGet      = _ => new ShimSPWeb();
            ShimSPContext.AllInstances.ListGet     = _ => new ShimSPList();
            ShimSPContext.AllInstances.ListItemGet = _ => new ShimSPListItem();

            ShimSPRibbon.GetCurrentPage = _ => new ShimSPRibbon();
            ShimRibbon.AllInstances.RegisterDataExtensionXmlNodeString =
                (_, node, key) => _registeredExtensions[key]           = node;

            ShimSPWeb.AllInstances.IDGet                     = _ => DefaultWebId;
            ShimSPWeb.AllInstances.SiteGet                   = _ => new ShimSPSite();
            ShimSPWeb.AllInstances.LanguageGet               = _ => Id;
            ShimSPWeb.AllInstances.FeaturesGet               = _ => new ShimSPFeatureCollection();
            ShimSPWeb.AllInstances.CurrentUserGet            = _ => new ShimSPUser();
            ShimSPUser.AllInstances.IDGet                    = _ => Id;
            ShimSPFeatureCollection.AllInstances.ItemGetGuid = (_, __) => new ShimSPFeature();
            ShimSPSite.AllInstances.IDGet                    = _ => DefaultSiteId;

            ShimSPList.AllInstances.IDGet = _ => DefaultListId;
            var fieldCollection = new ShimSPFieldCollection();

            ShimSPList.AllInstances.FieldsGet       = _ => fieldCollection.Bind(new SPField[] { new ShimSPField() });
            ShimSPList.AllInstances.BaseTemplateGet = _ => (SPListTemplateType)EPMLiveLists.ProjectCenter;

            ShimSPListItem.AllInstances.ItemGetString = (_, key) =>
            {
                switch (key)
                {
                case ProjectArchiverService.ArchivedColumn:
                    return(false);

                case "WorkspaceUrl":
                    return(ExampleUrl);

                default:
                    return(DummyString);
                }
            };
            ShimSPListItem.AllInstances.ParentListGet            = _ => new ShimSPList();
            ShimSPListItem.AllInstances.ModerationInformationGet = _ => new ShimSPModerationInformation();
            ShimSPModerationInformation.AllInstances.StatusGet   = _ => SPModerationStatusType.Approved;

            ShimSPFieldCollection.AllInstances.ContainsFieldString = (_, __) => true;
        }
Exemple #9
0
        private ShimSPListCollection CreateShimSpListCollection(ShimSPFieldCollection shimFields)
        {
            _listsDictionary = new Dictionary <string, SPList>();
            var shimLists = new ShimSPListCollection();

            shimLists.ItemGetString    = listName => _listsDictionary[listName];
            shimLists.TryGetListString = listName => _listsDictionary.ContainsKey(listName)
                ? _listsDictionary[listName]
                : null;

            var shimSpList = new ShimSPList();

            shimSpList.FieldsGet = () => shimFields.Instance;
            _listsDictionary.Add("Task Center", shimSpList.Instance);

            return(shimLists);
        }
Exemple #10
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 = () => { }
     };
 }
Exemple #11
0
        private ShimSPFieldCollection CreateShimSpFieldCollection()
        {
            var fieldsDictionary = new Dictionary <string, SPField>();
            var shimFields       = new ShimSPFieldCollection();

            shimFields.ContainsFieldString = fieldName => fieldsDictionary.ContainsKey(fieldName);
            shimFields.ItemGetString       = fieldName => fieldsDictionary[fieldName];
            shimFields.AddSPField          = spField =>
            {
                fieldsDictionary.Add(spField.TypeDisplayName, spField);
                return(spField.TypeDisplayName);
            };
            shimFields.AddStringSPFieldTypeBoolean = (displayName, fieldType, required) =>
            {
                var spField = CreateSpField(displayName, fieldType, fieldsDictionary.Count);
                fieldsDictionary.Add(displayName, spField);

                return(displayName);
            };
            shimFields.CreateNewFieldStringString = (typeName, displayName) =>
            {
                SPField spField;

                if (typeName == SPFieldType.Text.ToString())
                {
                    var spFieldText = new ShimSPFieldText();
                    spField = CreateSpField(displayName, SPFieldType.Text, fieldsDictionary.Count, spFieldText.Instance);
                }
                else
                {
                    spField = CreateSpField(displayName, SPFieldType.Invalid, fieldsDictionary.Count);
                }

                return(spField);
            };

            var shimBaseCollection = new ShimSPBaseCollection(shimFields.Instance);

            shimBaseCollection.GetEnumerator = () => fieldsDictionary.Values.ToList().GetEnumerator();

            return(shimFields);
        }
Exemple #12
0
        public void TestInitialize()
        {
            _shimsContext = ShimsContext.Create();
            _spWeb        = new ShimSPWeb
            {
                CurrentUserGet = () => new ShimSPUser
                {
                    LoginNameGet = () => "LoginName"
                },
                SiteGet = () => new ShimSPSite
                {
                    WebApplicationGet = () =>
                    {
                        var shim = new ShimSPWebApplication();
                        new ShimSPPersistedObject(shim)
                        {
                            IdGet = () => Guid.Empty
                        };
                        return(shim);
                    }
                }
            };
            _shimSPFieldCollection = new ShimSPFieldCollection
            {
                ItemGetGuid = guid => new ShimSPField
                {
                    GetFieldValueString = stringValue => "[today]",
                    TypeGet             = () => SPFieldType.DateTime
                },
                GetFieldByInternalNameString = stringValue => new ShimSPField
                {
                    TypeGet      = () => SPFieldType.Calculated,
                    SchemaXmlGet = () => "<Default></Default>"
                }
            };
            _spSite = new ShimSPSite
            {
                RootWebGet  = () => _spWeb,
                OpenWebGuid = guid => new ShimSPWeb
                {
                    IDGet    = () => guid,
                    ListsGet = () => new ShimSPListCollection
                    {
                        ItemGetGuid = guidValue => new ShimSPList
                        {
                            IDGet            = () => guid,
                            GetItemByIdInt32 = intValue => new ShimSPListItem
                            {
                                FieldsGet = () => _shimSPFieldCollection
                            },
                            FieldsGet = () => _shimSPFieldCollection
                        }
                    }
                }
            };
            ShimSPContext.CurrentGet = () => new ShimSPContext
            {
                SiteGet = () => _spSite,
                WebGet  = () => _spWeb
            };
            var shimSpView = new ShimSPView
            {
                ViewFieldsGet = () => new ShimSPViewFieldCollection()
                {
                    CountGet = () => 1
                }
            };

            _shimSpList = new ShimSPList
            {
                FieldsGet = () => _shimSPFieldCollection
            };
            _getpmapprovals = new getpmapprovals();
            _privateObject  = new PrivateObject(_getpmapprovals);
            _privateObject.SetFieldOrProperty("site", (SPSite)_spSite);
            _privateObject.SetFieldOrProperty("view", (SPView)shimSpView);
            _privateObject.SetFieldOrProperty("list", (SPList)_shimSpList);
            var dataSet = new DataSet();

            dataSet.Tables.Add(GetDataTable("TimesheetMeta"));
            _privateObject.SetFieldOrProperty("dsTimesheetMeta", dataSet);
            ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = codeToRun => codeToRun();
        }
Exemple #13
0
        private void commonTest(Boolean groups)
        {
            try
            {
                SortedList    arrGTemp = new SortedList();
                PrivateObject objToTestPrivateMethod = new PrivateObject(typeof(getts));
                XmlDocument   docXml = new XmlDocument();

                using (SPEmulators.SPEmulationContext ctx = new SPEmulators.SPEmulationContext(SPEmulators.IsolationLevel.Fake))
                {
                    SPList list  = new ShimSPList();
                    SPWeb  spWeb = new ShimSPWeb();

                    docXml.LoadXml("<rows></rows>");
                    objToTestPrivateMethod.SetField("docXml", docXml);
                    objToTestPrivateMethod.SetField("period", "1");
                    objToTestPrivateMethod.SetField("ndMainParent", docXml.ChildNodes[0]);
                    objToTestPrivateMethod.SetField("list", list);

                    if (groups)
                    {
                        objToTestPrivateMethod.SetField("arrGroupFields", new string[] { "FirstName", "LastName" });

                        ShimSPField.AllInstances.IdGet = (instance) =>
                        {
                            return(Guid.NewGuid());
                        };

                        ShimSPList.AllInstances.FieldsGet = (instance) =>
                        {
                            ShimSPFieldCollection fcol = new ShimSPFieldCollection();
                            fcol.GetFieldByInternalNameString = (internalName) =>
                            {
                                ShimSPField field = new ShimSPField();
                                field.IdGet = () =>
                                {
                                    return(Guid.NewGuid());
                                };
                                field.GetFieldValueAsTextObject = (obj) =>
                                {
                                    return(internalName);
                                };
                                return(field);
                            };
                            return(fcol);
                        };
                    }

                    ShimSPList.AllInstances.GetItemsSPQuery = (instance, a) =>
                    {
                        SPListItemEnumerator sPListItemEnumerator = new SPListItemEnumerator();
                        return(new ShimSPListItemCollection()
                        {
                            GetEnumerator = () =>
                            {
                                return sPListItemEnumerator;
                            },
                            CountGet = () =>
                            {
                                return sPListItemEnumerator.sPListItems.Length;
                            }
                        });
                    };

                    objToTestPrivateMethod.Invoke("processList", spWeb, arrGTemp);
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
        private void SetupShims(ICollection spArray = null)
        {
            ShimCoreFunctions.getConnectionStringGuid = (_) => { return("Data Source=epmdb;Initial Catalog=PEPM_Dev_eelsayed_Fake;Integrated Security=True"); };

            var webApplication = new SPWebApplication()
            {
                Id = Guid.Empty
            };
            var spFieldCollection = new ShimSPFieldCollection()
            {
                ItemGetGuid = _ => (spArray as SPField[])?[0]
            };
            var spList = new ShimSPList()
            {
                FieldsGet = () => spFieldCollection
            };
            var spListCollection = new ShimSPListCollection()
            {
                ItemGetString = _ => spList,
                ItemGetGuid   = _ => spList
            };
            var spWeb = new ShimSPWeb()
            {
                Close    = () => { },
                ListsGet = () => spListCollection,
                GetAvailableWebTemplatesUInt32 = _ => null,
                AllUsersGet = () => new ShimSPUserCollection()
            };
            var shimSPSite = new ShimSPSite()
            {
                IDGet                = () => new Guid(),
                WebApplicationGet    = () => webApplication,
                RootWebGet           = () => spWeb,
                UrlGet               = () => ValidUrl,
                Close                = () => { },
                ServerRelativeUrlGet = () => ValidUrl
            };

            ShimSPWeb.AllInstances.UrlGet   = _ => ValidUrl;
            ShimSPWeb.AllInstances.SiteGet  = _ => shimSPSite;
            ShimSPWeb.AllInstances.ListsGet = _ => spListCollection;
            ShimSPWeb.AllInstances.WebsGet  = _ => new ShimSPWebCollection()
            {
                AddStringStringStringUInt32StringBooleanBoolean = (a, b, c, d, e, f, g) => spWeb
            };
            ShimSPSite.ConstructorString = (site, _) =>
            {
                site = shimSPSite;
            };
            ShimSPSite.ConstructorGuid = (site, _) =>
            {
                site = shimSPSite;
            };
            ShimSPSite.AllInstances.RootWebGet        = _ => spWeb;
            ShimSPSite.AllInstances.WebApplicationGet = _ => webApplication;
            ShimSPSite.AllInstances.OpenWeb           = _ => new ShimSPWeb();
            ShimSPSite.AllInstances.Close             = _ => { };
            ShimSPContext.CurrentGet = () => new ShimSPContext()
            {
                SiteGet = () => shimSPSite,
                WebGet  = () => spWeb
            };
            if (spArray == null)
            {
                spArray = new SPField[0];
            }
            ShimSPBaseCollection.AllInstances.GetEnumerator            = _ => spArray.GetEnumerator();
            ShimCustomFields.AllInstances.ReadCustomFieldsByEntityGuid =
                (_, __) => new CustomFieldDataSet();
            ShimSqlConnection.AllInstances.Open = _ =>
            {
                _isConnectionOpenedCalled = true;
            };
            ShimSqlCommand.AllInstances.ExecuteReader = _ =>
            {
                _executeReaderCallCount++;
                return(new ShimSqlDataReader());
            };
            ShimSqlCommand.AllInstances.ExecuteNonQuery = _ =>
            {
                _isExecuteNonQueryCalled = true;
                return(0);
            };
            ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = (_) =>
            {
                _.Invoke();
            };
            ShimEventLog.AllInstances.WriteEntryStringEventLogEntryTypeInt32 = (a, b, c, d) =>
            {
                _isWriteEntryCalled = true;
            };
            var projectDataTable = CreateProjectDataTable();

            ShimProject.AllInstances.ReadProjectGuidDataStoreEnum = (_, __, ___) => new ShimProjectDataSet()
            {
                ProjectGet = () => projectDataTable
            };
            ShimSqlConnection.AllInstances.DisposeBoolean = (_, __) =>
            {
                _isConnectionDisposeCalled = true;
            };
            ShimSqlCommand.AllInstances.DisposeBoolean = (_, __) =>
            {
                _sqlCommandDisposeCallCount++;
            };
            ShimEventLog.AllInstances.DisposeBoolean = (_, __) =>
            {
                _isEventLogDisposeCalled = true;
            };
            ShimWssInterop.AllInstances.ReadWssSettings = _ => new ShimWssSettingsDataSet()
            {
                WssAdminGet = () => new ShimWssAdminDataTable()
                {
                    ItemGetInt32 = (index) => new ShimWssAdminRow()
                    {
                        WADMIN_DEFAULT_SITE_COLLECTIONGet = () => string.Empty,
                        WADMIN_STS_TEMPLATE_LCIDGet       = () => 1
                    }
                }
            };
        }
        private void SetupVariables()
        {
            guid = new Guid(GuidString);

            spSite = new ShimSPSite()
            {
                IDGet              = () => guid,
                UrlGet             = () => Url,
                ContentDatabaseGet = () => new ShimSPContentDatabase(),
                OpenWebGuid        = _ => spWeb
            };

            fields = new ShimSPFieldCollection()
            {
                ContainsFieldString = _1 => true
            };

            spListItem = new ShimSPListItem()
            {
                IDGet         = () => 1,
                FieldsGet     = () => fields,
                ItemGetString = _1 => DummyString
            };

            spList = new ShimSPList()
            {
                IDGet           = () => guid,
                TitleGet        = () => Title,
                GetItemsSPQuery = _ => new ShimSPListItemCollection()
                {
                    FieldsGet     = () => fields,
                    GetEnumerator = () => new List <SPListItem>()
                    {
                        spListItem
                    }.GetEnumerator()
                },
                GetItemByIdInt32 = _ => spListItem
            };

            var currentUser = new ShimSPUser()
            {
                IDGet               = () => 1,
                LoginNameGet        = () => DummyString,
                RegionalSettingsGet = () => new ShimSPRegionalSettings()
            };

            spWeb = new ShimSPWeb()
            {
                CurrentUserGet       = () => currentUser,
                SiteGet              = () => spSite,
                TitleGet             = () => Title,
                ServerRelativeUrlGet = () => ServerRelativeUrl,
                ListsGet             = () => new ShimSPListCollection()
                {
                    ItemGetString    = _ => spList,
                    ItemGetGuid      = _ => spList,
                    TryGetListString = _ => spList
                },
                UrlGet = () => Url
            };

            webApplication = new ShimSPWebApplication();
        }
        private ShimSPWeb ArrangeForExecute()
        {
            var list = new List <SPUser>
            {
                new ShimSPUser
                {
                    IDGet    = () => 11,
                    NameGet  = () => "Name",
                    EmailGet = () => "Email"
                }
            };
            var shimSPUserCollection = new ShimSPUserCollection
            {
                GetByIDInt32 = intValue => list[0]
            };

            new ShimSPBaseCollection(shimSPUserCollection)
            {
                GetEnumerator = () => list.GetEnumerator()
            };
            return(new ShimSPWeb
            {
                AllUsersGet = () => shimSPUserCollection,
                ListsGet = () =>
                {
                    var listSpList = new List <SPList>
                    {
                        new ShimSPList
                        {
                            GetItemsSPQuery = spQuery =>
                            {
                                var listSPField = new List <SPField>
                                {
                                    new ShimSPField
                                    {
                                        InternalNameGet = () => "InternalName",
                                        SchemaXmlGet = () => " Percentage=\"TRUE\""
                                    }
                                };
                                var listListItem = new List <SPListItem>
                                {
                                    new ShimSPListItem
                                    {
                                        FieldsGet = () =>
                                        {
                                            var shimSPFieldCollection = new ShimSPFieldCollection
                                            {
                                                GetFieldByInternalNameString = stringValue => listSPField[0]
                                            };
                                            new ShimSPBaseCollection(shimSPUserCollection)
                                            {
                                                GetEnumerator = () => listSPField.GetEnumerator()
                                            };
                                            return shimSPFieldCollection;
                                        },
                                        ItemGetGuid = guidValue => "2018-05-12"
                                    }
                                };
                                var shimSPListItemCollection = new ShimSPListItemCollection
                                {
                                    CountGet = () => listListItem.Count,
                                    GetEnumerator = () => listListItem.GetEnumerator()
                                };
                                return shimSPListItemCollection;
                            }
                        }
                    };
                    var shim = new ShimSPListCollection
                    {
                        ItemGetString = stringValue => listSpList[0]
                    };
                    new ShimSPBaseCollection(shim)
                    {
                        GetEnumerator = () => listSpList.GetEnumerator()
                    };
                    return shim;
                },
                LocaleGet = () => new CultureInfo("en-US"),
                PropertiesGet = () =>
                {
                    var shim = new ShimSPPropertyBag();
                    var stringDictionary = new StringDictionary
                    {
                        ["EPMLiveNotificationLists"] = "notification|notificationC`notification|notificationC`notification|notificationC`notification|notificationC",
                        ["EPMLiveNotificationEmail"] = "EPMLiveNotificationEmail",
                        ["EPMLiveNotificationEmailSubject"] = "EPMLiveNotificationEmailSubject",
                        ["EPMLiveNotificationNote"] = "EPMLiveNotificationNote",
                        ["EPMLiveLogDetailedErrors"] = "EPMLiveLogDetailedErrors",
                        ["EPMLiveNotificationOptedOutUsers"] = "10"
                    };
                    new ShimStringDictionary(shim)
                    {
                        ContainsKeyString = key => stringDictionary.ContainsKey(key),
                        ItemGetString = key => stringDictionary.ContainsKey(key)
                            ? stringDictionary[key]
                            : null,
                        ItemSetStringString = (key, stringValue) =>
                        {
                            if (stringDictionary.ContainsKey(key))
                            {
                                stringDictionary[key] = stringValue;
                            }
                            else
                            {
                                stringDictionary.Add(key, stringValue);
                            }
                        }
                    };
                    return shim;
                },
                SiteUsersGet = () => shimSPUserCollection,
                UrlGet = () => SpWebUrl,
                WebsGet = () =>
                {
                    var shim = new ShimSPWebCollection();
                    new ShimSPBaseCollection(shim)
                    {
                        GetEnumerator = () => new List <SPWeb>().GetEnumerator()
                    };
                    return shim;
                }
            });
        }
Exemple #17
0
 private void SetupVariables()
 {
     validations       = 0;
     publicStatic      = BindingFlags.Static | BindingFlags.Public;
     nonPublicStatic   = BindingFlags.Static | BindingFlags.NonPublic;
     publicInstance    = BindingFlags.Instance | BindingFlags.Public;
     nonPublicInstance = BindingFlags.Instance | BindingFlags.NonPublic;
     guid    = Guid.Parse(SampleGuidString1);
     request = new Dictionary <string, string>()
     {
         ["period"]     = DummyString,
         ["action"]     = DummyString,
         ["duser"]      = DummyString,
         ["ts_uids"]    = DummyString,
         ["tsitemuids"] = DummyString
     };
     currentDate = DateTime.Now;
     spWeb       = new ShimSPWeb()
     {
         IDGet                = () => guid,
         SiteGet              = () => spSite,
         ListsGet             = () => spListCollection,
         GetFolderString      = _ => spFolder,
         GetFileString        = _ => spFile,
         FoldersGet           = () => spFolderCollection,
         CurrentUserGet       = () => spUser,
         ServerRelativeUrlGet = () => SampleUrl,
         AllUsersGet          = () => new ShimSPUserCollection(),
         SiteUsersGet         = () => new ShimSPUserCollection(),
         TitleGet             = () => DummyString
     };
     spSite = new ShimSPSite()
     {
         IDGet             = () => guid,
         WebApplicationGet = () => new ShimSPWebApplication(),
         RootWebGet        = () => spWeb,
         FeaturesGet       = () => new ShimSPFeatureCollection()
         {
             ItemGetGuid = _ => new ShimSPFeature()
         },
         ContentDatabaseGet = () => new ShimSPContentDatabase()
     };
     spListCollection = new ShimSPListCollection()
     {
         TryGetListString = _ => spList,
         ItemGetString    = _ => spList,
         ItemGetGuid      = _ => spList
     };
     spList = new ShimSPList()
     {
         IDGet             = () => guid,
         FieldsGet         = () => spFieldCollection,
         GetItemByIdInt32  = _ => spListItem,
         ItemsGet          = () => spListItemCollection,
         GetItemsSPQuery   = _ => spListItemCollection,
         RootFolderGet     = () => spFolder,
         ParentWebGet      = () => spWeb,
         DefaultViewGet    = () => spView,
         ViewsGet          = () => spViewCollection,
         ContentTypesGet   = () => spContentTypeCollection,
         TitleGet          = () => DummyString,
         EventReceiversGet = () => new ShimSPEventReceiverDefinitionCollection(),
         DefaultViewUrlGet = () => SampleUrl
     };
     spListItemCollection = new ShimSPListItemCollection()
     {
         CountGet     = () => DummyInt,
         ItemGetInt32 = _ => spListItem
     };
     spListItem = new ShimSPListItem()
     {
         IDGet             = () => DummyInt,
         TitleGet          = () => DummyString,
         ItemGetString     = _ => DummyString,
         ItemGetGuid       = _ => DummyString,
         ItemSetGuidObject = (_, __) => { },
         Update            = () => { },
         FileGet           = () => spFile,
         ParentListGet     = () => spList,
         NameGet           = () => DummyString
     };
     spFieldCollection = new ShimSPFieldCollection()
     {
         GetFieldByInternalNameString = _ => spField,
         ContainsFieldString          = _ => false,
         GetFieldString = _ => spField,
         ItemGetString  = _ => spField
     };
     spField = new ShimSPField()
     {
         IdGet            = () => guid,
         TitleGet         = () => DummyString,
         InternalNameGet  = () => DummyString,
         ReadOnlyFieldGet = () => false,
         HiddenGet        = () => false,
         ReorderableGet   = () => true,
         TypeAsStringGet  = () => DummyString
     };
     spUser = new ShimSPUser()
     {
         IDGet          = () => DummyInt,
         IsSiteAdminGet = () => true,
         UserTokenGet   = () => new ShimSPUserToken(),
         EmailGet       = () => DummyString
     };
     spFolderCollection = new ShimSPFolderCollection()
     {
         ItemGetString = _ => spFolder,
         AddString     = _ => spFolder
     };
     spFolder = new ShimSPFolder()
     {
         ExistsGet     = () => false,
         SubFoldersGet = () => spFolderCollection,
         FilesGet      = () => spFileCollection,
         UrlGet        = () => SampleUrl,
         UniqueIdGet   = () => guid,
         ParentWebGet  = () => spWeb
     };
     spFileCollection = new ShimSPFileCollection()
     {
         CountGet = () => DummyInt,
         AddStringByteArrayBoolean = (_1, _2, _3) => spFile,
         AddStringStream           = (_1, _2) => spFile,
         ItemGetString             = _ => spFile
     };
     spFile = new ShimSPFile()
     {
         Delete                 = () => { },
         OpenBinaryStream       = () => null,
         NameGet                = () => DummyString,
         GetListItemStringArray = _ => spListItem
     };
     spViewCollection = new ShimSPViewCollection()
     {
         ItemGetString = _ => spView
     };
     spView = new ShimSPView()
     {
         ViewFieldsGet        = () => spViewFieldCollection,
         ServerRelativeUrlGet = () => SampleUrl
     };
     spViewFieldCollection   = new ShimSPViewFieldCollection();
     spContentTypeCollection = new ShimSPContentTypeCollection()
     {
         ItemGetString = _ => spContentType
     };
     spContentType = new ShimSPContentType()
     {
         IdGet         = () => default(SPContentTypeId),
         FieldLinksGet = () => spFieldLinkCollection
     };
     spFieldLinkCollection = new ShimSPFieldLinkCollection()
     {
         ItemGetGuid = _ => new ShimSPFieldLink()
     };
     transaction = new ShimSqlTransaction()
     {
         Commit   = () => { },
         Rollback = () => { }
     };
     dataReader = new ShimSqlDataReader()
     {
         Read             = () => false,
         GetInt32Int32    = _ => One,
         GetDateTimeInt32 = _ => currentDate,
         GetStringInt32   = _ => DummyString,
         GetGuidInt32     = _ => guid,
         Close            = () => { }
     };
 }