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 }; }
private void SetupForPageLoad() { var requestFormCollection = new Dictionary <string, string>() { ["Server"] = RequestServer, ["DB"] = RequestDb, ["Username"] = RequestUserName, ["Password"] = RequestPassword, ["WEBAPP"] = RequestWebApp }; var shimHttpServerUtility = new ShimHttpServerUtility(); var shimHttpRequest = new ShimHttpRequest(); shimHttpRequest.ItemGetString = key => requestFormCollection.ContainsKey(key) ? requestFormCollection[key] : string.Empty; ShimPage.AllInstances.ServerGet = _ => shimHttpServerUtility; ShimPage.AllInstances.RequestGet = _ => shimHttpRequest; var shimSpApplicationPool = new ShimSPApplicationPool(); var shimSpProcessIdentity = new ShimSPProcessIdentity(shimSpApplicationPool); shimSpProcessIdentity.UsernameGet = () => ApplicationPoolUserName; var shimSpWebApplication = new ShimSPWebApplication(); shimSpWebApplication.ApplicationPoolGet = () => shimSpApplicationPool; var shimSpWebApplicationCollection = new ShimSPWebApplicationCollection(); var shimSpPersistedObjectCollection = new ShimSPPersistedObjectCollection <SPWebApplication>(shimSpWebApplicationCollection); shimSpPersistedObjectCollection.ItemGetGuid = _ => shimSpWebApplication; var shimSpWebService = new ShimSPWebService(); shimSpWebService.WebApplicationsGet = () => shimSpWebApplicationCollection; ShimSPWebService.ContentServiceGet = () => shimSpWebService; }
public void TestInitialize() { _shimsContext = ShimsContext.Create(); _spWeb = new ShimSPWeb { CurrentUserGet = () => new ShimSPUser { LoginNameGet = () => "LoginName" }, SiteGet = () => new ShimSPSite { WebApplicationGet = () => { var shim = new ShimSPWebApplication(); new ShimSPPersistedObject(shim) { IdGet = () => Guid.Empty }; return(shim); } } }; _shimSPFieldCollection = new ShimSPFieldCollection { ItemGetGuid = guid => new ShimSPField { GetFieldValueString = stringValue => "[today]", TypeGet = () => SPFieldType.DateTime }, GetFieldByInternalNameString = stringValue => new ShimSPField { TypeGet = () => SPFieldType.Calculated, SchemaXmlGet = () => "<Default></Default>" } }; _spSite = new ShimSPSite { RootWebGet = () => _spWeb, OpenWebGuid = guid => new ShimSPWeb { IDGet = () => guid, ListsGet = () => new ShimSPListCollection { ItemGetGuid = guidValue => new ShimSPList { IDGet = () => guid, GetItemByIdInt32 = intValue => new ShimSPListItem { FieldsGet = () => _shimSPFieldCollection }, FieldsGet = () => _shimSPFieldCollection } } } }; ShimSPContext.CurrentGet = () => new ShimSPContext { SiteGet = () => _spSite, WebGet = () => _spWeb }; var shimSpView = new ShimSPView { ViewFieldsGet = () => new ShimSPViewFieldCollection() { CountGet = () => 1 } }; _shimSpList = new ShimSPList { FieldsGet = () => _shimSPFieldCollection }; _getpmapprovals = new getpmapprovals(); _privateObject = new PrivateObject(_getpmapprovals); _privateObject.SetFieldOrProperty("site", (SPSite)_spSite); _privateObject.SetFieldOrProperty("view", (SPView)shimSpView); _privateObject.SetFieldOrProperty("list", (SPList)_shimSpList); var dataSet = new DataSet(); dataSet.Tables.Add(GetDataTable("TimesheetMeta")); _privateObject.SetFieldOrProperty("dsTimesheetMeta", dataSet); ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = codeToRun => codeToRun(); }
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 void ISendEmail_Called_Disposed(bool hideFrom, string curUserEmail) { // Arrange const string outboundEmail = "*****@*****.**"; var siteId = new Guid("0E2FCE32-4507-452C-A8BF-D28C867DF0E9"); var webId = new Guid("4008FE64-56A8-4DDF-99C7-AF3C45AEBDDA"); var shimCurrentUser = new ShimSPUser { NameGet = () => "CurUserName", EmailGet = () => curUserEmail }; var currentUser = (SPUser)shimCurrentUser; var shimUser = new ShimSPUser { NameGet = () => "EUserName", EmailGet = () => "*****@*****.**" }; var user = (SPUser)shimUser; var arguments = new object[] { 1, hideFrom, siteId, webId, (SPUser)shimCurrentUser, (SPUser)shimUser, new Hashtable() { { "building", "64" } } }; ShimSPAdministrationWebApplication.LocalGet = () => { var spAdministrationWebApplication = new ShimSPAdministrationWebApplication(); var spWebApplication = new ShimSPWebApplication(spAdministrationWebApplication) { OutboundMailServiceInstanceGet = () => { var spOutboundMailServiceInstance = new ShimSPOutboundMailServiceInstance(); var spServiceInstance = new ShimSPServiceInstance(spOutboundMailServiceInstance) { ServerGet = () => new ShimSPServer { AddressGet = () => "15th ave" } }; return(spOutboundMailServiceInstance); }, OutboundMailSenderAddressGet = () => outboundEmail }; return(spAdministrationWebApplication); }; string setHost = null; MailMessage sentMessage = null; var clientDisposed = false; ShimSmtpClient.Constructor = client => { new ShimSmtpClient(client) { HostSetString = host => { setHost = host; }, SendMailMessage = message => { sentMessage = message; }, DisposeBoolean = disposing => { clientDisposed = true; } }; }; var messageDisposed = false; ShimMailMessage.AllInstances.DisposeBoolean = (message, disposing) => { messageDisposed = true; }; // Act _apiEmailPrivate.Invoke("iSendEmail", BindingFlags.Static | BindingFlags.NonPublic, arguments); // Assert AssertConnection(); if (hideFrom) { Assert.AreEqual(outboundEmail, sentMessage.From.Address); Assert.IsTrue(string.IsNullOrWhiteSpace(sentMessage.From.DisplayName)); } else if (string.IsNullOrWhiteSpace(curUserEmail)) { Assert.AreEqual(outboundEmail, sentMessage.From.Address); Assert.AreEqual(currentUser.Name, sentMessage.From.DisplayName); } else { Assert.AreEqual(currentUser.Email, sentMessage.From.Address); Assert.AreEqual(currentUser.Name, sentMessage.From.DisplayName); } Assert.AreEqual(user.Email, sentMessage.To[0].Address); Assert.AreEqual("64 house", sentMessage.Subject); Assert.AreEqual("goose live in 64 house", sentMessage.Body); Assert.IsTrue(clientDisposed); Assert.IsTrue(messageDisposed); }
private void SetupVariables() { guid = new Guid(GuidString); spSite = new ShimSPSite() { IDGet = () => guid, UrlGet = () => Url, ContentDatabaseGet = () => new ShimSPContentDatabase(), OpenWebGuid = _ => spWeb }; fields = new ShimSPFieldCollection() { ContainsFieldString = _1 => true }; spListItem = new ShimSPListItem() { IDGet = () => 1, FieldsGet = () => fields, ItemGetString = _1 => DummyString }; spList = new ShimSPList() { IDGet = () => guid, TitleGet = () => Title, GetItemsSPQuery = _ => new ShimSPListItemCollection() { FieldsGet = () => fields, GetEnumerator = () => new List <SPListItem>() { spListItem }.GetEnumerator() }, GetItemByIdInt32 = _ => spListItem }; var currentUser = new ShimSPUser() { IDGet = () => 1, LoginNameGet = () => DummyString, RegionalSettingsGet = () => new ShimSPRegionalSettings() }; spWeb = new ShimSPWeb() { CurrentUserGet = () => currentUser, SiteGet = () => spSite, TitleGet = () => Title, ServerRelativeUrlGet = () => ServerRelativeUrl, ListsGet = () => new ShimSPListCollection() { ItemGetString = _ => spList, ItemGetGuid = _ => spList, TryGetListString = _ => spList }, UrlGet = () => Url }; webApplication = new ShimSPWebApplication(); }
private void SetupShims() { _jobId = Guid.NewGuid(); _siteId = _jobId; _webId = _jobId; _listId = _jobId; _spWeb = new ShimSPWeb { SiteGet = () => new ShimSPSite { IDGet = () => _jobId }, IDGet = () => _jobId }; ShimSPSite.ConstructorGuid = (instance, _guid) => { }; ShimSPSite.AllInstances.WebApplicationGet = instance => { var webApp = new ShimSPWebApplication(); return(webApp); }; ShimSPSite.AllInstances.Dispose = instance => { }; ShimLoggingService.WriteTraceStringStringTraceSeverityString = (_, __, ___, ____) => { }; ShimCoreFunctions.getConnectionStringGuid = instance => string.Empty; ShimSqlCommand.AllInstances.ExecuteReader = instance => new ShimSqlDataReader { Read = () => _read, GetSqlInt32Int32 = _int => { _read = false; return(20); }, GetGuidInt32 = _int => { _read = false; return(_jobId); }, GetDateTimeInt32 = _int => { _read = false; return(DateTime.MinValue.ToUniversalTime()); }, GetStringInt32 = _int => { _read = false; return(string.Empty); }, IsDBNullInt32 = _int => { _read = false; return(false); } }; ShimHttpUtility.HtmlEncodeString = a => a; _spWeb = new ShimSPWeb { SiteGet = () => new ShimSPSite { IDGet = () => _jobId }, IDGet = () => _jobId }; ShimSPSite.ConstructorGuid = (instance, guid) => { }; ShimSPSite.AllInstances.WebApplicationGet = instance => { var webApp = new ShimSPWebApplication(); return(webApp); }; ShimSPSite.AllInstances.Dispose = instance => { }; ShimLoggingService.WriteTraceStringStringTraceSeverityString = (_, __, ___, ____) => { }; ShimCoreFunctions.getConnectionStringGuid = instance => string.Empty; ShimSqlCommand.AllInstances.ExecuteReader = instance => new ShimSqlDataReader { Read = () => _read, GetSqlInt32Int32 = _int => { _read = false; return(20); }, GetGuidInt32 = _int => { _read = false; return(_jobId); }, GetDateTimeInt32 = _int => { _read = false; return(DateTime.MinValue.ToUniversalTime()); }, GetStringInt32 = _int => { _read = false; return(string.Empty); }, IsDBNullInt32 = _int => { _read = false; return(false); } }; ShimHttpUtility.HtmlEncodeString = a => a; }
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); } }