private void InitializeSharePoint() { var shimSpWebApplication = new ShimSPWebApplication(); var shimSpPersistedObject = new ShimSPPersistedObject(shimSpWebApplication) { IdGet = () => SpWebApplicationId }; var shimSpSite = new ShimSPSite() { IDGet = () => SpSiteId, WebApplicationGet = () => shimSpWebApplication.Instance }; var shimSpWeb = new ShimSPWeb() { IDGet = () => SpWebId, UrlGet = () => WebUrl, ServerRelativeUrlGet = () => ServerRelativeUrl, CurrentUserGet = () => new ShimSPUser() { IDGet = () => UserId } }; var shimSpContext = new ShimSPContext() { SiteGet = () => shimSpSite, WebGet = () => shimSpWeb }; ShimSPContext.CurrentGet = () => shimSpContext; _spContextCurrent = shimSpContext.Instance; }
private static ShimSPListItem CreateShimSpListItem(Guid webApplicationId) { var webAppShim = new ShimSPWebApplication(); var persistentObject = new ShimSPPersistedObject(webAppShim); persistentObject.IdGet = () => webApplicationId; return(new ShimSPListItem { IDGet = () => ListItemId, ParentListGet = () => { return new ShimSPList { IDGet = () => _listParentListId, ParentWebGet = () => { return new ShimSPWeb { IDGet = () => _parentWebId, SiteGet = () => { return new ShimSPSite { IDGet = () => _parentWebSiteId, WebApplicationGet = () => { return webAppShim; } }; } }; }, FormsGet = () => { var formCollection = new ShimSPFormCollection { ItemGetPAGETYPE = formId => { return new ShimSPForm { UrlGet = () => { return "valera.com"; } }; } }; return formCollection; } }; } }); }
public void SetUp() { _shimsContext = ShimsContext.Create(); _adoShims = AdoShims.ShimAdoNetCalls(); _sharepointShims = SharepointShims.ShimSharepointCalls(); _testObj = new adminconns(); _privateObj = new PrivateObject(_testObj); ShimCoreFunctions.getConnectionStringGuid = (guid) => TestConnectionString; var webApp = new ShimSPWebApplication(); var persistedObject = new ShimSPPersistedObject(webApp); persistedObject.IdGet = () => Guid.Parse(WebAppId); _webAppSelector = new StubWebApplicationSelector { GetItem01 = () => webApp }; }
public void SendEmail_DisposesProperly() { // Arrange var writerDisposeCalled = false; var smtpDisposeCalled = false; var sendCalled = false; ShimSmtpClient.AllInstances.SendMailMessage = (_1, _2) => { if (smtpDisposeCalled) { throw new InvalidOperationException("Smtp Client shouldn't dispose before sending"); } sendCalled = true; }; ShimSmtpClient.AllInstances.Dispose = _ => smtpDisposeCalled = true; ShimMailMessage.AllInstances.Dispose = _ => { if (!smtpDisposeCalled || !sendCalled) { throw new InvalidOperationException("Mail Message can only be disposed after client send message and properly disposed"); } writerDisposeCalled = true; }; ShimSPAdministrationWebApplication.LocalGet = () => { var spAdministrationWebApplication = new ShimSPAdministrationWebApplication(); var spWebApplication = new ShimSPWebApplication(spAdministrationWebApplication) { OutboundMailServiceInstanceGet = () => { var spOutboundMailServiceInstance = new ShimSPOutboundMailServiceInstance(); var spServiceInstance = new ShimSPServiceInstance(spOutboundMailServiceInstance) { ServerGet = () => { var spServer = new ShimSPServer(); var spPersistedOb = new ShimSPPersistedObject(spServer) { NameGet = () => DummyServerName }; return(spServer); } }; return(spOutboundMailServiceInstance); } }; return(spAdministrationWebApplication); }; ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = code => code(); // Act _privateObject.Invoke( SendEmailMethodName, DummyUserEmail, DummyFromEmail, DummySubject, DummyUserDisplayName); // Assert this.ShouldSatisfyAllConditions( () => writerDisposeCalled.ShouldBeTrue(), () => smtpDisposeCalled.ShouldBeTrue(), () => sendCalled.ShouldBeTrue()); }
private void ShimIQueueItemMessage() { ShimSPSite.ConstructorGuid = (site, _) => { var shimSite = new ShimSPSite(site) { OpenWebGuid = webGuid => { if (webGuid == _oWebId) { return(new ShimSPWeb { IDGet = () => Guid.NewGuid(), SiteGet = () => new ShimSPSite { IDGet = () => Guid.NewGuid() }, ListsGet = () => new ShimSPListCollection { ItemGetGuid = key => { if (key == new Guid(ListId)) { return new ShimSPList { GetItemByIdInt32 = id => { if (id == ItemId) { return CreateShimSpListItem(_webAppGuid1); } return null; } }; } else { return null; } }, TryGetListString = key => { if (key == ListName) { return new ShimSPList { GetItemByIdInt32 = id => { if (id == ItemId) { return CreateShimSpListItem(_webAppGuid2); } return null; } }; } else { return null; } } } }); } else { return(new ShimSPWeb { IDGet = () => Guid.NewGuid(), SiteGet = () => new ShimSPSite { IDGet = () => Guid.NewGuid() }, ListsGet = () => new ShimSPListCollection { ItemGetGuid = key => { if (key == new Guid(ListId)) { return new ShimSPList { GetItemByIdInt32 = id => { if (id == ItemId) { return CreateShimSpListItem(_webAppGuid3); } return null; } }; } else { return null; } }, TryGetListString = key => { if (key == ListName) { return new ShimSPList { GetItemByIdInt32 = id => { if (id == ItemId) { return CreateShimSpListItem(_webAppGuid4); } return null; } }; } else { return null; } } } }); } }, WebApplicationGet = () => { var shimSPWebApplication = new ShimSPWebApplication(); var shimSPWebApplicationPersistedObject = new ShimSPPersistedObject(shimSPWebApplication) { IdGet = () => Guid.NewGuid() }; return(shimSPWebApplication); } }; }; _createdConnection = null; ShimSqlConnection.ConstructorString = (connection, _) => { _createdConnection = connection; }; ShimGetCoreInformation(); _openedConnection = null; ShimSqlConnection.AllInstances.Open = connection => { _openedConnection = connection; }; _closedConnection = null; ShimSqlConnection.AllInstances.Close = (connection) => { _closedConnection = connection; }; _disposedConnection = null; ShimSqlConnection.AllInstances.DisposeBoolean = (connection, disposing) => { _disposedConnection = connection; }; _createdCommands = new List <SqlCommand>(); ShimSqlCommand.ConstructorStringSqlConnection = (command, text, conn) => { command.Connection = conn; command.CommandText = text; _createdCommands.Add(command); }; ShimSqlCommand.Constructor = command => { _createdCommands.Add(command); }; _executeReaderCommandsCalled = new List <SqlCommand>(); ShimSqlCommand.AllInstances.ExecuteReader = command => { _executeReaderCommandsCalled.Add(command); var shimReader = new ShimSqlDataReader { Read = () => { return(true); }, GetGuidInt32 = _ => { var readerGuid = new Guid("E2954076-F6FD-4FFE-9B10-642C9D08368F"); return(readerGuid); } }; return(shimReader); }; _executeNonQueryCommands = new List <SqlCommand>(); ShimSqlCommand.AllInstances.ExecuteNonQuery = command => { _executeNonQueryCommands.Add(command); return(0); }; _disposedCommands = new List <SqlCommand>(); ShimSqlCommand.AllInstances.DisposeBoolean = (command, disposing) => { _disposedCommands.Add(command); }; _dataSetCommands = new List <SqlCommand>(); ShimDbDataAdapter.AllInstances.FillDataSet = (adapter, dataSet) => { var command = (SqlCommand)adapter.SelectCommand; _dataSetCommands.Add(command); var userTable = new DataTable(); userTable.Columns.Add("userid", typeof(string)); var userRow = userTable.NewRow(); userRow["userid"] = "177"; userTable.Rows.Add(userRow); dataSet.Tables.Add(userTable); return(0); }; }
private string ProcessNewSaveRequest(bool hasPermission) { PrivateType objToTestPrivateMethod = new PrivateType(typeof(EPMLiveCore.API.MyWork)); using (new SPEmulators.SPEmulationContext(SPEmulators.IsolationLevel.Fake)) { ShimSPWeb fakespweb = fakespweb = new ShimSPWeb() { IDGet = () => { return(Guid.Parse("D4A8A5A3-5C26-45D0-876C-AC2B4FB86D03")); }, CurrentUserGet = () => { return(new ShimSPUser() { IDGet = () => { return 1073741823; } }); }, SiteGet = () => { return(new ShimSPSite() { UrlGet = () => { return ""; }, OpenWebGuid = (gg) => { return new ShimSPWeb() { IDGet = () => { return Guid.Parse("D4A8A5A3-5C26-45D0-876C-AC2B4FB86D03"); }, PropertiesGet = () => { var propertyBag = new ShimSPPropertyBag(); var sd = new ShimStringDictionary(propertyBag); sd.ItemGetString = (key) => { return "EPMLive_MyWork_Grid_GlobalViews"; }; return propertyBag; }, SiteGet = () => { return new ShimSPSite() { IDGet = () => { return Guid.Parse("D4A8A5A3-5C26-45D0-876C-AC2B4FB86D03"); } }; }, Dispose = () => { }, AllowUnsafeUpdatesSetBoolean = (b) => { } }; }, RootWebGet = () => { return new ShimSPWeb() { IDGet = () => { return Guid.Parse("D4A8A5A3-5C26-45D0-876C-AC2B4FB86D03"); } }; } }); }, ParentWebGet = () => { return(null); }, PropertiesGet = () => { var propertyBag = new ShimSPPropertyBag(); var sd = new ShimStringDictionary(propertyBag); sd.ItemGetString = (key) => { return("EPMLiveLockConfig"); }; return(propertyBag); } }; fakespweb.Dispose = () => { }; ShimSPSite.ConstructorString = (instance, url) => { ShimSPSite moledInstance = new ShimSPSite(instance); moledInstance.Dispose = () => { }; ShimSPSite.AllInstances.OpenWeb = (ins) => { return(fakespweb); }; }; ShimSPSite.ConstructorGuid = (instance, url) => { ShimSPSite moledInstance = new ShimSPSite(instance) { 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); } }; moledInstance.Dispose = () => { }; ShimSPSite.AllInstances.OpenWeb = (ins) => { return(fakespweb); }; }; ShimCoreFunctions.iGetConfigSettingSPWebStringBooleanBoolean = (p1, p2, p3, p4) => { return("<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<ArrayOfMyWorkGridView xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n <MyWorkGridView>\r\n <Cols>Flag:30,Work0000Type:131,Project:116,DueDate:100,WorkingOn:85</Cols>\r\n <Default>false</Default>\r\n <Filters>0|WorkingOn:1:11</Filters>\r\n <Grouping>0|</Grouping>\r\n <Id>7e9399ec83ae91854b600b808918b3c4</Id>\r\n <LeftCols>Complete:20,CommentCount:36,Priority:25,Title:222</LeftCols>\r\n <Name>Working On It</Name>\r\n <Personal>false</Personal>\r\n <RightCols />\r\n <Sorting>DueDate</Sorting>\r\n <HasPermission>false</HasPermission>\r\n </MyWorkGridView>\r\n <MyWorkGridView>\r\n <Cols>Work0000Type:89,StartDate:97,DueDate:131,Status:38,PercentComplete:113,Flag:41,Project:83,WorkingOn:86</Cols>\r\n <Default>false</Default>\r\n <Filters>0|</Filters>\r\n <Grouping>0|Due</Grouping>\r\n <Id>0007b12319302de33f227d1e08e089be</Id>\r\n <LeftCols>Complete:20,CommentCount:36,Priority:25,Title:213</LeftCols>\r\n <Name>My Work by Due</Name>\r\n <Personal>false</Personal>\r\n <RightCols />\r\n <Sorting>DueDate</Sorting>\r\n <HasPermission>false</HasPermission>\r\n </MyWorkGridView>\r\n <MyWorkGridView>\r\n <Cols>Work0000Type:119,Due:98,StartDate:83,DueDate:112,Work:33,Status:56,PercentComplete:113,Flag:44,WorkingOn:86</Cols>\r\n <Default>false</Default>\r\n <Filters>0|</Filters>\r\n <Grouping>0|Project</Grouping>\r\n <Id>2ba87d5cf4822160e548843193ad30db</Id>\r\n <LeftCols>Complete:20,CommentCount:36,Priority:25,Title:140</LeftCols>\r\n <Name>My Work by Project</Name>\r\n <Personal>false</Personal>\r\n <RightCols />\r\n <Sorting>DueDate,Due</Sorting>\r\n <HasPermission>false</HasPermission>\r\n </MyWorkGridView>\r\n <MyWorkGridView>\r\n <Cols>DueDate:58,WorkingOn:100</Cols>\r\n <Default>false</Default>\r\n <Filters>0|</Filters>\r\n <Grouping>0|</Grouping>\r\n <Id>0111d91d9fc6c72b3fe349a55e89048a</Id>\r\n <LeftCols>Complete:25,CommentCount:36,Priority:25,Title:601</LeftCols>\r\n <Name>Work Summary</Name>\r\n <Personal>false</Personal>\r\n <RightCols />\r\n <Sorting>DueDate</Sorting>\r\n <HasPermission>false</HasPermission>\r\n </MyWorkGridView>\r\n <MyWorkGridView>\r\n <Cols />\r\n <Default>false</Default>\r\n <Filters>0|</Filters>\r\n <Grouping>0|</Grouping>\r\n <Id>57bcc4f29adfe3c1f09d7e29e7128bdb</Id>\r\n <LeftCols>Complete:25,CommentCount:36,Priority:25,Title:570</LeftCols>\r\n <Name>gg3</Name>\r\n <Personal>false</Personal>\r\n <RightCols>Flag:30,Work0000Type:125,Project:90,DueDate:100,WorkingOn:87</RightCols>\r\n <Sorting>DueDate</Sorting>\r\n <HasPermission>true</HasPermission>\r\n </MyWorkGridView>\r\n <MyWorkGridView>\r\n <Cols />\r\n <Default>false</Default>\r\n <Filters>0|</Filters>\r\n <Grouping>0|</Grouping>\r\n <Id>dv</Id>\r\n <LeftCols>Complete:25,CommentCount:36,Priority:25,Title:570</LeftCols>\r\n <Name>Default View</Name>\r\n <Personal>false</Personal>\r\n <RightCols>Flag:30,Work0000Type:125,Project:90,DueDate:100,WorkingOn:87</RightCols>\r\n <Sorting>DueDate</Sorting>\r\n <HasPermission>true</HasPermission>\r\n </MyWorkGridView>\r\n <MyWorkGridView>\r\n <Cols />\r\n <Default>true</Default>\r\n <Filters>0|</Filters>\r\n <Grouping>0|</Grouping>\r\n <Id>ec6ef230f1828039ee794566b9c58adc</Id>\r\n <LeftCols>Complete:25,CommentCount:36,Priority:25,Title:570</LeftCols>\r\n <Name>p1</Name>\r\n <Personal>true</Personal>\r\n <RightCols>Flag:30,Work0000Type:125,Project:90,DueDate:100,WorkingOn:87</RightCols>\r\n <Sorting>DueDate</Sorting>\r\n <HasPermission>true</HasPermission>\r\n </MyWorkGridView>\r\n</ArrayOfMyWorkGridView>"); }; ShimSPContext.CurrentGet = () => { return(new ShimSPContext() { WebGet = () => { return fakespweb; } }); }; ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = (w) => { w(); }; ShimCoreFunctions.getConnectionStringGuid = (guid) => { return("Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;"); }; var openedConnections = 0; var closedConnections = 0; ShimSqlConnection.ConstructorString = (instance, connString) => { var connection = new ShimSqlConnection(instance); connection.Open = () => { openedConnections++; }; connection.Close = () => { closedConnections++; }; }; ShimSqlCommand.ConstructorStringSqlConnection = (instance, cmdText, sqlConnection) => { ShimSqlCommand sqlCommand = new ShimSqlCommand(instance); sqlCommand.ParametersGet = () => { var realSqlCommand = new SqlCommand(); return(realSqlCommand.Parameters); }; sqlCommand.ExecuteScalar = () => { return("<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<ArrayOfMyWorkGridView xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n <MyWorkGridView>\r\n <Cols />\r\n <Default>false</Default>\r\n <Filters>0|</Filters>\r\n <Grouping>0|</Grouping>\r\n <Id>7d7f7e971ca8152804ad89b891fba0b4</Id>\r\n <LeftCols>Complete:25,CommentCount:36,Priority:25,Title:554</LeftCols>\r\n <Name>gg2</Name>\r\n <Personal>true</Personal>\r\n <RightCols>Flag:30,Work0000Type:125,Project:90,DueDate:100,WorkingOn:87</RightCols>\r\n <Sorting>DueDate</Sorting>\r\n <HasPermission>true</HasPermission>\r\n </MyWorkGridView>\r\n <MyWorkGridView>\r\n <Cols />\r\n <Default>false</Default>\r\n <Filters>0|</Filters>\r\n <Grouping>0|</Grouping>\r\n <Id>57bcc4f29adfe3c1f09d7e29e7128bdb</Id>\r\n <LeftCols>Complete:25,CommentCount:36,Priority:25,Title:554</LeftCols>\r\n <Name>gg3</Name>\r\n <Personal>true</Personal>\r\n <RightCols>Flag:30,Work0000Type:125,Project:90,DueDate:100,WorkingOn:87</RightCols>\r\n <Sorting>DueDate</Sorting>\r\n <HasPermission>true</HasPermission>\r\n </MyWorkGridView>\r\n <MyWorkGridView>\r\n <Cols />\r\n <Default>true</Default>\r\n <Filters>0|</Filters>\r\n <Grouping>0|</Grouping>\r\n <Id>ec6ef230f1828039ee794566b9c58adc</Id>\r\n <LeftCols>Complete:25,CommentCount:36,Priority:25,Title:570</LeftCols>\r\n <Name>p1</Name>\r\n <Personal>true</Personal>\r\n <RightCols>Flag:30,Work0000Type:125,Project:90,DueDate:100,WorkingOn:87</RightCols>\r\n <Sorting>DueDate</Sorting>\r\n <HasPermission>true</HasPermission>\r\n </MyWorkGridView>\r\n</ArrayOfMyWorkGridView>"); }; sqlCommand.ExecuteNonQuery = () => { return(1); }; }; var data = "<MyWork><View ID=\"73c18c59a39b18382081ec00bb456d43\" Name=\"gg\" Default=\"true\" Personal=\"false\" HasPermission=\"" + hasPermission.ToString() + "\" LeftCols=\"Complete:25,CommentCount:36,Priority:25,Title:570\" Cols=\"\" RightCols=\"Flag:30,Work0000Type:125,Project:90,DueDate:100,WorkingOn:87\" Filters=\"0|\" Grouping=\"0|\" Sorting=\"DueDate\"/></MyWork>"; string result = ""; result = objToTestPrivateMethod.InvokeStatic("SaveMyWorkGridView", data) as string; Assert.AreEqual(openedConnections, closedConnections); return(result); } }
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); } }