Esempio n. 1
0
        public void CanGetListOfCustomers()
        {
            if (context.IsolationLevel == IsolationLevel.Fake)
            {
                var item = context.CustomerList.Items.Add();
                item["Title"] = "Customer 1";
                item.Update();

                var item2 = context.CustomerList.Items.Add();
                item2["Title"] = "Customer 1";
                item2.Update();

                new ShimSPList(context.CustomerList)
                {
                    GetItemsSPQuery = (q) =>
                    {
                        var shim = new ShimSPListItemCollection();
                        shim.Bind(new[] { item, item2 });
                        return(shim.Instance);
                    }
                };
            }

            var result = repository.GetAll();

            Assert.AreEqual(2, result.Count());
        }
Esempio n. 2
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);
            }
        }
        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
        }
        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();
        }
        public void CanGetSalesOrderByCustomer()
        {
            using (var context = new SPEmulationContext(Settings.Default.IsolationLevel, Settings.Default.Url))
            {
                var solutionRelativePath = @"..\..\..\SalesOrderPortalSolution\Lists\";
                var salesOrderList = context.GetOrCreateList(solutionRelativePath + "SalesOrders\\Elements.xml", solutionRelativePath + "SalesOrders\\schema.xml");
                var orderLinesList = context.GetOrCreateList(solutionRelativePath + "OrderLines\\Elements.xml", solutionRelativePath + "OrderLines\\schema.xml");

                var repository = new SalesOrderListRepository();

                // CAML not yet supported. Fake queries.
                if (context.IsolationLevel == IsolationLevel.Fake)
                {
                    new ShimSPList(salesOrderList)
                    {
                        GetItemsSPQuery = (q) =>
                            {
                                var shim = new ShimSPListItemCollection();
                                shim.Bind(salesOrderList.Items.Cast<SPListItem>().Where(i => (int)i["Customer"] == 1));

                                return shim.Instance;
                            }
                    };

                    new ShimSPList(orderLinesList)
                    {
                        GetItemsSPQuery = (q) =>
                        {
                            var shim = new ShimSPListItemCollection();
                            var match = Regex.Match(q.Query, "<FieldRef Name='SalesOrder' LookupId='TRUE' /><Value Type='Lookup' >.*?</Value>");
                            var lookupId = int.Parse(match.Value.Replace("<FieldRef Name='SalesOrder' LookupId='TRUE' /><Value Type='Lookup' >", "").Replace("</Value>", ""));
                            shim.Bind(orderLinesList.Items.Cast<SPListItem>().Where(i => (int)i["SalesOrder"] == 1));

                            return shim.Instance;
                        }
                    };
                }

                var customer1 = new Customer
                {
                    CustomerId = 1,
                    Name = "Customer 1"
                };

                var salesOrdersOfCustomer1 = repository.GetByCustomer(customer1);
                Assert.AreEqual<int>(2, salesOrdersOfCustomer1.Count());
                Assert.AreEqual<int>(2, salesOrdersOfCustomer1.First().Lines.Count);
            }
        }
        public void CanGetSalesOrderByCustomer()
        {
            using (var context = new SPEmulationContext(Settings.Default.IsolationLevel, Settings.Default.Url))
            {
                var solutionRelativePath = @"..\..\..\SalesOrderPortalSolution\Lists\";
                var salesOrderList       = context.GetOrCreateList(solutionRelativePath + "SalesOrders\\Elements.xml", solutionRelativePath + "SalesOrders\\schema.xml");
                var orderLinesList       = context.GetOrCreateList(solutionRelativePath + "OrderLines\\Elements.xml", solutionRelativePath + "OrderLines\\schema.xml");

                var repository = new SalesOrderListRepository();

                // CAML not yet supported. Fake queries.
                if (context.IsolationLevel == IsolationLevel.Fake)
                {
                    new ShimSPList(salesOrderList)
                    {
                        GetItemsSPQuery = (q) =>
                        {
                            var shim = new ShimSPListItemCollection();
                            shim.Bind(salesOrderList.Items.Cast <SPListItem>().Where(i => (int)i["Customer"] == 1));

                            return(shim.Instance);
                        }
                    };

                    new ShimSPList(orderLinesList)
                    {
                        GetItemsSPQuery = (q) =>
                        {
                            var shim     = new ShimSPListItemCollection();
                            var match    = Regex.Match(q.Query, "<FieldRef Name='SalesOrder' LookupId='TRUE' /><Value Type='Lookup' >.*?</Value>");
                            var lookupId = int.Parse(match.Value.Replace("<FieldRef Name='SalesOrder' LookupId='TRUE' /><Value Type='Lookup' >", "").Replace("</Value>", ""));
                            shim.Bind(orderLinesList.Items.Cast <SPListItem>().Where(i => (int)i["SalesOrder"] == 1));

                            return(shim.Instance);
                        }
                    };
                }

                var customer1 = new Customer
                {
                    CustomerId = 1,
                    Name       = "Customer 1"
                };

                var salesOrdersOfCustomer1 = repository.GetByCustomer(customer1);
                Assert.AreEqual <int>(2, salesOrdersOfCustomer1.Count());
                Assert.AreEqual <int>(2, salesOrdersOfCustomer1.First().Lines.Count);
            }
        }
