Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        public void ShouldReturnListItemFromPropertiesIfNoCache()
        {
            var listItemMock = new ShimSPListItem();

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

            listItem.ShouldBe(listItemMock);
        }
 /// <summary>
 /// An item is being updated.
 /// </summary>
 public override void ItemUpdating(SPItemEventProperties properties)
 {
     try
     {
         var listItem = SaveDataJobExecuteCache.GetListItem(properties);
         if ((string)properties.AfterProperties["Status"] != (string)listItem["Status"])
         {
             if ((string)properties.AfterProperties["Status"] == "Completed")
             {
                 properties.AfterProperties["PercentComplete"] = "1";
             }
             else if ((string)properties.AfterProperties["Status"] == "In Progress")
             {
                 if ((string)properties.AfterProperties["PercentComplete"] == "0" || (string)properties.AfterProperties["PercentComplete"] == "1" || Convert.ToString(properties.AfterProperties["PercentComplete"]) == "")
                 {
                     properties.AfterProperties["PercentComplete"] = "0.5";
                 }
             }
             else if ((string)properties.AfterProperties["Status"] == "Not Started")
             {
                 properties.AfterProperties["PercentComplete"] = "0";
             }
         }
         else if ((string)properties.AfterProperties["PercentComplete"] != Convert.ToString(listItem["PercentComplete"]))
         {
             if ((string)properties.AfterProperties["PercentComplete"] == "0")
             {
                 properties.AfterProperties["Status"] = "Not Started";
             }
             else if (float.Parse((string)properties.AfterProperties["PercentComplete"]) > 0.00 & float.Parse((string)properties.AfterProperties["PercentComplete"]) < 1.00)
             {
                 properties.AfterProperties["Status"] = "In Progress";
             }
             else if ((string)properties.AfterProperties["PercentComplete"] == "1")
             {
                 properties.AfterProperties["Status"] = "Completed";
             }
         }
     }
     catch { }
 }