public void Query_Where_CustomItem_By_DateTime_Test() { using (var tc = new TestListScope <CustomItem>("Query_Where_CustomItem_By_Number_Test", true)) { var entity = new CustomItem { Title = "asd", CustomDate = new DateTime(2011, 1, 11), }; var entity2 = new CustomItem { Title = "zxc", CustomDate = new DateTime(2013, 5, 1) }; tc.List.Add(entity); tc.List.Add(entity2); var query = tc.List.Items().Where(i => i.CustomDate == entity2.CustomDate); var coll = query.ToList(); Assert.That(query.ToString(), Is.EqualTo( "<View><Query><Where><Eq><FieldRef Name=\"CustomDate\" /><Value Type=\"DateTime\">2013-05-01T00:00:00</Value></Eq></Where></Query></View>")); Assert.That(coll.Count, Is.EqualTo(1)); Assert.That(coll[0].Id == entity2.Id); Assert.That(coll[0].Title == entity2.Title); } }
public void Query_Skip_Test() { using (var tc = new TestListScope <Item>("Query_Skip_Test")) { var entity = new Item { Title = "asd", }; var entity2 = new Item { Title = "zxc", }; var entity3 = new Item { Title = "qwe", }; tc.List.Add(entity); tc.List.Add(entity2); tc.List.Add(entity3); var query = tc.List.Items().Where(x => x.Id != 0).Skip(1); var coll = query.ToList(); Assert.That(coll.Count, Is.EqualTo(2)); Assert.That(coll[0].Id == entity2.Id); Assert.That(coll[1].Id == entity3.Id); } }
public void Is_Updated_Async_Called_Test() { using (var ts = new TestListScope <UpdatedItemAsync>("Is_Updated_Async_Called_Test", true)) { ts.List.AddEventReceiver <UpdatedReceiverAsync>(); var entity = FillCusomItem(ts); ts.List.Add(entity); entity = ts.List.ById(entity.Id); ModifyCustomItem(entity); ts.List.Update(entity, true); UpdatedItemAsync.ManualResetEvent.WaitOne(10000); Assert.True(UpdatedItemAsync.IsUpdateCalled, "Not fired updated receiver!"); if (UpdatedItemAsync.Exception != null) { throw UpdatedItemAsync.Exception; } ValidateCustomItem(UpdatedItemAsync.Received, entity); } }
public void Add_Item_With_Custom_Lookup() { /*Mockable.AddFieldAsXml = (collection, s) => string.Empty; * Mockable.GetFieldByInternalName = (collection, s) => null; * Mockable.FieldMapper_SetFieldProperties = (f, fi) => { };*/ using (var tls = new TestListScope <Contract>("Add_Item_With_Custom_Lookup")) { var list = tls.List; var i = new Contract { ProjectNew = new Item { Id = 1, }, Projects = new List <Item> { new Item { Id = 1, }, new Item { Id = 2, } }, }; list.Add(i); } }
public void Query_Sum_Test() { using (var tc = new TestListScope <CustomItem>("Query_Sum_Test")) { var entity = new CustomItem { Title = "asd", CustomFieldNumber = 11, }; var entity2 = new CustomItem { Title = "zxc", CustomFieldNumber = 22, }; var entity3 = new CustomItem { Title = "qwe", CustomFieldNumber = 33, }; tc.List.Add(entity); tc.List.Add(entity2); tc.List.Add(entity3); var sum = tc.List.Items().Sum(i => i.CustomFieldNumber); var sum2 = tc.List.Items().Sum(i => i.Id); Assert.That(sum, Is.EqualTo(11 + 22 + 33)); Assert.That(sum2, Is.EqualTo(entity.Id + entity2.Id + entity3.Id)); } }
public void Is_Updating_Sync_Called_Test() { using (var ts = new TestListScope <UpdatingItem>("Is_Updating_Sync_Called_Test", true)) { ts.List.AddEventReceiver <UpdatingReceiver>(); var entity = FillCusomItem(ts); ts.List.Add(entity); var origCopy = new UpdatingItem(entity); entity = ts.List.ById(entity.Id); ModifyCustomItem(entity); ts.List.Update(entity, true); Assert.True(UpdatingItem.IsUpdateCalled, "Not fired updating receiver!"); if (UpdatingItem.Exception != null) { throw UpdatingItem.Exception; } ValidateCustomItem(UpdatingItem.ReceivedOrig, origCopy); ValidateCustomItem(UpdatingItem.ReceivedChanged, entity, true); } }
public void Query_Where_By_Two_Where_Test() { using (var tc = new TestListScope <Item>("Query_Where_By_Two_Where_Test")) { var entity = new Item { Title = "asd", }; var entity2 = new Item { Title = "zxc", }; var entity3 = new Item { Title = "zxc", }; tc.List.Add(entity); tc.List.Add(entity2); tc.List.Add(entity3); var query = tc.List.Items().Where(i => i.Id == entity2.Id).Where(i => i.Title == "zxc"); var coll = query.ToList(); Assert.That(coll.Count, Is.EqualTo(1)); Assert.That(coll[0].Id == entity2.Id); } }
public void Query_Where_CustomItem_Attr_By_Choice_Nullable_Test() { using (var tc = new TestListScope <CustomItem>("Query_Where_CustomItem_Attr_By_Choice_Nullable_Test", true)) { var entity = new CustomItem { Title = "asd", NullbleChoice = TheChoice.Choice2, }; var entity2 = new CustomItem { Title = "zxc", NullbleChoice = TheChoice.Choice3, }; tc.List.Add(entity); tc.List.Add(entity2); var query = tc.List.Items().Where(i => i.NullbleChoice == TheChoice.Choice3); var coll = query.ToList(); Assert.That(coll.Count, Is.EqualTo(1)); Assert.That(coll[0].Id == entity2.Id); query = tc.List.Items().Where(i => i.NullbleChoice == TheChoice.Choice2); coll = query.ToList(); Assert.That(coll.Count, Is.EqualTo(1)); Assert.That(coll[0].Id == entity.Id); } }
public void Doc_Updating_Async_Throws_Test() { using (var ts = new TestListScope <UpdatingDocAsync>("Is_Updating_Async_Called_Test")) { Assert.Throws <SharepointCommonException>( () => ts.List.AddEventReceiver <UpdatingDocReceiverAsync>()); } }
public void Is_Deleting_Async_Throws_Test() { using (var ts = new TestListScope <DeletingItemAsync>("Is_Deleting_Async_Throws_Test")) { Assert.Throws <SharepointCommonException>( () => ts.List.AddEventReceiver <DeletingReceiverAsync>()); } }
public void Create_Query_Test() { using (var tc = new TestListScope <Item>("Create_Query_Test")) { var query = tc.List.Items().Where(i => i.Id == 1); var coll = query.ToList(); } }
public void Ensure_List_With_Custom_Lookup() { /*Mockable.AddFieldAsXml = (collection, s) => string.Empty; * Mockable.GetFieldByInternalName = (collection, s) => null; * Mockable.FieldMapper_SetFieldProperties = (f, fi) => { };*/ using (var tls = new TestListScope <Contract>("Ensure_List_With_Custom_Lookup")) { var list = tls.List; } }
public void Get_Custom_Lookup_Value_Throws_NoOverride_Test() { using (var tls = new TestListScope <ContractBad>("Get_Custom_Lookup_Value_Throws_NoOverride_Test")) { var list = tls.List; var i = new ContractBad { }; list.Add(i); var item = list.ById(i.Id); Assert.Throws <SharepointCommonException>(() => { var project = item.Project; }); } }
public void Doc_Deleted_Sync_Called_Test() { using (var ts = new TestListScope <DeletedDoc>("Doc_Deleted_Sync_Called_Test", true)) { ts.List.AddEventReceiver <DeletedDocReceiver>(); var entity = FillCusomItem(ts); ts.List.Add(entity); ts.List.Delete(entity, false); Assert.True(DeletedDoc.IsDeleteCalled, "Not fired deleted receiver!"); Assert.That(entity.Id, Is.EqualTo(DeletedDoc.DeletedId)); if (DeletedDoc.Exception != null) { throw DeletedDoc.Exception; } } }
public void Is_Adding_Sync_Called_Test() { using (var ts = new TestListScope <AddingItem>("Is_Adding_Sync_Called_Test", true)) { ts.List.AddEventReceiver <AddingReceiver>(); var entity = FillCusomItem(ts); ts.List.Add(entity); Assert.True(AddingItem.IsAddCalled, "Not fired added receiver!"); if (AddingItem.Exception != null) { throw AddingItem.Exception; } ValidateCustomItem(AddingItem.Received, entity, true); } }
public void Doc_Deleting_Sync_Called_Test() { using (var ts = new TestListScope <DeletingDoc>("Doc_Deleting_Sync_Called_Test", true)) { ts.List.AddEventReceiver <DeletingDocReceiver>(); var entity = FillCusomItem(ts); ts.List.Add(entity); ts.List.Delete(entity, false); Assert.True(DeletingDoc.IsDeleteCalled, "Not fired added receiver!"); if (DeletingItem.Exception != null) { throw DeletingDoc.Exception; } ValidateCustomItem(DeletingDoc.Received, entity); } }
public void Query_Select_Test() { using (var tc = new TestListScope <CustomItem>("Query_Select_Test", true)) { var entity = new CustomItem { Title = "asd", CustomField1 = "zxc", Тыдыщ = "zxc" }; tc.List.Add(entity); var query = tc.List.Items() .Where(x => x.Id != 0) .Select(i => new { A = i.Title, B = i.CustomField1, C = i.Тыдыщ, }); var coll = query.ToList(); Assert.That(coll.Count, Is.EqualTo(1)); } }
public void Is_Deleted_Sync_Called_Test() { using (var ts = new TestListScope <DeletedItem>("Is_Deleted_Sync_Called_Test")) { ts.List.AddEventReceiver <DeletedReceiver>(); var entity = new DeletedItem { Title = "test1", TheText = "test2" }; ts.List.Add(entity); ts.List.Delete(entity, false); Assert.True(DeletedItem.IsDeleteCalled, "Not fired deleted receiver!"); Assert.That(entity.Id, Is.EqualTo(DeletedItem.DeletedId)); if (DeletedItem.Exception != null) { throw DeletedItem.Exception; } } }
public void Query_FirstOrDefault_Test() { using (var tc = new TestListScope <Item>("Query_FirstOrDefault_Test")) { var entity = new Item { Title = "asd", }; var entity2 = new Item { Title = "zxc", }; tc.List.Add(entity); tc.List.Add(entity2); var itm = tc.List.Items().FirstOrDefault(i => i.Title == "asd"); Assert.NotNull(itm); Assert.That(itm.Id == entity.Id); } }
public void Is_Added_Async_Called_Test() { using (var ts = new TestListScope <AddedItemAsync>("Is_Added_Async_Called_Test", true)) { ts.List.AddEventReceiver <AddedReceiverAsync>(); var entity = FillCusomItem(ts); ts.List.Add(entity); AddedItemAsync.ManualResetEvent.WaitOne(10000); Assert.True(AddedItemAsync.IsAddCalled, "Not fired added receiver!"); ValidateCustomItem(AddedItemAsync.Received, entity); if (AddedItemAsync.Exception != null) { throw AddedItemAsync.Exception; } } }
public void Query_Where_CustomItem_Attr_By_Text_Test() { using (var tc = new TestListScope <CustomItem>("Query_Where_CustomItem_Attr_By_Text_Test", true)) { var entity = new CustomItem { Title = "asd", Тыдыщ = "asd", }; var entity2 = new CustomItem { Title = "zxc", Тыдыщ = "zxc", }; tc.List.Add(entity); tc.List.Add(entity2); var query = tc.List.Items().Where(i => i.Тыдыщ == "asd"); var coll = query.ToList(); Assert.That(coll.Count, Is.EqualTo(1)); Assert.That(coll[0].Id == entity.Id); } }
public void Query_Where_CustomItem_By_Number_Test() { using (var tc = new TestListScope <CustomItem>("Query_Where_CustomItem_By_Number_Test", true)) { var entity = new CustomItem { Title = "asd", CustomFieldNumber = 123, }; var entity2 = new CustomItem { Title = "zxc", CustomFieldNumber = 256, }; tc.List.Add(entity); tc.List.Add(entity2); var query = tc.List.Items().Where(i => i.CustomFieldNumber == 256); var coll = query.ToList(); Assert.That(coll.Count, Is.EqualTo(1)); Assert.That(coll[0].Id == entity2.Id); Assert.That(coll[0].Title == entity2.Title); } }
public void Add_Remove_Receiever_Test() { using (var ts = new TestListScope <AddRemoveTest>("Add_Remove_Receiever_Test")) { ts.List.AddEventReceiver <AddRemoveReceiver>(); var entity = new AddRemoveTest { Title = "test1", TheText = "test2" }; ts.List.Add(entity); Assert.True(AddRemoveTest.IsAddCalled, "Not fired added receiver!"); ts.List.RemoveEventReceiver <AddRemoveReceiver>(); entity.Title = "asd-asd"; ts.List.Update(entity, true); Assert.False(AddRemoveTest.IsUpdateCalled, "Fired after receiver was removed!"); if (AddRemoveTest.Exception != null) { throw AddRemoveTest.Exception; } } }
public void Doc_Updated_Sync_Called_Test() { using (var ts = new TestListScope <UpdatedDoc>("Doc_Updated_Sync_Called_Test", true)) { ts.List.AddEventReceiver <UpdatedDocReceiver>(); var entity = FillCusomItem(ts); ts.List.Add(entity); entity = ts.List.ById(entity.Id); ModifyCustomItem(entity); ts.List.Update(entity, true); Assert.True(UpdatedDoc.IsUpdateCalled, "Not fired updated receiver!"); if (UpdatedDoc.Exception != null) { throw UpdatedDoc.Exception; } ValidateCustomItem(UpdatedDoc.Recieved, entity); } }
public void Get_Custom_Lookup_Value_Test() { using (var tls = new TestListScope <Contract>("Get_Custom_Lookup_Value_Test")) { var list = tls.List; var i = new Contract { Projects = new List <Item> { new Item { Id = 1, }, new Item { Id = 2, } }, }; list.Add(i); var item = list.ById(i.Id); var project = item.ProjectNew; var projects = item.Projects.ToList(); } }
public void Query_Where_CustomItem_By_Nullable_And_Bool_Test() { using (var tc = new TestListScope <CustomItem>("Query_Where_CustomItem_By_Nullable_And_Bool_Test", true)) { var entity = new CustomItem { Title = "asd", NullableBool = true, }; var entity2 = new CustomItem { Title = "zxc", NullableBool = false, }; var entity3 = new CustomItem { Title = "zxc", NullableBool = null, }; tc.List.Add(entity); tc.List.Add(entity2); tc.List.Add(entity3); var query = tc.List.Items().Where(i => i.NullableBool == true); var coll = query.ToList(); Assert.That(coll.Count, Is.EqualTo(1)); Assert.That(coll[0].Id == entity.Id); Assert.That(coll[0].Title == entity.Title); query = tc.List.Items().Where(i => i.NullableBool == false); coll = query.ToList(); Assert.That(coll.Count, Is.EqualTo(1)); Assert.That(coll[0].Id == entity2.Id); Assert.That(coll[0].Title == entity2.Title); query = tc.List.Items().Where(i => i.NullableBool == null); coll = query.ToList(); Assert.That(coll.Count, Is.EqualTo(1)); Assert.That(coll[0].Id == entity3.Id); Assert.That(coll[0].Title == entity3.Title); } }
public void Is_Updated_Sync_DisabledEvent_Test() { using (var ts = new TestListScope <UpdatedItem>("Is_Updated_Sync_DisabledEvent_Test", true)) { ts.List.AddEventReceiver <UpdatedReceiverDisabledEvent>(); var entity = FillCusomItem(ts); ts.List.Add(entity); entity = ts.List.ById(entity.Id); ModifyCustomItem(entity); ts.List.Update(entity, true); Assert.That(UpdatedItem.CalledCount, Is.EqualTo(1), "fired updated receiver on disabled!"); if (UpdatedItem.Exception != null) { throw UpdatedItem.Exception; } ValidateCustomItem(UpdatedItem.Recieved, entity); } }
private T FillCusomItem <T>(TestListScope <T> ts) where T : Item, new() { var lookupItem = new Item { Title = ts.List.Title + "_lkp1" }; ts.LookupList.Add(lookupItem); var lookupItem2 = new Item { Title = ts.List.Title + "_lkp2" }; ts.LookupList.Add(lookupItem2); var nt = new T(); if (nt is CustomItem) { var ci = nt as CustomItem; ci.Title = ts.List.Title; ci.CustomField1 = ts.List.Title + "_1"; ci.CustomField2 = ts.List.Title + "_2"; ci.CustomFieldNumber = 123.5; ci.CustomBoolean = true; ci.CustomUser = new Person(_firstUser.LoginName); ci.CustomUsers = new List <User> { new Person(_firstUser.LoginName), new User(_spGroup.Name) }; ci.CustomLookup = lookupItem; ci.CustomMultiLookup = new List <Item> { lookupItem, lookupItem2 }; ci.CustomDate = DateTime.Now; ci.CustomChoice = TheChoice.Choice2; return((T)(Item)ci); } if (nt is CustomDocument) { var cd = nt as CustomDocument; cd.Title = ts.List.Title; cd.Name = ts.List.Title + ".bin"; cd.Content = new byte[] { 10, 20, 48 }; cd.CustomField1 = ts.List.Title + "_1"; cd.CustomField2 = ts.List.Title + "_2"; cd.CustomFieldNumber = 123.5; cd.CustomBoolean = true; cd.CustomUser = new Person(_firstUser.LoginName); cd.CustomUsers = new List <User> { new Person(_firstUser.LoginName), new User(_spGroup.Name) }; cd.CustomLookup = lookupItem; cd.CustomMultiLookup = new List <Item> { lookupItem, lookupItem2 }; cd.CustomDate = DateTime.Now; cd.CustomChoice = TheChoice.Choice2; return((T)(Item)cd); } Assert.Fail(); return(null); }