예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        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);
            }
        }
예제 #5
0
        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));
            }
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
        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);
            }
        }
예제 #8
0
        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);
            }
        }
예제 #9
0
 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>());
     }
 }
예제 #10
0
 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>());
     }
 }
예제 #11
0
        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;
                });
            }
        }
예제 #14
0
        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;
                }
            }
        }
예제 #15
0
        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);
            }
        }
예제 #16
0
        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);
            }
        }
예제 #17
0
        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));
            }
        }
예제 #18
0
        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;
                }
            }
        }
예제 #19
0
        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);
            }
        }
예제 #20
0
        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;
                }
            }
        }
예제 #21
0
        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);
            }
        }
예제 #22
0
        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);
            }
        }
예제 #23
0
        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;
                }
            }
        }
예제 #24
0
        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();
            }
        }
예제 #26
0
        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);
            }
        }
예제 #27
0
        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);
            }
        }
예제 #28
0
        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);
        }