private static void ShimSpSiteObject() { var shimRootWeb = new ShimSPWeb(); shimRootWeb.TitleGet = () => RootWebTitle; var webList = new List <SPWeb>() { new ShimSPWeb() { TitleGet = () => WebTitle01 }.Instance }; var shimAllWebs = new ShimSPWebCollection() { CountGet = () => webList.Count }; var shimAllWebsBase = new ShimSPBaseCollection(shimAllWebs.Instance) { GetEnumerator = () => webList.GetEnumerator() }; ShimSPSite.AllInstances.RootWebGet = _ => shimRootWeb.Instance; ShimSPSite.AllInstances.AllWebsGet = _ => shimAllWebs.Instance; ShimSPSite.AllInstances.UrlGet = _ => SiteUrl; }
public void Returns(IList <SPWebSubstitute> webs) { Substitute.Actions.Add(delegate { SetFakesDelegate(() => { var shim = new ShimSPWebCollection(); var webTemplates = webs.Select(x => x.SpType); shim.Bind(webTemplates); shim.ItemGetInt32 = i => webs[i].SpType; return(shim); }); }); }
public void TestShowingMoreRealisticCollectionExpectations() { // Arrange. int count = 4; using (new SharePointEmulationScope()) { ShimSPWeb web = new ShimSPWeb(); ShimSPWebCollection webCollection = new ShimSPWebCollection(); webCollection.CountGet = () => count; web.WebsGet = () => webCollection; ShimSPSite.ConstructorString = (instance, url) => { ShimSPSite site = new ShimSPSite(instance); site.Dispose = () => { }; site.OpenWeb = () => web; }; WebSiteManager manager = new WebSiteManager("http://test"); // Act. int resultCount = manager.GetNumberOfSubSites(); // Assert. Assert.AreEqual(count, resultCount); } }
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; } }); }
public void Execute_Always_SetExpectedValues() { // Arrange var shimSpWeb = ArrangeForExecute(); var shim = new ShimSPWebCollection(); var list = new List <SPWeb> { ArrangeForExecute() }; new ShimSPBaseCollection(shim) { GetEnumerator = () => list.GetEnumerator() }; shimSpWeb.WebsGet = () => shim; var shimSite = new ShimSPSite { RootWebGet = () => shimSpWeb }; ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = codeToRun => codeToRun(); ShimSPAdministrationWebApplication.LocalGet = () => { var shimSPAdministrationWebApplication = new ShimSPAdministrationWebApplication(); new ShimSPWebApplication(shimSPAdministrationWebApplication) { OutboundMailServiceInstanceGet = () => { var shimSPOutboundMailServiceInstance = new ShimSPOutboundMailServiceInstance(); new ShimSPServiceInstance(shimSPOutboundMailServiceInstance) { ServerGet = () => { var shimSPServer = new ShimSPServer(); new ShimSPPersistedObject(shimSPServer) { NameGet = () => "SPPersistedObject" }; return(shimSPServer); } }; return(shimSPOutboundMailServiceInstance); } }; return(shimSPAdministrationWebApplication); }; ShimMailAddress.ConstructorString = (instance, address) => new ShimMailAddress(instance); ShimSmtpClient.Constructor = instance => new ShimSmtpClient(instance) { SendMailMessage = mailMessage => { } }; ShimSqlConnection.AllInstances.Open = instance => { }; ShimSqlCommand.AllInstances.ExecuteNonQuery = instance => 0; var data = string.Empty; _notifications.EmailSubject = null; _notifications.FromEmail = null; _notifications.LogDetailedErrors = true; // Act _notifications.execute( shimSite, shimSpWeb, data); // Assert this.ShouldSatisfyAllConditions( () => ((string)_privateObject.GetFieldOrProperty("sMainURL")).ShouldBe(SpWebUrl), () => _notifications.FromEmail.ShouldBe("EPMLiveNotificationEmail"), () => _notifications.EmailSubject.ShouldBe("EPMLiveNotificationEmailSubject"), () => _notifications.LogDetailedErrors.ShouldBeFalse(), () => _notifications.ErrorLogDetailLevel.ShouldBe(ErrorLogDetailLevelEnum.SectionLevelErrors)); }