Esempio n. 7
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;
        }
Esempio n. 8
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 = () => { }
     };
 }
        public void GetCustomerByNameReturnsNull()
        {
            if (context.IsolationLevel == IsolationLevel.Fake)
            {
                var item = context.CustomerList.Items.Add();
                item["Title"] = "Customer 1";
                item.Update();

                new ShimSPList(context.CustomerList)
                {
                    GetItemsSPQuery = (q) =>
                    {
                        var shim = new ShimSPListItemCollection();
                        shim.Bind(new SPListItem[0]);
                        return shim.Instance;
                    }
                };
            }

            var result = repository.GetByName("Customer XXX");
            Assert.IsNull(result);
        }
Esempio n. 10
0
        public void GetCustomerByNameReturnsNull()
        {
            if (context.IsolationLevel == IsolationLevel.Fake)
            {
                var item = context.CustomerList.Items.Add();
                item["Title"] = "Customer 1";
                item.Update();

                new ShimSPList(context.CustomerList)
                {
                    GetItemsSPQuery = (q) =>
                    {
                        var shim = new ShimSPListItemCollection();
                        shim.Bind(new SPListItem[0]);
                        return(shim.Instance);
                    }
                };
            }

            var result = repository.GetByName("Customer XXX");

            Assert.IsNull(result);
        }
