コード例 #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 Moq_QueryWeb_Test()
        {
            var moqQueryWeb  = new Mock <IQueryWeb>();
            var moqQueryList = new Mock <IQueryList <Item> >(MockBehavior.Strict);

            moqQueryWeb.Setup(m => m.GetByName <Item>(It.IsAny <string>()))
            .Returns(moqQueryList.Object);

            moqQueryList.Setup(m => m.Add(It.IsAny <Item>()));

            IQueryWeb queryWeb = moqQueryWeb.Object;

            IQueryList <Item> list = queryWeb.GetByName <Item>("Test");

            list.Add(new Item());
        }
コード例 #3
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);
                }
            }
        }
コード例 #4
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);
                }
            }
        }
コード例 #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);
                }
            }
        }