public void GetResourceWithDuplicateEmail_IsAddFalseisOnlineFalse_ReturnsListItemCollection()
        {
            // Arrange
            const bool isAdd    = false;
            const bool isOnline = false;

            var properties = new ShimSPItemEventProperties()
            {
                WebGet      = () => spWeb,
                ListGet     = () => spList,
                ListItemGet = () => spListItem
            };

            spList.GetItemsSPQuery = _ => new ShimSPListItemCollection()
            {
                CountGet     = () => 10,
                ItemGetInt32 = __ => spListItem
            };

            // Act
            var actual = (SPListItemCollection)privateObject.Invoke(
                GetResourceWithDuplicateEmailMethodName,
                BindingFlags.Static | BindingFlags.NonPublic,
                new object[] { properties.Instance, isAdd, isOnline, string.Empty, spUser.Instance });

            // Assert
            actual.Count.ShouldBe(10);
        }
Exemple #2
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);
            }
        }
Exemple #3
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);
            }
        }
Exemple #4
0
        public void ShouldReturnListItemFromPropertiesIfNoCache()
        {
            var listItemMock = new ShimSPListItem();

            var properties = new ShimSPItemEventProperties {
                ListItemGet = () => listItemMock
            };
            var listItem = SaveDataJobExecuteCache.GetListItem(properties);

            listItem.ShouldBe(listItemMock);
        }
Exemple #5
0
        public void ShouldReturnListFromPropertiesIfItIsNotFoundInCache()
        {
            var          siteMock = new ShimSPSite();
            const string TestUrl  = "test/url";
            var          listMock = new ShimSPList();

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

                list.ShouldBe(listMock);
            }
        }
        public void EnsureNoDuplicates_WhenCalled_EnsuresNoDuplicates()
        {
            // Arrange
            var validation = false;
            var properties = new ShimSPItemEventProperties()
            {
                AfterPropertiesGet = () => new ShimSPItemEventDataCollection()
                {
                    ItemGetString = input =>
                    {
                        throw new Exception();
                    }
                },
                ListItemGet = () => new ShimSPListItem()
                {
                    ItemGetString = input =>
                    {
                        if (input.Equals("Generic"))
                        {
                            throw new Exception();
                        }

                        return(DummyString);
                    }
                }
            };

            ShimCoreFunctions.GetResourceWithDuplicateEmailSPItemEventPropertiesBooleanBooleanStringSPUserOut =
                (SPItemEventProperties propertiesParam, Boolean isAdd, Boolean isOnline, string sharePointAccount, out SPUser u) =>
            {
                validation = true;
                u          = null;
                return(new ShimSPListItemCollection()
                {
                    CountGet = () => 0
                });
            };

            // Act
            privateObject.Invoke(
                EnsureNoDuplicatesMethodName,
                BindingFlags.Static | BindingFlags.Public,
                new object[] { properties.Instance, true, true });

            // Assert
            validation.ShouldBeTrue();
        }