Пример #1
0
        public void Upload_Rename_WithoutVersioning_Test()
        {
            IQueryList <Document> lib = null;

            try
            {
                lib = _queryWeb.Create <Document>("Upload_Rename_WithoutVersioning_Test");
                var document = new Document
                {
                    Name    = "Doc1.dat",
                    Content = new byte[] { 5, 10, 15, 25 },
                };
                lib.Add(document);

                var document2 = new Document
                {
                    Name           = "Doc1.dat",
                    Content        = new byte[] { 5, 10, 15, 27 },
                    RenameIfExists = true,
                };
                lib.Add(document2);

                var item = lib.Items(new CamlQuery()
                                     .Query(Q.Where(Q.Eq(Q.FieldRef <Document>(d => d.Name), Q.Value("Doc1.dat")))))
                           .FirstOrDefault();

                Assert.IsNotNull(item);
                Assert.That(item.Id, Is.EqualTo(document.Id));
                Assert.That(item.Name, Is.EqualTo(document.Name));
                Assert.That(item.Version.Major, Is.EqualTo(1));

                var item2 = lib.Items(new CamlQuery()
                                      .Query(Q.Where(Q.Eq(Q.FieldRef <Document>(d => d.Name), Q.Value("Doc1(1).dat")))))
                            .FirstOrDefault();

                Assert.IsNotNull(item2);
                Assert.That(item2.Id, Is.EqualTo(document2.Id));
                Assert.That(item2.Name, Is.EqualTo(document2.Name));
                Assert.That(item2.Version.Major, Is.EqualTo(1));
            }
            finally
            {
                if (lib != null)
                {
                    lib.DeleteList(false);
                }
            }
        }
Пример #2
0
        public void Add_Uploads_Document_To_Folder_Test()
        {
            IQueryList <Document> lib = null;

            try
            {
                lib = _queryWeb.Create <Document>("Add_Uploads_Document_To_Folder_Test");

                var document = new Document
                {
                    Name    = "Add_Uploads_Document_To_Folder_Test.dat",
                    Content = new byte[] { 5, 10, 15, 25 },
                    Folder  = "Folder1/Folder2/Folder3",
                };
                lib.Add(document);

                var item = lib.Items(new CamlQuery()
                                     .Recursive()
                                     //  .Folder(document.Url)
                                     .Query(Q.Where(Q.Eq(Q.FieldRef <Document>(d => d.Name), Q.Value("Add_Uploads_Document_To_Folder_Test.dat")))))
                           .FirstOrDefault();

                Assert.IsNotNull(item);
                Assert.That(item.Id, Is.EqualTo(document.Id));
                Assert.That(item.Name, Is.EqualTo(document.Name));
                Assert.That(item.Content, Is.Not.Null);
                Assert.That(item.Content.Length, Is.EqualTo(document.Content.Length));
                Assert.That(item.Size, Is.EqualTo(4));
                Assert.That(item.Icon, Is.EqualTo("/_layouts/images/icgen.gif"));
                Assert.That(item.Folder, Is.EqualTo(document.Folder));
                //// Assert.That(item.Title, Is.EqualTo(document.Title));
            }
            finally
            {
                if (lib != null)
                {
                    lib.DeleteList(false);
                }
            }
        }
Пример #3
0
        public void Add_Uploads_Document_Test()
        {
            IQueryList <Document> lib = null;

            try
            {
                lib = _queryWeb.Create <Document>("Add_AddsCustomItem");
                var document = new Document
                {
                    Name    = "Add_AddsCustomItem.dat",
                    Content = new byte[] { 5, 10, 15, 25 },
                };
                lib.Add(document);

                var item = lib.Items(new CamlQuery()
                                     .Query(Q.Where(Q.Eq(Q.FieldRef <Document>(d => d.Name), Q.Value("Add_AddsCustomItem.dat")))))
                           .FirstOrDefault();

                Assert.IsNotNull(item);
                Assert.That(item.Id, Is.EqualTo(document.Id));
                Assert.That(item.Name, Is.EqualTo(document.Name));
                Assert.That(item.Content, Is.Not.Null);
                Assert.That(item.Content.Length, Is.EqualTo(document.Content.Length));
                Assert.That(item.Size, Is.EqualTo(4));
                Assert.That(item.Icon, Is.EqualTo("/_layouts/images/icgen.gif"));
                Assert.That(item.Folder, Is.EqualTo(document.Folder));
                Assert.NotNull(item.Url);
                Assert.That(item.Url, Is.EqualTo(SPUtility.ConcatUrls(_queryWeb.Web.ServerRelativeUrl, "/Add_AddsCustomItem/Add_AddsCustomItem.dat")));
            }
            finally
            {
                if (lib != null)
                {
                    lib.DeleteList(false);
                }
            }
        }
