public void SharepointUtils_BuildCamlQuery_ValidFilters_HasQueryWithAnd() { //------------Setup for test-------------------------- var sharepointUtils = new SharepointUtils(); //------------Execute Test--------------------------- var camlQuery = sharepointUtils.BuildCamlQuery(new ExecutionEnvironment(), new List <SharepointSearchTo> { new SharepointSearchTo("Title", "Equal", "Bob", 1) { InternalName = "Title" }, new SharepointSearchTo("ID", "Equal", "1", 1) { InternalName = "ID" } }, new List <ISharepointFieldTo> { new SharepointFieldTo { InternalName = "Title", Type = SharepointFieldType.Text }, new SharepointFieldTo { InternalName = "ID", Type = SharepointFieldType.Number } }, 0); //------------Assert Results------------------------- Assert.AreEqual("<View><Query><Where><And><FieldRef Name=\"Title\"></FieldRef><Value Type=\"Text\">Bob</Value>" + Environment.NewLine + "<FieldRef Name=\"ID\"></FieldRef><Value Type=\"Integer\">1</Value>" + Environment.NewLine + "</And></Where></Query></View>", camlQuery.ViewXml); }
/// <summary> /// Checkout document /// </summary> /// <param name="localCheckout">Whether document should be checked out locally or on the server side</param> /// <returns> /// Whether check out process has completed successfully /// </returns> public bool CheckOut(bool localCheckout) { string documentUrl = StringUtil.EnsurePostfix('/', this.context.Url) + StringUtil.RemovePrefix('/', this.document.FileRef); SharepointUtils.LogDebugInfo(this.context, "Checking out file: [" + documentUrl + "]"); return(this.ListsWebService.CheckOutFile(documentUrl, localCheckout ? "true" : "false", string.Empty)); }
protected void advancedSearchBtn_Click(object sender, EventArgs e) { advancedSearchBtn.Text = "» " + Translate.Text(UIMessages.AdvancedSearch); advancedSearchSitesPane.Visible = !advancedSearchSitesPane.Visible; advancedSearchListsPane.Visible = !advancedSearchListsPane.Visible; if (advancedSearchSitesPane.Visible) { advancedSearchBtn.Text = "» " + Translate.Text(UIMessages.AdvancedSearch); Server spServer = ObjectModel.Entities.Server.Connect(SpContext); try { List <System.Web.UI.WebControls.ListItem> webs = new List <System.Web.UI.WebControls.ListItem> { new System.Web.UI.WebControls.ListItem(Translate.Text(UIMessages.AllSites), this.Web) }; webs.AddRange(spServer.Webs.Select(web => new ListItem(web.Title, web.Path))); if ((webs.Count > 0)) { sitesList.DataSource = webs; } sitesList.DataTextField = "Text"; sitesList.DataValueField = "Value"; sitesList.DataBind(); listsList.DataSource = new[] { new System.Web.UI.WebControls.ListItem(Translate.Text(UIMessages.AllLists)) }; listsList.DataBind(); AttemptNumber = 0; } catch (WebException ex) { sitesList.DataSource = new[] { new System.Web.UI.WebControls.ListItem(Translate.Text(UIMessages.AllSites), this.Web) }; sitesList.DataBind(); listsList.DataSource = new[] { new System.Web.UI.WebControls.ListItem(Translate.Text(UIMessages.AllLists)) }; listsList.DataBind(); errorLbl.Text = Translate.Text(UIMessages.CouldntGetResponseFromSharepointServer); HttpWebResponse webResponse = ex.Response as HttpWebResponse; if ((webResponse != null) && (webResponse.StatusCode == HttpStatusCode.Unauthorized) && (webResponse.Headers.AllKeys.Contains("WWW-Authenticate"))) { errorLbl.Text = Translate.Text(UIMessages.YouDoNotHaveEnoughRights); if (AttemptNumber < 3) { SharepointExtension.WriteAuthenticationResponseBasic(Request, Response); AttemptNumber++; } } this.ShowErrorLabel(); return; } catch (SoapException ex) { SharepointUtils.LogDebugInfo(SpContext, "Can't retrieve info for advanced search"); return; } } }
public void SharepointUtils_CastWarewolfValueToCorrectType_Date_ShouldGiveDateValueValue() { //------------Setup for test-------------------------- var sharepointUtils = new SharepointUtils(); //------------Execute Test--------------------------- var value = SharepointUtils.CastWarewolfValueToCorrectType(DateTime.Now, SharepointFieldType.DateTime); //------------Assert Results------------------------- Assert.IsInstanceOfType(value, typeof(DateTime)); }
public void SharepointUtils_CastWarewolfValueToCorrectType_Currency_ShouldGiveDecimalValue() { //------------Setup for test-------------------------- var sharepointUtils = new SharepointUtils(); //------------Execute Test--------------------------- var value = SharepointUtils.CastWarewolfValueToCorrectType("2.01", SharepointFieldType.Currency); //------------Assert Results------------------------- Assert.IsInstanceOfType(value, typeof(Decimal)); }
public void SharepointUtils_CastWarewolfValueToCorrectType_Note_ShouldGiveStringValue() { //------------Setup for test-------------------------- var sharepointUtils = new SharepointUtils(); //------------Execute Test--------------------------- var value = SharepointUtils.CastWarewolfValueToCorrectType("Bob", SharepointFieldType.Note); //------------Assert Results------------------------- Assert.IsInstanceOfType(value, typeof(String)); }
public void SharepointUtils_CastWarewolfValueToCorrectType_Boolean_ShouldGiveBoolValue() { //------------Setup for test-------------------------- var sharepointUtils = new SharepointUtils(); //------------Execute Test--------------------------- var value = SharepointUtils.CastWarewolfValueToCorrectType("true", SharepointFieldType.Boolean); //------------Assert Results------------------------- Assert.IsInstanceOfType(value, typeof(Boolean)); }
public void SharepointUtils_BuildCamlQuery_NoFilters_ShouldBeCreateAllItemsQuery() { //------------Setup for test-------------------------- var sharepointUtils = new SharepointUtils(); //------------Execute Test--------------------------- var camlQuery = sharepointUtils.BuildCamlQuery(new ExecutionEnvironment(), new List <SharepointSearchTo>(), new List <ISharepointFieldTo>(), 0); //------------Assert Results------------------------- Assert.AreEqual(CamlQuery.CreateAllItemsQuery().ViewXml, camlQuery.ViewXml); }
/// <summary> /// Check in document /// </summary> /// <param name="comment">The comment for SharePoint</param> /// <param name="checkInType">The check in type. Possible values /// A string representation of the values 0, 1 or 2, where 0 = MinorCheckIn, 1 = MajorCheckIn, and 2 = OverwriteCheckIn.</param> /// <returns> /// Whether check in process has completed successfully /// </returns> public bool CheckIn([NotNull] string comment, [NotNull] string checkInType) { Assert.ArgumentNotNull(comment, "comment"); Assert.ArgumentNotNull(checkInType, "checkInType"); string documentUrl = StringUtil.EnsurePostfix('/', this.context.Url) + StringUtil.RemovePrefix('/', this.document.FileRef); SharepointUtils.LogDebugInfo(this.context, "Checking in file: [" + documentUrl + "]"); return(this.ListsWebService.CheckInFile(documentUrl, comment, checkInType)); }
public void SharepointUtils_CastWarewolfValueToCorrectType_Integer_ShouldGiveIntValue() { //------------Setup for test-------------------------- var sharepointUtils = new SharepointUtils(); //------------Execute Test--------------------------- var value = SharepointUtils.CastWarewolfValueToCorrectType("2", SharepointFieldType.Integer); //------------Assert Results------------------------- Assert.IsInstanceOfType(value, typeof(Int32)); }
public void SharepointUtils_GetValidReadListItems_NullList_EmptyList() { //------------Setup for test-------------------------- var sharepointUtils = new SharepointUtils(); //------------Execute Test--------------------------- var validList = SharepointUtils.GetValidReadListItems(null); //------------Assert Results------------------------- Assert.IsNotNull(validList); Assert.AreEqual(0, validList.Count()); }
public void SharepointUtils_GetValidReadListItems_WhereVariableNameEmpty_ListWithoutItem() { //------------Setup for test-------------------------- var sharepointUtils = new SharepointUtils(); //------------Execute Test--------------------------- var validList = SharepointUtils.GetValidReadListItems(new List <SharepointReadListTo> { new SharepointReadListTo("Bob", "Title", "Title", ""), new SharepointReadListTo("", "Title", "Title", "") }); //------------Assert Results------------------------- Assert.IsNotNull(validList); var tos = validList as IList <SharepointReadListTo> ?? validList.ToList(); Assert.AreEqual(1, tos.Count); Assert.AreEqual("Bob", tos[0].VariableName); }
protected void sitesList_IndexChanged(object sender, EventArgs e) { List <System.Web.UI.WebControls.ListItem> lists = new List <System.Web.UI.WebControls.ListItem> { new System.Web.UI.WebControls.ListItem(Translate.Text(UIMessages.AllLists)) }; listsList.DataSource = null; listsList.Items.Clear(); string siteName = sitesList.SelectedValue; if (!string.IsNullOrEmpty(siteName) && (sitesList.SelectedIndex > 0)) { Server spServer = ObjectModel.Entities.Server.Connect(SpContext); try { Web selectedWeb = spServer.Webs.First(web => web.Path == siteName); if (selectedWeb != null) { lists.AddRange(selectedWeb.Lists.Select(list => new ListItem(list.Name, list is ObjectModel.Entities.Lists.List ? "Lists/" + list.Name : list.Name))); } } catch (WebException ex) { HttpWebResponse webResponse = ex.Response as HttpWebResponse; if ((webResponse != null) && (webResponse.StatusCode == HttpStatusCode.Unauthorized) && (webResponse.Headers.AllKeys.Contains("WWW-Authenticate"))) { SharepointExtension.WriteAuthenticationResponseBasic(Request, Response); } return; } catch (SoapException ex) { SharepointUtils.LogDebugInfo(SpContext, "Couldn't retrieve lists for {0} site.\n{1}", siteName, ex.StackTrace); return; } } listsList.DataTextField = "Text"; listsList.DataValueField = "Value"; listsList.DataSource = lists; listsList.DataBind(); }
public void SharepointUtils_BuildCamlQuery_ValidFilter_In_TextResultCommaSeperated() { //------------Setup for test-------------------------- var sharepointUtils = new SharepointUtils(); var executionEnvironment = new ExecutionEnvironment(); //------------Execute Test--------------------------- var camlQuery = sharepointUtils.BuildCamlQuery(executionEnvironment, new List <SharepointSearchTo> { new SharepointSearchTo("Title", "In", "bob,dora", 1) { InternalName = "Title" } }, new List <ISharepointFieldTo> { new SharepointFieldTo { InternalName = "Title", Type = SharepointFieldType.Text } }, 0); //------------Assert Results------------------------- Assert.AreEqual("<View><Query><Where><In><FieldRef Name=\"Title\"></FieldRef><Values><Value Type=\"Text\">bob</Value><Value Type=\"Text\">dora</Value></Values></In>" + Environment.NewLine + "</Where></Query></View>", camlQuery.ViewXml); }
protected void Initialize(string serverUrl, ICredentials serverCredentials) { if (string.IsNullOrEmpty(serverUrl)) { serverUrl = SharepointUtils.CurrentSharepointServer; } this.Url = serverUrl; if (serverCredentials == null) { serverCredentials = this.GetPredefinedCredentials(); if (serverCredentials == null) { serverCredentials = CredentialCache.DefaultNetworkCredentials; this.Credentials = serverCredentials; SharepointUtils.LogDebugInfo(this, "Using DefaultNetworkCredentials"); } } this.Credentials = serverCredentials; this.InitConfiguration(); }
/// <summary>Creates context.</summary> /// <param name="sharepointServer">The SharePoint server.</param> /// <param name="web">The web.</param> /// <param name="predefinedContext">The predefined context.</param> /// <param name="credentials">The credentials.</param> /// <param name="connectionConfiguration">The connection configuration.</param> /// <returns>The <see cref="SpContext"/>.</returns> protected virtual SpContext CreateContext(string sharepointServer, string web, string predefinedContext, ICredentials credentials = null, string connectionConfiguration = null) { var context = new SpContext { Url = !string.IsNullOrEmpty(sharepointServer) ? sharepointServer : SharepointUtils.CurrentSharepointServer, Credentials = credentials, ConnectionConfiguration = connectionConfiguration }; if (!string.IsNullOrEmpty(context.ConnectionConfiguration) && context.Credentials != null) { return(context); } ServerEntry serverEntry = this.GetServerEntry(StringUtil.EnsurePostfix('/', sharepointServer) + StringUtil.RemovePrefix('/', web), predefinedContext); if (serverEntry != null) { if (string.IsNullOrEmpty(context.ConnectionConfiguration)) { context.ConnectionConfiguration = serverEntry.ConnectionConfiguration; } if (context.Credentials == null) { context.Credentials = serverEntry.Credentials; } } if (context.Credentials == null) { context.Credentials = this.DefaultCredentials; SharepointUtils.LogDebugInfo(context, "Using DefaultNetworkCredentials"); } return(context); }
public void SharepointReadListActivity_GetState() { //------------Setup for test-------------------------- const string activityName = "SharepointReadList"; var resourceId = Guid.NewGuid(); var filterCriteria = new List <SharepointSearchTo>() { new SharepointSearchTo("A", "A", "", 1) }; var sharepointList = "SharepointList"; var requireAllCriteriaToMatch = true; var readListItems = new List <SharepointReadListTo>(); var sharepointUtils = new SharepointUtils(); var sharepointReadListActivity = new SharepointReadListActivity { DisplayName = activityName, SharepointServerResourceId = resourceId, ReadListItems = readListItems, FilterCriteria = filterCriteria, SharepointList = sharepointList, RequireAllCriteriaToMatch = requireAllCriteriaToMatch, SharepointUtils = sharepointUtils }; var dataObj = new DsfDataObject(It.IsAny <string>(), It.IsAny <Guid>(), It.IsAny <string>()); var resourceCatalog = new Mock <IResourceCatalog>(); var privateObject = new PrivateObject(sharepointReadListActivity); privateObject.SetProperty("ResourceCatalog", resourceCatalog.Object); //------------Execute Test--------------------------- privateObject.Invoke("ExecuteTool", dataObj, 0); var serializer = new Dev2JsonSerializer(); var expectedResults = new[] { new StateVariable { Name = "SharepointServerResourceId", Type = StateVariable.StateType.Input, Value = resourceId.ToString() }, new StateVariable { Name = "ReadListItems", Type = StateVariable.StateType.InputOutput, Value = ActivityHelper.GetSerializedStateValueFromCollection(readListItems) }, new StateVariable { Name = "FilterCriteria", Type = StateVariable.StateType.Input, Value = ActivityHelper.GetSerializedStateValueFromCollection(filterCriteria) }, new StateVariable { Name = "RequireAllCriteriaToMatch", Type = StateVariable.StateType.Input, Value = requireAllCriteriaToMatch.ToString() }, new StateVariable { Name = "SharepointList", Type = StateVariable.StateType.Input, Value = sharepointList } }; //---------------Test Result ----------------------- var stateItems = sharepointReadListActivity.GetState(); Assert.AreEqual(5, stateItems.Count()); var iter = stateItems.Select( (item, index) => new { value = item, expectValue = expectedResults[index] } ); //------------Assert Results------------------------- foreach (var entry in iter) { Assert.AreEqual(entry.expectValue.Name, entry.value.Name); Assert.AreEqual(entry.expectValue.Type, entry.value.Type); Assert.AreEqual(entry.expectValue.Value, entry.value.Value); } }