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 ShowApprovalNotificationTest() { using (new SPEmulators.SPEmulationContext(SPEmulators.IsolationLevel.Fake)) { ShimSPWeb web = new ShimSPWeb() { CurrentUserGet = () => { return(new ShimSPUser() { IDGet = () => { return 1073741823; } }); }, SiteGet = () => { return(new ShimSPSite() { IDGet = () => { return Guid.Parse("D4A8A5A3-5C26-45D0-876C-AC2B4FB86D03"); }, WebApplicationGet = () => { var webApp = new ShimSPWebApplication(); var persistedObject = new ShimSPPersistedObject(webApp); persistedObject.IdGet = () => { return Guid.Parse("D4A8A5A3-5C26-45D0-876C-AC2B4FB86DAA"); }; return webApp; } }); }, RoleDefinitionsGet = () => { return(new ShimSPRoleDefinitionCollection().Bind( new List <SPRoleDefinition> { new ShimSPRoleDefinition() { NameGet = () => "Contribute2" }.Instance })); } }; new ShimSPSecurableObject(web).AllRolesForCurrentUserGet = () => new ShimSPRoleDefinitionBindingCollection().Bind( new List <SPRoleDefinition> { new ShimSPRoleDefinition() { NameGet = () => "Contribute2" }.Instance }); ShimQueryExecutor.ConstructorSPWeb = (instance, spweb) => { ShimQueryExecutor moledInstance = new ShimQueryExecutor(instance); moledInstance.ExecuteReportingDBQueryStringIDictionaryOfStringObject = (str1, dict) => { DataTable dt = new DataTable(); DataRow newRow = dt.NewRow(); DataColumn newColumn = new DataColumn("SharePointAccountID"); dt.Columns.Add(newColumn); newRow["SharePointAccountID"] = "1073741823"; dt.Rows.Add(newRow); return(dt); }; }; ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = (w) => { w(); }; ShimCoreFunctions.getConnectionStringGuid = (guid) => { return("Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;"); }; ShimSqlConnection.ConstructorString = (instance, connString) => { var connection = new ShimSqlConnection(instance); connection.Open = () => { }; connection.Close = () => { }; }; ShimSqlCommand.ConstructorStringSqlConnection = (instance, cmdText, sqlConnection) => { ShimSqlCommand sqlCommand = new ShimSqlCommand(instance); sqlCommand.ParametersGet = () => { var realSqlCommand = new SqlCommand(); return(realSqlCommand.Parameters); }; sqlCommand.ExecuteScalar = () => { return(2); }; }; var data = "<ApprovalNotification PeriodId='1'/>"; TimesheetAPI.RoleChecker = new TestRoleChecker(); var result = TimesheetAPI.ShowApprovalNotification(data, web); Assert.AreEqual("<ApprovalNotification Status=\"0\" IsTimeSheetManager=\"True\" IsProjectManager=\"False\">2</ApprovalNotification>", result); } }