Esempio n. 11
0
        private void SetupShims()
        {
            var listCount = 1;

            var spListItem = new ShimSPListItem
            {
                Update        = () => _listItemUpdated = true,
                ItemGetString = _ => DummyString,
                Delete        = () =>
                {
                    _listItemDeleted = true;
                    listCount--;
                }
            };

            var spListItemCollection = new ShimSPListItemCollection
            {
                CountGet = () => listCount,
                Add      = () =>
                {
                    _listItemAdded = true;
                    return(spListItem);
                },
                GetDataTable = () => new ShimDataTable
                {
                    Clone = () => CreateDataTable()
                },
                DeleteInt32  = _ => _listItemDeleted = true,
                ItemGetInt32 = _ => spListItem
            };

            var spList = new ShimSPList
            {
                FieldsGet = () => new ShimSPFieldCollection
                {
                    ContainsFieldString         = _ => false,
                    AddStringSPFieldTypeBoolean = (name, __, ___) =>
                    {
                        _fieldAdded = true;
                        return(name);
                    },
                    ItemGetString = _ => new ShimSPField()
                },
                ItemsGet         = () => spListItemCollection,
                Update           = () => _listUpdated = true,
                GetItemByIdInt32 = _ => spListItem,
                GetItemsSPQuery  = _ => spListItemCollection
            };

            _site = new ShimSPSite
            {
                IDGet      = () => Guid.NewGuid(),
                AllWebsGet = () => new ShimSPWebCollection
                {
                    ItemGetString = _ => _web
                },
                RootWebGet = () => _web
            };

            var userCount = 0;

            _web = new ShimSPWeb
            {
                IDGet    = () => Guid.NewGuid(),
                SiteGet  = () => _site,
                ListsGet = () => new ShimSPListCollection
                {
                    ItemGetString = _ => spList
                },
                UrlGet      = () => DummyString,
                AllUsersGet = () => new ShimSPUserCollection
                {
                    ItemGetString = _ =>
                    {
                        userCount++;

                        return(userCount == 1 ? null : new ShimSPUser());
                    },
                    AddStringStringStringString = (_1, _2, _3, _4) => _userAdded = true
                }
            };

            ShimSPSite.AllInstances.OpenWeb = _ => _web;

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

            ShimSPContext.CurrentGet          = () => new ShimSPContext();
            ShimSPContext.AllInstances.WebGet = _ => _web;

            ShimSPQuery.Constructor = _ => { };

            ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = action => action();

            ShimEPMData.ConstructorGuid = (_, __) => { };
            ShimEPMData.AllInstances.GetEPMLiveConnectionGet      = _ => new ShimSqlConnection();
            ShimEPMData.AllInstances.ExecuteNonQuerySqlConnection = (instance, __) =>
            {
                _nonQueryExecuted = true;
                _sqlString        = instance.Command;

                return(true);
            };
            ShimEPMData.AllInstances.AddParamStringObject = (_, __, ___) => { };
            ShimEPMData.AllInstances.Dispose = _ => _daoDisposed = true;

            ShimCoreFunctions.getConfigSettingSPWebStringBooleanBoolean = (_1, _2, _3, _4) => DummyString;
            ShimCoreFunctions.getConfigSettingSPWebString = (_, item) =>
            {
                switch (item)
                {
                case "EPMLIVEaddelete":
                    return("true");

                case "EPMLIVEadSizeLimit":
                    return(DummyInt.ToString());

                case "EPMLIVEadfields":
                    return($"{DummyString};{DummyString}");

                default:
                    return(DummyString);
                }
            };

            ShimDomain.GetComputerDomain = () => new ShimDomain();

            ShimActiveDirectoryPartition.AllInstances.ToString01 = _ => $"{DummyString}.Domain";

            ShimDirectoryEntry.ConstructorString = (_, __) => { };
            ShimDirectoryEntry.ConstructorStringStringStringAuthenticationTypes = (_1, _2, _3, _4, _5) => { };
            ShimDirectoryEntry.AllInstances.RefreshCache  = _ => _deRefreshCacheCalled = true;
            ShimDirectoryEntry.AllInstances.PropertiesGet = _ => new ShimPropertyCollection
            {
                ItemGetString = item => new ShimPropertyValueCollection
                {
                    ItemGetInt32 = ___ => new byte[] { }
                }
            };

            ShimDirectorySearcher.ConstructorDirectoryEntry       = (_, __) => { };
            ShimDirectorySearcher.ConstructorDirectoryEntryString = (_, __, ___) => { };
            ShimDirectorySearcher.AllInstances.FindAll            = _ => new ShimSearchResultCollection
            {
                Dispose = () => { }
            }.Bind(new SearchResult[]
            {
                new ShimSearchResult
                {
                    GetDirectoryEntry = () => new ShimDirectoryEntry
                    {
                        NameGet = () => DummyString,
                        PathGet = () => DummyString
                    },
                    PathGet = () => DummyString
                }.Instance
            });
            ShimDirectorySearcher.AllInstances.FindOne = _ => new ShimSearchResult
            {
                PropertiesGet = () => new ShimResultPropertyCollection
                {
                    ItemGetString = __ => new ShimResultPropertyValueCollection
                    {
                        ItemGetInt32 = ___ => DummyString
                    }
                }
            };

            ShimSecurityIdentifier.ConstructorByteArrayInt32 = (_, __, ___) => { };
            ShimSecurityIdentifier.AllInstances.ValueGet     = _ => DummyString;
        }
        public void CanGetListOfCustomers()
        {
            if (context.IsolationLevel == IsolationLevel.Fake)
            {
                var item = context.CustomerList.Items.Add();
                item["Title"] = "Customer 1";
                item.Update();

                var item2 = context.CustomerList.Items.Add();
                item2["Title"] = "Customer 1";
                item2.Update();

                new ShimSPList(context.CustomerList)
                {
                    GetItemsSPQuery = (q) =>
                    {
                        var shim = new ShimSPListItemCollection();
                        shim.Bind(new[] { item, item2 });
                        return shim.Instance;
                    }
                };
            }

            var result = repository.GetAll();
            Assert.AreEqual(2, result.Count());
        }
        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;
                }
            });
        }
