Exemple #1
0
        public void ShouldCallCallbackIfNoCache()
        {
            var siteMock = new ShimSPSite();
            var site     = SaveDataJobExecuteCache.GetSiteFromCache(Guid.Empty, false, () => siteMock);

            site.ShouldBe(siteMock);

            site = SaveDataJobExecuteCache.GetSiteFromCache(Guid.Empty, true, () => siteMock);
            site.ShouldBe(siteMock);
        }
Exemple #2
0
        public void ShouldCallCallbackIfSiteOfDifferentId()
        {
            using (SaveDataJobExecuteCache.InitializeCache(new ShimSPSite()))
            {
                var siteId   = Guid.NewGuid();
                var siteMock = new ShimSPSite {
                    IDGet = () => siteId
                };
                var site = SaveDataJobExecuteCache.GetSiteFromCache(siteId, false, () => siteMock);
                site.ShouldBe(siteMock);

                site = SaveDataJobExecuteCache.GetSiteFromCache(siteId, true, () => siteMock);
                site.ShouldBe(siteMock);
            }
        }
Exemple #3
0
        public void ShouldReturnOriginalSiteForNonElevated()
        {
            var siteMock = new ShimSPSite();

            using (SaveDataJobExecuteCache.InitializeCache(siteMock))
            {
                var site = SaveDataJobExecuteCache.GetSiteFromCache(Guid.Empty, false, () =>
                {
                    Assert.Fail();
                    return(null);
                });

                site.ShouldBe(siteMock);
            }
        }
Exemple #4
0
        public void ShouldReturnElevatedOnRequest()
        {
            var        siteMock         = new ShimSPSite();
            ShimSPSite siteMockElevated = null;

            ShimSPSite.ConstructorGuid = (site, guid) => { siteMockElevated = new ShimSPSite(site); };
            ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = cb => cb();
            using (SaveDataJobExecuteCache.InitializeCache(siteMock))
            {
                var site = SaveDataJobExecuteCache.GetSiteFromCache(Guid.Empty, true, () =>
                {
                    Assert.Fail();
                    return(null);
                });

                site.ShouldSatisfyAllConditions(
                    () => site.ShouldNotBeNull(),
                    () => site.ShouldBe(siteMockElevated),
                    () => site.ShouldNotBe(siteMock));
            }
        }