Пример #4
0
        public IEnumerable <T> ExecuteCollection <T>(QueryModel queryModel)
        {
            var visitor = new CamlableVisitor <TL>();

            visitor.VisitQueryModel(queryModel);

            var caml = visitor.ToString();

            _debuggerDisplayCaml = caml;

            var camlQuery = new CamlQuery().ViewXml(caml);

            var items = _qList.Items(camlQuery);


            foreach (var resultOperator in queryModel.ResultOperators)
            {
                if (resultOperator is ResultOperators.CountResultOperator)
                {
                    var i = items.Count();
                    yield return((T)(object)i);
                }

                if (resultOperator is ResultOperators.SumResultOperator)
                {
                    var ex = Expression.Lambda(queryModel.SelectClause.Selector, Expression.Parameter(typeof(TL), "i"));


                    var tex = new RewriteMemberAccessVisitor().Execute(ex);

                    if (typeof(T) == typeof(double))
                    {
                        var tex2 = (Expression <Func <TL, double> >)tex;
                        var sum  = items.AsQueryable().Sum(tex2);
                        yield return((T)(object)sum);
                    }

                    if (typeof(T) == typeof(int))
                    {
                        var tex2 = (Expression <Func <TL, int> >)tex;
                        var sum  = items.AsQueryable().Sum(tex2);
                        yield return((T)(object)sum);
                    }
                }

                var resOp = resultOperator as ResultOperators.FirstResultOperator;
                if (resOp != null)
                {
                    if (resOp.ReturnDefaultWhenEmpty)
                    {
                        yield return((T)(object)items.FirstOrDefault());
                    }
                    else
                    {
                        yield return((T)(object)items.Single());
                    }
                }

                var skipOp = resultOperator as ResultOperators.SkipResultOperator;
                if (skipOp != null)
                {
                    var count = skipOp.GetConstantCount();
                    var skip  = items.Skip(count).Cast <T>();
                    foreach (var c in skip)
                    {
                        yield return(c);
                    }
                }

                if (resultOperator is ResultOperators.TakeResultOperator)
                {
                    var cast = items.Cast <T>();
                    foreach (var c in cast)
                    {
                        yield return(c);
                    }
                }
            }

            if (queryModel.ResultOperators.Count == 0)
            {
                var cast = CastConvert <T>(items, queryModel.SelectClause.Selector);
                foreach (var c in cast)
                {
                    yield return(c);
                }
            }
        }
Пример #5
0
        public void Add_Uploads_CustomDocument_Test()
        {
            IQueryList <CustomDocument> list = null;

            try
            {
                var lookupItem = new Item {
                    Title = "Add_Adds_CustomItem_Test_Lookup"
                };
                _listForLookup.Add(lookupItem);

                var lookupItem2 = new Item {
                    Title = "Add_Adds_CustomItem_Test_Lookup_2"
                };
                _listForLookup.Add(lookupItem2);

                list = _queryWeb.Create <CustomDocument>("Add_Uploads_CustomDocument_Test");
                var customDoc = new CustomDocument
                {
                    Title             = "Add_Uploads_CustomDocument_Test",
                    Name              = "Add_Uploads_CustomDocument_Test",
                    Content           = new byte[] { 5, 10, 15, 25 },
                    CustomField1      = "Add_Uploads_CustomDocument_Test1",
                    CustomField2      = "Add_Uploads_CustomDocument_Test2",
                    CustomFieldNumber = 123.5,
                    CustomBoolean     = true,
                    CustomLookup      = lookupItem,
                    CustomMultiLookup = new List <Item> {
                        lookupItem, lookupItem2
                    },
                    CustomDate  = new DateTime(2011, 1, 11, 18, 15, 00),
                    CustomUser  = new Person(_firstUser.LoginName),
                    CustomUsers = new List <User> {
                        new Person(_firstUser.LoginName), new User(_spGroup.Name)
                    }
                };
                list.Add(customDoc);

                var item = list.Items(new CamlQuery()
                                      .Query(Q.Where(Q.Eq(Q.FieldRef <Document>(d => d.Name), Q.Value("Add_Uploads_CustomDocument_Test")))))
                           .FirstOrDefault();

                Assert.IsNotNull(item);
                Assert.That(item.Id, Is.EqualTo(customDoc.Id));

                Assert.That(item.Name, Is.EqualTo(customDoc.Name));
                Assert.That(item.Content, Is.Not.Null);
                Assert.That(item.Content.Length, Is.EqualTo(customDoc.Content.Length));
                Assert.That(item.Size, Is.EqualTo(4));
                Assert.That(item.Icon, Is.EqualTo("/_layouts/images/icgen.gif"));
                Assert.That(item.Folder, Is.EqualTo(customDoc.Folder));

                Assert.That(item.Title, Is.EqualTo(customDoc.Title));
                Assert.That(item.CustomField1, Is.EqualTo(customDoc.CustomField1));
                Assert.That(item.CustomField2, Is.EqualTo(customDoc.CustomField2));
                Assert.That(item.CustomFieldNumber, Is.EqualTo(customDoc.CustomFieldNumber));
                Assert.That(item.CustomBoolean, Is.EqualTo(customDoc.CustomBoolean));


                Assert.That(item.CustomDate, Is.EqualTo(new DateTime(2011, 1, 11, 18, 15, 00)).Within(1).Seconds);



                Assert.That(item.CustomLookup, Is.Not.Null);
                Assert.That(item.CustomLookup.Id, Is.EqualTo(lookupItem.Id));
                Assert.That(item.CustomMultiLookup, Is.Not.Null);
                Assert.That(item.CustomMultiLookup.Count(), Is.EqualTo(2));
                Assert.That(item.CustomMultiLookup.First().Title, Is.EqualTo(lookupItem.Title));

                Assert.That(item.CustomUser.GetType().ToString(), Is.EqualTo("Castle.Proxies.PersonProxy"));

                Assert.That(item.CustomUsers.Count(), Is.EqualTo(2));
                var users = item.CustomUsers.ToList();

                Assert.That(users[0].GetType().ToString(), Is.EqualTo("Castle.Proxies.PersonProxy"));
                Assert.That(users[1].GetType().ToString(), Is.EqualTo("Castle.Proxies.UserProxy"));
            }
            finally
            {
                if (list != null)
                {
                    list.DeleteList(false);
                }
            }
        }