Esempio n. 14
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            = () => { }
     };
 }
        private void SetupShims()
        {
            var count = 0;

            _dataTable = new DataTable();
            _dataTable.Columns.Add(IDColumn, typeof(int));
            _dataTable.Columns.Add(SharePointAccountColumn);
            _dataTable.Columns.Add(PermissionsColumn);
            _dataTable.Columns.Add(ResourceLevelField);
            _dataTable.Columns.Add(ChoiceField);
            _dataTable.Columns.Add(MultiChoiceField);
            _dataTable.Columns.Add(UserField);

            var listItemCollection = new ShimSPListItemCollection
            {
                GetDataTable = () =>
                {
                    count++;
                    if (count > 1)
                    {
                        return(_dataTable);
                    }
                    return(null);
                },
                Add = () => new ShimSPListItem
                {
                    ItemGetString = x => DummyString,
                    SystemUpdate  = () => _listItemSystemUpdated = true,
                    Delete        = () => { }
                }
            }
            .Bind(new SPListItem[]
            {
                new ShimSPListItem()
            });

            var spList = new ShimSPList
            {
                FieldsGet = () => new ShimSPFieldCollection().Bind(new SPField[]
                {
                    new ShimSPFieldLookup
                    {
                        LookupFieldGet = () => DummyString,
                        LookupWebIdGet = () => Guid.NewGuid(),
                        LookupListGet  = () => Guid.NewGuid().ToString()
                    },
                    new ShimSPFieldChoice(),
                    new ShimSPFieldMultiChoice(),
                    new ShimSPFieldUser()
                }),
                ParentWebGet        = () => _web,
                GetItemsSPQuery     = query => listItemCollection,
                ItemsGet            = () => listItemCollection,
                GetItemsStringArray = _ => listItemCollection,
                GetItemByIdInt32    = x => new ShimSPListItem
                {
                    ItemGetString = item =>
                    {
                        if (item == ResourceLevelField)
                        {
                            return(new ShimSPFieldLookupValueCollection().Instance);
                        }
                        return(DummyString);
                    }
                }
            };

            _web = new ShimSPWeb
            {
                SiteGet = () => new ShimSPSite
                {
                    IDGet = () => Guid.NewGuid()
                },
                ListsGet = () => new ShimSPListCollection
                {
                    ItemGetString = _ => spList,
                    ItemGetGuid   = _ => spList
                },
                CurrentUserGet = () => new ShimSPUser
                {
                    IsSiteAdminGet = () => true
                },
                GroupsGet = () => new ShimSPGroupCollection()
            };
            ShimSPWeb.AllInstances.Dispose = _ => { };

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

            ShimSPField.AllInstances.TitleGet        = _ => DummyString;
            ShimSPField.AllInstances.InternalNameGet = instance =>
            {
                if (instance is SPFieldUser)
                {
                    return(UserField);
                }
                if (instance is SPFieldLookup)
                {
                    return(ResourceLevelField);
                }
                if (instance is SPFieldChoice)
                {
                    return(ChoiceField);
                }
                if (instance is SPFieldMultiChoice)
                {
                    return(MultiChoiceField);
                }
                return(DummyString);
            };
            ShimSPField.AllInstances.ParentListGet = _ => new ShimSPList
            {
                ParentWebGet = () => _web
            };
            ShimSPField.AllInstances.TypeGet = instance =>
            {
                if (instance is SPFieldUser)
                {
                    return(SPFieldType.User);
                }
                if (instance is SPFieldLookup)
                {
                    return(SPFieldType.Lookup);
                }
                if (instance is SPFieldChoice)
                {
                    return(SPFieldType.Choice);
                }
                if (instance is SPFieldMultiChoice)
                {
                    return(SPFieldType.MultiChoice);
                }
                return(SPFieldType.Text);
            };

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

            ShimSPFieldLookup.AllInstances.AllowMultipleValuesGet = _ => true;

            ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = action => action();

            ShimSPQuery.Constructor = _ => { };

            ShimDisabledItemEventScope.Constructor = _ => { };

            ShimResourceExporter.GetPermissionsSPWeb = _ => new List <string> {
                DummyString
            };

            ShimSPFieldUserValue.ConstructorSPWebString = (_, __, ___) => { };
            ShimSPFieldUserValue.AllInstances.UserGet   = _ => new ShimSPUser
            {
                LoginNameGet = () => DummyString,
                GroupsGet    = () => new ShimSPGroupCollection().Bind(new SPGroup[]
                {
                    new ShimSPGroup
                    {
                        NameGet = () => DummyString
                    }
                })
            };

            ShimAct.ConstructorSPWeb         = (_, __) => { };
            ShimAct.AllInstances.IsOnlineGet = _ => true;
            ShimAct.AllInstances.GetLevelsFromSiteInt32OutString = (Act _, out int actType, string userName) =>
            {
                actType = DummyInt;
                return(new ArrayList
                {
                    new ActLevel
                    {
                        id = DummyInt,
                        name = DummyString
                    }
                });
            };

            ShimEPMLiveFileStore.ConstructorSPWeb          = (_, __) => { };
            ShimEPMLiveFileStore.AllInstances.AddByteArray = (_, __) =>
            {
                _fileAdded = true;
                return(DummyString);
            };
        }