private void SetupProcessSecurityGroupsShims() { var groupList = new List <SPGroup>(); var shimSpGroupCollection = new ShimSPGroupCollection(); var shimSpBaseGroupCollection = new ShimSPBaseCollection(shimSpGroupCollection.Instance) { GetEnumerator = () => groupList.GetEnumerator() }; var userList = new List <SPUser>(); var shimSpUserCollection = new ShimSPUserCollection() { GetByIDInt32 = userId => new ShimSPUser() { IDGet = () => userId, GroupsGet = () => shimSpGroupCollection.Instance } }; var shimSpBaseUserCollection = new ShimSPBaseCollection(shimSpUserCollection.Instance) { GetEnumerator = () => userList.GetEnumerator() }; var shimRootWeb = new ShimSPWeb(_spShims.SiteShim.Instance.RootWeb) { SiteGroupsGet = () => shimSpGroupCollection.Instance, SiteUsersGet = () => shimSpUserCollection.Instance }; ShimSqlBulkCopy.AllInstances.WriteToServerDataTable = (_1, _2) => { }; }
public void TestGetUsersForSiteReturnsLoginNamesOfAllDefinedUsers() { // Arrange. using (new SharePointEmulationScope()) { ShimSPUser user1 = new ShimSPUser() {LoginNameGet = () => @"DOMAIN\user1"}; ShimSPUser user2 = new ShimSPUser() {LoginNameGet = () => @"EXTERNAL\some.user"}; ShimSPUser user3 = new ShimSPUser() {LoginNameGet = () => "*****@*****.**"}; ShimSPUser user4 = new ShimSPUser() {LoginNameGet = () => "mike.test"}; List<ShimSPUser> masterUsers = new List<ShimSPUser>() { user1, user2, user3, user4 }; ShimSPWeb web = new ShimSPWeb(); ShimSPUserCollection coll = new ShimSPUserCollection(); coll.CountGet = () => masterUsers.Count; coll.GetByIDInt32 = (id) => masterUsers.ElementAt(id); coll.ItemGetInt32 = (id) => masterUsers.ElementAt(id); coll.ItemAtIndexInt32 = (id) => masterUsers.ElementAt(id); web.UsersGet = () => coll; ShimSPSite.ConstructorString = (instance, url) => { ShimSPSite site = new ShimSPSite(instance); site.Dispose = () => { }; site.OpenWeb = () => web; }; WebSiteManager manager = new WebSiteManager("http://test"); // Act. IEnumerable<string> users = manager.GetUsersForSite(); // Assert. Assert.IsTrue(users.Contains(user1.Instance.LoginName)); Assert.IsTrue(users.Contains(user2.Instance.LoginName)); Assert.IsTrue(users.Contains(user3.Instance.LoginName)); Assert.IsTrue(users.Contains(user4.Instance.LoginName)); } }
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; } }); }
private static void PrepareShims(string listTitle, bool generateQueryExecutorError = false) { System.Web.Fakes.ShimHttpContext.AllInstances.ItemsGet = (e) => { return(new Dictionary <string, object>()); }; System.Web.Fakes.ShimHttpContext.CurrentGet = () => { return(new System.Web.Fakes.ShimHttpContext()); }; System.Web.Fakes.ShimHttpContext.AllInstances.DisableCustomHttpEncoderGet = (instance) => { return(true); }; string expectedTitle = "Test Site"; ShimSPSite.BehaveAsNotImplemented(); ShimSPWeb.BehaveAsNotImplemented(); ShimSPSite.ConstructorString = (instance, url) => { ShimSPSite moledInstance = new ShimSPSite(instance); moledInstance.Dispose = () => { }; moledInstance.OpenWeb = () => { ShimSPWeb web = new ShimSPWeb(); web.Dispose = () => { }; web.UsersGet = () => { ShimSPUserCollection users = new ShimSPUserCollection(); users.CountGet = () => 0; return(users); }; return(web); }; }; ShimSPSite.ConstructorGuid = (instance, guid) => { ShimSPSite moledInstance = new ShimSPSite(instance); moledInstance.Dispose = () => { }; moledInstance.OpenWebGuid = (guid1) => { ShimSPWeb web = new ShimSPWeb(); web.Dispose = () => { }; web.UsersGet = () => { ShimSPUserCollection users = new ShimSPUserCollection(); users.CountGet = () => 0; return(users); }; web.ListsGet = () => { ShimSPListCollection lists = new ShimSPListCollection(); lists.ItemGetGuid = (guid2) => { ShimSPList list = new ShimSPList(); list.TitleGet = () => { return(listTitle); }; list.HiddenGet = () => { return(false); }; return(list); }; return(lists); }; return(web); }; }; ShimSPSite.AllInstances.Dispose = (instance) => { }; ShimSPSite.AllInstances.OpenWeb = (instance) => { ShimSPWeb web = new ShimSPWeb(); web.Dispose = () => { }; web.TitleGet = () => expectedTitle; return(web); }; ShimQueryExecutor.ConstructorSPWeb = (instance, spweb) => { ShimQueryExecutor moledInstance = new ShimQueryExecutor(instance); //moledInstance.Dispose = () => { }; moledInstance.ExecuteEpmLiveQueryStringIDictionaryOfStringObject = (str1, dict) => { if (generateQueryExecutorError) { throw new NotImplementedException("message"); } DataTable dt = new DataTable(); DataRow newRow = dt.NewRow(); DataColumn newColumn = new DataColumn("CustomerID"); dt.Columns.Add(newColumn); newRow["CustomerID"] = "ALFKI"; dt.Rows.Add(newRow); return(dt); }; }; }
public void ListIdTest() { var testParams = "<Data>" + "<Param key=\"SiteId\">7F316E11-C842-4440-9918-39A8F1C12DA9</Param>" + "<Param key=\"WebId\">1A8F7946-CCA1-4A24-8785-CE8E32D012BE</Param>" + "<Param key=\"ListId\">5D592B57-C072-4B36-8809-11262120484D</Param>" + "</Data>"; var analyticsData = new AnalyticsData(testParams, AnalyticsType.Favorite, AnalyticsAction.Read); using (new SPEmulators.SPEmulationContext(SPEmulators.IsolationLevel.Fake)) { ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = (w) => { w(); }; ShimSPSite.ConstructorGuid = (instance, guid) => { ShimSPSite moledInstance = new ShimSPSite(instance); moledInstance.Dispose = () => { }; moledInstance.OpenWebGuid = (guid1) => { ShimSPWeb web = new ShimSPWeb(); web.Dispose = () => { }; web.UsersGet = () => { ShimSPUserCollection users = new ShimSPUserCollection(); users.CountGet = () => 0; return(users); }; web.ListsGet = () => { ShimSPListCollection lists = new ShimSPListCollection(); lists.ItemGetGuid = (guid2) => { ShimSPList list = new ShimSPList(); //list.TitleGet = () => { return listTitle; }; list.HiddenGet = () => { return(false); }; return(list); }; return(lists); }; return(web); }; }; Assert.AreEqual(analyticsData.ListId, new Guid("5D592B57-C072-4B36-8809-11262120484D")); Assert.AreEqual(analyticsData.WebId, new Guid("1A8F7946-CCA1-4A24-8785-CE8E32D012BE")); Assert.AreEqual(analyticsData.SiteId, new Guid("7F316E11-C842-4440-9918-39A8F1C12DA9")); //Isolate.Fake.StaticConstructor(typeof(SPSecurity)); //Isolate.WhenCalled(() => SPSecurity.RunWithElevatedPrivileges(() => { })).DoInstead((ctx) => Console.WriteLine("called")); //var fakeSite = Isolate.Fake.NextInstance<SPSite>(); Assert.AreEqual(analyticsData.Icon, "icon-file-5"); } }