public void test_THAT_neq_or_isnull_with_orderby_expression_IS_translated_sucessfully() { string caml = Camlex.Query().Where(x => (string)x["Status"] != "Completed" || x["Status"] == null). OrderBy(x => new[] { x["Modified"] as Camlex.Desc }).ToString(); string expected = // "<Query>" + " <Where>" + " <Or>" + " <Neq>" + " <FieldRef Name=\"Status\" />" + " <Value Type=\"Text\">Completed</Value>" + " </Neq>" + " <IsNull>" + " <FieldRef Name=\"Status\" />" + " </IsNull>" + " </Or>" + " </Where>" + " <OrderBy>" + " <FieldRef Name=\"Modified\" Ascending=\"False\" />" + " </OrderBy>"; // "</Query>"; Assert.That(caml, Is.EqualTo(expected).Using(new CamlComparer())); }
public void test_THAT_contains_and_beginswith_expression_IS_translated_sucessfully() { var caml = Camlex.Query() .Where(x => ((string)x["Title"]).StartsWith("Task") && ((string)x["Project"]).Contains("Camlex")) .ToString(); const string expected = // "<Query>" + " <Where>" + " <And>" + " <BeginsWith>" + " <FieldRef Name=\"Title\" />" + " <Value Type=\"Text\">Task</Value>" + " </BeginsWith>" + " <Contains>" + " <FieldRef Name=\"Project\" />" + " <Value Type=\"Text\">Camlex</Value>" + " </Contains>" + " </And>" + " </Where>"; // "</Query>"; Assert.That(caml, Is.EqualTo(expected).Using(new CamlComparer())); }
public List <ContactInfo> get_ContactInfo(SPWeb web, string currentContact) { var list = web.Lists[listName]; var contactsInfoList = new List <ContactInfo>(); var query = Camlex.Query().Where(c => (Boolean)c[Constants.ContactInfomation.InternalFields.Activate]) .OrderBy(c => c[Constants.ContactInfomation.InternalFields.Order] as Camlex.Asc) .ToSPQuery(); var items = list.GetItems(query); if (items != null && items.Count > 0) { int currentId = 0; if (!int.TryParse(currentContact, out currentId)) { currentContact = Convert.ToString(items[0].ID); } contactsInfoList.AddRange(from SPListItem item in items select new ContactInfo { Id = item.ID, Title = item.Title, Language = web.Language, WebUrl = web.Url, Content = Convert.ToString(item[Constants.ContactInfomation.InternalFields.Content]), active = currentContact, }); } return(contactsInfoList); }
public DocumentsLegalInfo get_DocumentsLegalInfoItemId(SPWeb web, int id) { var list = web.Lists[listName]; var documentsLegalInfo = new DocumentsLegalInfo(); var query = Camlex.Query() .Where(c => (Boolean)c[Constants.DocumentShareholder.InternalFields.Activate] && (int)c[Constants.CommonField.ID] == id) .OrderBy(c => c[Constants.DocumentShareholder.InternalFields.DocumentDate] as Camlex.Desc).ToSPQuery(); var items = list.GetItems(query); if (items != null && items.Count > 0) { var item = items[0]; documentsLegalInfo = new DocumentsLegalInfo { Id = item.ID, Title = item.Title, Language = web.Language, WebUrl = web.Url, Created = Convert.ToDateTime(item[Constants.CommonField.Created]).ToShortDateString(), DocumentDate = item[Constants.DocumentShareholder.InternalFields.DocumentDate] != null?Convert.ToDateTime(item[Constants.DocumentShareholder.InternalFields.DocumentDate]).ToShortDateString() : string.Empty }; } return(documentsLegalInfo); }
public void test_THAT_existing_single_eq_expression_with_query_tag_IS_mixed_with_single_expression_correctly_using_and() { string existingQuery = "<Query>" + " <Where>" + " <Eq>" + " <FieldRef Name=\"Title\" />" + " <Value Type=\"Text\">testValue</Value>" + " </Eq>" + " </Where>" + "</Query>"; string expected = "<Where>" + " <And>" + " <Eq>" + " <FieldRef Name=\"Title\" />" + " <Value Type=\"Text\">foo</Value>" + " </Eq>" + " <Eq>" + " <FieldRef Name=\"Title\" />" + " <Value Type=\"Text\">testValue</Value>" + " </Eq>" + " </And>" + "</Where>"; var query = Camlex.Query().WhereAll(existingQuery, x => (string)x["Title"] == "foo").ToString(); Assert.That(query, Is.EqualTo(expected).Using(new CamlComparer())); }
public void test_THAT_mixed_boolean_expression_IS_translated_successfully() { var xml = "<Query>" + " <Where>" + " <Or>" + " <And>" + " <Eq>" + " <FieldRef Name=\"foo1\" />" + " <Value Type=\"Boolean\">1</Value>" + " </Eq>" + " <Eq>" + " <FieldRef Name=\"foo2\" />" + " <Value Type=\"Boolean\">0</Value>" + " </Eq>" + " </And>" + " <Eq>" + " <FieldRef Name=\"foo3\" />" + " <Value Type=\"Boolean\">1</Value>" + " </Eq>" + " </Or>" + " </Where>" + "</Query>"; var expr = Camlex.QueryFromString(xml).ToExpression(); Assert.That(expr.ToString(), Is.EqualTo("Query().Where(x => ((Convert(x.get_Item(\"foo1\")) AndAlso Not(Convert(x.get_Item(\"foo2\")))) OrElse Convert(x.get_Item(\"foo3\"))))")); }
public List <OrganizationBroadInfor> getOrganizationBroad(SPWeb web, string division) { var getOrganizationBroad = new List <OrganizationBroadInfor>(); var query = Camlex.Query() .Where( c => (Boolean)c[Constants.OrganizationBroad.InternalFields.Activate] && (string)c[Constants.OrganizationBroad.InternalFields.Division] == division) .OrderBy(c => c[Constants.OrganizationBroad.InternalFields.Level]).OrderBy(c => c[Constants.OrganizationBroad.InternalFields.Order] as Camlex.Asc) .ToSPQuery(); var items = web.Lists[listOrganizationBroadName].GetItems(query); if (items.Count > 0) { getOrganizationBroad.AddRange(from SPListItem item in items select new OrganizationBroadInfor() { Id = item.ID, title = item.Title, division = Convert.ToString(item[Constants.OrganizationBroad.InternalFields.Division]), personname = Convert.ToString(item[Constants.OrganizationBroad.InternalFields.PersonName]), duty = Convert.ToString(item[Constants.OrganizationBroad.InternalFields.Duty]), level = Convert.ToString(item[Constants.OrganizationBroad.InternalFields.Level]), history = Convert.ToString(item[Constants.OrganizationBroad.InternalFields.History]), Image = Convert.ToString(item[Constants.OrganizationBroad.InternalFields.Image]) }); } return(getOrganizationBroad); }
public List <TemOfUseInfo> get_Allitems(SPWeb web, string currentItem) { var list = web.Lists[listName]; var TermOfUseInfoList = new List <TemOfUseInfo>(); var query = Camlex.Query() .Where(c => (Boolean)c[Constants.TermsOfUse.InternalFields.Activate]) .OrderBy(c => c[Constants.TermsOfUse.InternalFields.Order] as Camlex.Asc) .ToSPQuery(); var items = list.GetItems(query); if (items.Count > 0) { int id = 0; if (!int.TryParse(currentItem, out id)) { id = items[0].ID; } TermOfUseInfoList.AddRange(from SPListItem item in items select new TemOfUseInfo() { Language = web.Language, Id = item.ID, Title = item.Title, Content = Convert.ToString(item[Constants.TermsOfUse.InternalFields.Content]), Active = Convert.ToString(id), WebUrl = web.Url }); } return(TermOfUseInfoList); }
public List <ShareholderInfo> get_Top10ShareholderItems(SPWeb web, int id, string category) { var list = web.Lists[listName]; var shareholderInfoList = new List <ShareholderInfo>(); var query = Camlex.Query() .Where(c => (Boolean)c[Constants.MeetingPartners.InternalFields.Activate] && (int)c[Constants.CommonField.ID] != id && (string)c[Constants.MeetingPartners.InternalFields.Category] == category) .OrderBy(c => c[Constants.MeetingPartners.InternalFields.DateCreate] as Camlex.Desc).ToSPQuery(); query.RowLimit = 10; var items = list.GetItems(query); if (items != null && items.Count > 0) { shareholderInfoList.AddRange(from SPListItem item in items select new ShareholderInfo { Id = item.ID, Title = item.Title, Language = web.Language, WebUrl = web.Url, Image = Convert.ToString(item[Constants.MeetingPartners.InternalFields.Image]), Created = Convert.ToDateTime(item[Constants.MeetingPartners.InternalFields.DateCreate]).ToShortDateString(), Description = Convert.ToString(item[Constants.MeetingPartners.InternalFields.Description]), Category = Convert.ToString(item[Constants.MeetingPartners.InternalFields.Category]) }); } return(shareholderInfoList); }
public ShareholderInfo get_ShareholderItemId(SPWeb web, int id) { var list = web.Lists[listName]; var shareholderInfo = new ShareholderInfo(); var query = Camlex.Query() .Where(c => (Boolean)c[Constants.MeetingPartners.InternalFields.Activate] && (int)c[Constants.CommonField.ID] == id) .ToSPQuery(); var items = list.GetItems(query); if (items != null && items.Count > 0) { var item = items[0]; shareholderInfo = new ShareholderInfo { Id = item.ID, Title = item.Title, Language = web.Language, WebUrl = web.Url, Content = Convert.ToString(item[Constants.MeetingPartners.InternalFields.Content]), Image = Convert.ToString(item[Constants.MeetingPartners.InternalFields.Image]), Created = Convert.ToDateTime(item[Constants.MeetingPartners.InternalFields.DateCreate]).ToShortDateString(), Description = Convert.ToString(item[Constants.MeetingPartners.InternalFields.Description]), Category = Convert.ToString(item[Constants.MeetingPartners.InternalFields.Category]) }; } return(shareholderInfo); }
public void test_THAT_multiple_joins_ARE_translated_properly() { string caml = Camlex.Query().Joins().Left(x => x["test1"].ForeignList("foo1")) .Left(x => x["test2"].PrimaryList("foo2").ForeignList("bar2")) .Inner(x => x["test3"].PrimaryList("foo3").ForeignList("bar3")).ToString(); string expected = "<Join Type=\"LEFT\" ListAlias=\"foo1\">" + " <Eq>" + " <FieldRef Name=\"test1\" RefType=\"Id\" />" + " <FieldRef List=\"foo1\" Name=\"Id\" />" + " </Eq>" + "</Join>" + "<Join Type=\"LEFT\" ListAlias=\"bar2\">" + " <Eq>" + " <FieldRef List=\"foo2\" Name=\"test2\" RefType=\"Id\" />" + " <FieldRef List=\"bar2\" Name=\"Id\" />" + " </Eq>" + "</Join>" + "<Join Type=\"INNER\" ListAlias=\"bar3\">" + " <Eq>" + " <FieldRef List=\"foo3\" Name=\"test3\" RefType=\"Id\" />" + " <FieldRef List=\"bar3\" Name=\"Id\" />" + " </Eq>" + "</Join>"; Assert.That(caml, Is.EqualTo(expected).Using(new CamlComparer())); }
public void test_THAT_multiple_projected_field_IS_translated_properly() { string caml = Camlex.Query().ProjectedFields().Field(x => x["test1"].List("foo1").ShowField("bar1")).Field(x => x["test2"].List("foo2").ShowField("bar2")).ToString(); string expected = "<Field Name=\"test1\" Type=\"Lookup\" List=\"foo1\" ShowField=\"bar1\" /><Field Name=\"test2\" Type=\"Lookup\" List=\"foo2\" ShowField=\"bar2\" />"; Assert.That(caml, Is.EqualTo(expected).Using(new CamlComparer())); }
public void test_THAT_expression_with_2_andalso_and_1_orelse_ARE_translated_sucessfully() { string caml = Camlex.Query().Where(x => ((string)x["Title"] == "testValue" && (int)x["Count1"] == 1) || (int)x["Count2"] == 2).ToString(); string expected = // "<Query>" + " <Where>" + " <Or>" + " <And>" + " <Eq>" + " <FieldRef Name=\"Title\" />" + " <Value Type=\"Text\">testValue</Value>" + " </Eq>" + " <Eq>" + " <FieldRef Name=\"Count1\" />" + " <Value Type=\"Integer\">1</Value>" + " </Eq>" + " </And>" + " <Eq>" + " <FieldRef Name=\"Count2\" />" + " <Value Type=\"Integer\">2</Value>" + " </Eq>" + " </Or>" + " </Where>"; // "</Query>"; Assert.That(caml, Is.EqualTo(expected).Using(new CamlComparer())); }
public void test_THAT_contains_and_isnotnull_expression_IS_translated_sucessfully() { var caml = Camlex.Query() .Where(x => ((string)x["Title"]).StartsWith("Task") && x["Status"] != null) .ToString(); const string expected = // "<Query>" + " <Where>" + " <And>" + " <BeginsWith>" + " <FieldRef Name=\"Title\" />" + " <Value Type=\"Text\">Task</Value>" + " </BeginsWith>" + " <IsNotNull>" + " <FieldRef Name=\"Status\" />" + " </IsNotNull>" + " </And>" + " </Where>"; // "</Query>"; Assert.That(caml, Is.EqualTo(expected).Using(new CamlComparer())); }
public List <OrganizationChartInfor> getOrganizationChart(SPWeb web) { var getOrganizationChart = new List <OrganizationChartInfor>(); var query = Camlex.Query() .Where( c => (Boolean)c[Constants.OrganizationChart.InternalFields.Activate]) .OrderBy(c => c[Constants.CommonField.Title]) .ToSPQuery(); var items = web.Lists[listOrganizationChartName].GetItems(query); if (items.Count > 0) { getOrganizationChart.AddRange(from SPListItem item in items select new OrganizationChartInfor() { title = item.Title, description = Convert.ToString(item[Constants.OrganizationChart.InternalFields.Description]), //Image = Convert.ToString(item[Constants.OrganizationChart.InternalFields.Image]) }); } return(getOrganizationChart); }
public void test_THAT_mixed_join_explicit_boolean_cast_expressions_ARE_translated_sucessfully() { string caml = Camlex.Query().Where(x => ((bool)x["foo1"] && !(bool)x["foo2"]) || (bool)x["foo3"]).ToString(); string expected = " <Where>" + " <Or>" + " <And>" + " <Eq>" + " <FieldRef Name=\"foo1\" />" + " <Value Type=\"Boolean\">1</Value>" + " </Eq>" + " <Eq>" + " <FieldRef Name=\"foo2\" />" + " <Value Type=\"Boolean\">0</Value>" + " </Eq>" + " </And>" + " <Eq>" + " <FieldRef Name=\"foo3\" />" + " <Value Type=\"Boolean\">1</Value>" + " </Eq>" + " </Or>" + " </Where>"; Assert.That(caml, Is.EqualTo(expected).Using(new CamlComparer())); }
/// <summary> /// Cac funtion dung de hien thi du lieu, day em moi lam mau thoi, fai filter theo cac dk nhu la activate = true, ... /// </summary> /// <param name="web"></param> /// <returns></returns> public DataTable get_CategoryNews(SPWeb web) { var list = web.Lists[listName]; var query = Camlex.Query().Where(c => (Boolean)c[Constants.CategoryNews.InternalFields.Activate] == true).OrderBy(c => c[Constants.CategoryNews.InternalFields.Order] as Camlex.Asc).ToSPQuery(); return(list.GetItems(query).GetDataTable()); }
public void test_THAT_order_by_collection_IS_mixed_with_several_order_by_correctly() { string existingQuery = " <OrderBy>" + " <FieldRef Name=\"Modified\" Ascending=\"False\" />" + " <FieldRef Name=\"ModifiedBy\" />" + " </OrderBy>"; string expected = "<OrderBy>" + " <FieldRef Name=\"Modified\" Ascending=\"False\" />" + " <FieldRef Name=\"ModifiedBy\" />" + " <FieldRef Name=\"Title\" />" + " <FieldRef Name=\"State\" Ascending=\"True\" />" + "</OrderBy>"; var exprs = new List <Expression <Func <SPListItem, object> > >(); exprs.Add(x => x["Title"]); exprs.Add(x => x["State"] as Camlex.Asc); var query = Camlex.Query().OrderBy(existingQuery, exprs).ToString(); Assert.That(query, Is.EqualTo(expected).Using(new CamlComparer())); }
public void test_THAT_membership_expression_with_spwebusers_IS_valid() { var analyzer = new MembershipAnalyzer(null, null); Expression <Func <SPListItem, bool> > expr = x => Camlex.Membership(x["field"], new Camlex.SPWebUsers()); Assert.That(analyzer.IsValid(expr), Is.True); }
public List <SliderInfo> get_SliderInfo(SPWeb web) { var list = web.Lists[listName]; var sliderInfoList = new List <SliderInfo>(); var query = Camlex.Query().Where(c => (Boolean)c[Constants.Slider.InternalFields.Active] && (DateTime)c[Constants.Slider.InternalFields.FromDate] <= DateTime.Today && (c[Constants.Slider.InternalFields.ToDate] == null || (DateTime)c[Constants.Slider.InternalFields.ToDate] >= DateTime.Today)) .OrderBy(c => c[Constants.Slider.InternalFields.Order] as Camlex.Asc) .ToSPQuery(); query.RowLimit = 4; var items = list.GetItems(query); if (items != null && items.Count > 0) { sliderInfoList.AddRange(from SPListItem item in items select new SliderInfo { Id = item.ID, Title = item.Title, Language = web.Language, WebUrl = web.Url, Description = Convert.ToString(item[Constants.Slider.InternalFields.Description]), Image1366 = Convert.ToString(item[Constants.Slider.InternalFields.Banner1366]), Image1024 = Convert.ToString(item[Constants.Slider.InternalFields.Banner1024]), Image480 = Convert.ToString(item[Constants.Slider.InternalFields.Banner480]), Url = Convert.ToString(item[Constants.Slider.InternalFields.LinkToContent]), Index = Convert.ToString(item[Constants.Slider.InternalFields.Slider]) }); } return(sliderInfoList); }
public void test_THAT_in_expression_with_and_IS_translated_sucessfully() { Func <int, string> f = i => i.ToString(); var caml = Camlex.Query().Where(x => (string)x["Title"] == "test" && (new[] { f(0), f(1), f(2) }).Contains((string)x[new Guid("{1DF87A41-D795-4C0F-915F-DC3D54B296AA}")])).ToString(); var expected = "<Where>" + " <And>" + " <Eq>" + " <FieldRef Name=\"Title\" />" + " <Value Type=\"Text\">test</Value>" + " </Eq>" + " <In>" + " <FieldRef ID=\"1df87a41-d795-4c0f-915f-dc3d54b296aa\" />" + " <Values>" + " <Value Type=\"Text\">0</Value>" + " <Value Type=\"Text\">1</Value>" + " <Value Type=\"Text\">2</Value>" + " </Values>" + " </In>" + " </And>" + "</Where>"; Assert.That(caml, Is.EqualTo(expected).Using(new CamlComparer())); }
public void test_THAT_3_order_by_with_non_constant_fields_ARE_joined_properly() { var orderByList = new List <Expression <Func <SPListItem, object> > >(); string name = "Title"; orderByList.Add(x => x[name]); Func <string> f = () => "Date"; orderByList.Add(x => x[f()]); var sb = new StringBuilder(); for (int i = 0; i < 5; i++) { sb.Append("s"); } orderByList.Add(x => x[sb.ToString()]); var caml = Camlex.Query().OrderBy(orderByList).ToString(); var expected = " <OrderBy>" + " <FieldRef Name=\"Title\" />" + " <FieldRef Name=\"Date\" />" + " <FieldRef Name=\"sssss\" />" + " </OrderBy>"; Assert.That(caml, Is.EqualTo(expected).Using(new CamlComparer())); }
public void test_THAT_single_in_expression_with_dynamic_array_IS_translated_successfully() { var caml = Camlex.Query().Where(x => getArray().Contains((int)x["test"])).ToString(); var expected = "<Where>" + " <In>" + " <FieldRef Name=\"test\" />" + " <Values>" + " <Value Type=\"Integer\">0</Value>" + " <Value Type=\"Integer\">1</Value>" + " <Value Type=\"Integer\">2</Value>" + " <Value Type=\"Integer\">3</Value>" + " <Value Type=\"Integer\">4</Value>" + " <Value Type=\"Integer\">5</Value>" + " <Value Type=\"Integer\">6</Value>" + " <Value Type=\"Integer\">7</Value>" + " <Value Type=\"Integer\">8</Value>" + " <Value Type=\"Integer\">9</Value>" + " </Values>" + " </In>" + "</Where>"; Assert.That(caml, Is.EqualTo(expected).Using(new CamlComparer())); }
public List <DocumentsLegalInfo> get_DocumentsLegalInfoItemsByDocumentType(SPWeb web, string documentType) { var list = web.Lists[listName]; var documentsLegalInfoInfoList = new List <DocumentsLegalInfo>(); var query = Camlex.Query() .Where(c => (Boolean)c[Constants.DocumentShareholder.InternalFields.Activate] && c[Constants.DocumentShareholder.InternalFields.Type] == (DataTypes.LookupId)documentType) .OrderBy(c => c[Constants.CommonField.Created] as Camlex.Desc).ToSPQuery(); var items = list.GetItems(query); if (items != null && items.Count > 0) { documentsLegalInfoInfoList.AddRange(from SPListItem item in items select new DocumentsLegalInfo { Id = item.ID, Title = item.Title, Language = web.Language, WebUrl = web.Url, Created = Convert.ToDateTime(item[Constants.CommonField.Created]).ToShortDateString(), //FileUrl = Convert.ToString(item["LinkFilename"]) FileUrl = item.File.Url, DocumentDate = item[Constants.DocumentShareholder.InternalFields.DocumentDate] != null ? Convert.ToDateTime(item[Constants.DocumentShareholder.InternalFields.DocumentDate]).ToShortDateString() : string.Empty }); } return(documentsLegalInfoInfoList); }
public List <DocumentGroupInfo> get_DocumentType(SPWeb web, string documentType, string currentCatId) { var list = web.Lists[listName]; var typeList = new List <DocumentGroupInfo>(); var query = Camlex.Query() .Where(c => (string)c[Constants.DocumentGroup.InternalFields.DocumentType] == documentType && (Boolean)c[Constants.DocumentGroup.InternalFields.Activate]) .OrderBy(c => c[Constants.DocumentGroup.InternalFields.Order] as Camlex.Asc) .ToSPQuery(); var items = list.GetItems(query); if (items.Count > 0) { typeList.AddRange(from SPListItem item in items select new DocumentGroupInfo() { Title = item.Title, TypeId = Convert.ToString(item.ID), Current = currentCatId, Language = web.Language, WebUrl = web.Url }); } return(typeList); }
public void test_THAT_join_all_with_false_explicit_boolean_cast_expressions_ARE_translated_sucessfully() { var expressions = new List <Expression <Func <SPListItem, bool> > >(); Enumerable.Range(1, 3).ToList().ForEach(i => expressions.Add(x => !(bool)x["foo" + i])); string caml = Camlex.Query().WhereAll(expressions).ToString(); string expected = " <Where>" + " <And>" + " <And>" + " <Eq>" + " <FieldRef Name=\"foo1\" />" + " <Value Type=\"Boolean\">0</Value>" + " </Eq>" + " <Eq>" + " <FieldRef Name=\"foo2\" />" + " <Value Type=\"Boolean\">0</Value>" + " </Eq>" + " </And>" + " <Eq>" + " <FieldRef Name=\"foo3\" />" + " <Value Type=\"Boolean\">0</Value>" + " </Eq>" + " </And>" + " </Where>"; Assert.That(caml, Is.EqualTo(expected).Using(new CamlComparer())); }
public void test_THAT_daterangesoverlap_expression_with_special_constant_IS_valid() { var analyzer = new DateRangesOverlapAnalyzer(null, null); Expression <Func <SPListItem, bool> > expr = x => Camlex.DateRangesOverlap(x["start"], x["stop"], x["recurrence"], (DataTypes.DateTime)Camlex.Month); Assert.That(analyzer.IsValid(expr), Is.True); }
public async Task SharePointClient_DeleteFile_DeleteRollback() { // Arrange var file = _sharePointClientFixture.GenerateSharePointFile(); var invalidFile = _sharePointClientFixture.GenerateSharePointFile("RemoveFolder/Level1/", false); // Act _sharePointClientFixture.SharePointClient.AddFile(file); await _sharePointClientFixture.SharePointClient.SaveChangesAsync(); _sharePointClientFixture.SharePointClient.DeleteFile(file); _sharePointClientFixture.SharePointClient.AddFile(invalidFile); var exception = await Assert.ThrowsAsync <SharePointException>(() => _sharePointClientFixture.SharePointClient.SaveChangesAsync()); var expectedFile = _sharePointClientFixture.SharePointClient.GetFiles <SharePointFile>( Camlex.Query().Where(i => (string)i[SharePointConstants.FieldNameFileLeafRef] == file.FileName).ToCamlQuery()).FirstOrDefault(); var expectedInvalidFile = await _sharePointClientFixture.SharePointClient .GetFileByIdAsync <SharePointFile>(invalidFile.Id); // Assert expectedFile.Should().NotBeNull(); expectedInvalidFile.Should().BeNull(); expectedFile.Description.Should().Be(file.Description); }
public async Task SharePointClient_DeleteItem_Rollback() { // Arrange var item = _sharePointClientFixture.GenerateSharePointListItem(); var invalidItem = _sharePointClientFixture.GenerateSharePointListItem(false); // Act _sharePointClientFixture.SharePointClient.AddItem(item); await _sharePointClientFixture.SharePointClient.SaveChangesAsync(); _sharePointClientFixture.SharePointClient.DeleteItem(item); _sharePointClientFixture.SharePointClient.AddItem(invalidItem); var exception = await Assert.ThrowsAsync <SharePointException>(() => _sharePointClientFixture.SharePointClient.SaveChangesAsync()); var expectedItem = (await _sharePointClientFixture.SharePointClient.GetItemsAsync <SharePointListItem>( Camlex.Query().Where(i => (string)i[SharePointConstants.FieldNameTitle] == item.TitleField).ToCamlQuery())).FirstOrDefault(); var expectedInvalidItem = await _sharePointClientFixture.SharePointClient .GetItemByIdAsync <SharePointListItem>(invalidItem.Id); // Assert expectedInvalidItem.Should().BeNull(); expectedItem.TitleField.Should().Be(expectedItem.TitleField); exception.ErrorCode.Should().Be(SharePointErrorCode.SaveChanges); }
public async Task SharePointClient_AddItem_WithAssociationById() { // Arrange var aggregatingListItem = _sharePointClientFixture.GenerateSharePointAggregatingListItem(); // Act _sharePointClientFixture.SharePointClient.AddItem(aggregatingListItem); await _sharePointClientFixture.SharePointClient.SaveChangesAsync(); var listItem = _sharePointClientFixture.GenerateSharePointListItem(); var listItem2 = _sharePointClientFixture.GenerateSharePointListItem(); listItem.LookupFieldId = aggregatingListItem.Id; listItem2.LookupFieldId = aggregatingListItem.Id; _sharePointClientFixture.SharePointClient.AddItem(listItem); _sharePointClientFixture.SharePointClient.AddItem(listItem2); await _sharePointClientFixture.SharePointClient.SaveChangesAsync(); var items = await _sharePointClientFixture.SharePointClient.GetItemsAsync <SharePointListItem>( Camlex.Query().Where(i => i["LookupField"] == (DataTypes.LookupId)aggregatingListItem.Id.ToString()).ToCamlQuery()); // Assert items.Count.Should().Be(2); }
// just in order to avoid compiler error that base type doesn't contain parameterless constructor public FieldRefOperandWithOrdering(FieldRefOperand fieldRefOperand, Camlex.OrderDirection orderDirection) : base(string.Empty) { if (fieldRefOperand.FieldId != null) { this.initialize(fieldRefOperand.FieldId.Value); } else if (!string.IsNullOrEmpty(fieldRefOperand.FieldName)) { this.initialize(fieldRefOperand.FieldName); } else { throw new FieldRefOperandShouldContainNameOrIdException(); } this.orderDirection = orderDirection; }
public IOperand CreateFieldRefOperandWithOrdering(Expression expr, Camlex.OrderDirection orderDirection) { var fieldRefOperand = (FieldRefOperand)CreateFieldRefOperand(expr, null); return new FieldRefOperandWithOrdering(fieldRefOperand, orderDirection); }
public IOperand CreateFieldRefOperandWithOrdering(XElement el, Camlex.OrderDirection orderDirection) { var fieldRefOperand = this.CreateFieldRefOperand(el) as FieldRefOperand; if (fieldRefOperand == null) { throw new CamlAnalysisException( string.Format( "Can't create field ref operand with ordering: underlying field ref operand is null. Xml which causes issue:\n{0}", el)); } return new FieldRefOperandWithOrdering(fieldRefOperand, orderDirection); }