Пример #6
0
        public void Add_Uploads_CustomDocument_Test()
        {
            IQueryList <CustomDocument> list = null;

            try
            {
                var lookupItem = new Item {
                    Title = "Add_Adds_CustomItem_Test_Lookup"
                };
                _listForLookup.Add(lookupItem);

                var lookupItem2 = new Item {
                    Title = "Add_Adds_CustomItem_Test_Lookup_2"
                };
                _listForLookup.Add(lookupItem2);

                list = _queryWeb.Create <CustomDocument>("Add_Uploads_CustomDocument_Test");
                var customDoc = new CustomDocument
                {
                    Title             = "Add_Uploads_CustomDocument_Test",
                    Name              = "Add_Uploads_CustomDocument_Test",
                    Content           = new byte[] { 5, 10, 15, 25 },
                    CustomField1      = "Add_Uploads_CustomDocument_Test1",
                    CustomField2      = "Add_Uploads_CustomDocument_Test2",
                    CustomFieldNumber = 123.5,
                    CustomBoolean     = true,
                    CustomLookup      = lookupItem,
                    CustomMultiLookup = new List <Item> {
                        lookupItem, lookupItem2
                    },
                    CustomDate = DateTime.Now,
                };
                list.Add(customDoc);

                var item = list.Items(new CamlQuery()
                                      .Query(Q.Where(Q.Eq(Q.FieldRef <Document>(d => d.Name), Q.Value("Add_Uploads_CustomDocument_Test")))))
                           .FirstOrDefault();

                Assert.IsNotNull(item);
                Assert.That(item.Id, Is.EqualTo(customDoc.Id));

                Assert.That(item.Name, Is.EqualTo(customDoc.Name));
                Assert.That(item.Content, Is.Not.Null);
                Assert.That(item.Content.Length, Is.EqualTo(customDoc.Content.Length));
                Assert.That(item.Size, Is.EqualTo(4));
                Assert.That(item.Icon, Is.EqualTo("/_layouts/images/icgen.gif"));
                Assert.That(item.Folder, Is.EqualTo(customDoc.Folder));

                Assert.That(item.Title, Is.EqualTo(customDoc.Title));
                Assert.That(item.CustomField1, Is.EqualTo(customDoc.CustomField1));
                Assert.That(item.CustomField2, Is.EqualTo(customDoc.CustomField2));
                Assert.That(item.CustomFieldNumber, Is.EqualTo(customDoc.CustomFieldNumber));
                Assert.That(item.CustomBoolean, Is.EqualTo(customDoc.CustomBoolean));
                Assert.That(item.CustomLookup, Is.Not.Null);
                Assert.That(item.CustomLookup.Id, Is.EqualTo(lookupItem.Id));
                Assert.That(item.CustomMultiLookup, Is.Not.Null);
                Assert.That(item.CustomMultiLookup.Count(), Is.EqualTo(2));
                Assert.That(item.CustomMultiLookup.First().Title, Is.EqualTo(lookupItem.Title));
            }
            finally
            {
                if (list != null)
                {
                    list.DeleteList(false);
                }
            }
        }