Ejemplo n.º 1
0
        private void testOneType(SPOClient spoc, SPOList spoList, string type, string name, string value)
        {
            SPOField field = spoc.GetFields(spoList).Where(n => n.Title == name).First();

            field.Value = value;
            List <SPOField> fields = new List <SPOField>()
            {
                field
            };
            int itemId = spoc.AddDocument(spoList, null, null, fields);

            field.Value = null;
            spoc.GetFieldValues(spoList, itemId, fields);

            if (value == string.Empty)
            {
                Assert.IsNull(fields[0].Value);
                return;
            }
            // My theory on how things work:
            // Client -> Server: csom takes string and gives it to SharePoint. It is parsed by SharePoints culture
            // Server -> Client: csom receives data and converts it to string according to current culture
            Assert.AreEqual(
                normalize(spoc.ClientCulture, type, value),
                normalize(CultureInfo.CurrentCulture, type, fields[0].Value));
        }
Ejemplo n.º 2
0
        private void t08_ListItemCount1(SPOClient spoc, bool isLibrary, string listname)
        {
            try { spoc.DeleteList(listname); } catch { };

            // Create list or library with one column
            SPOList spol = createListOrLibrary(spoc, isLibrary, listname,
                                               new List <SPOClient.FieldSpec>()
            {
                new SPOClient.FieldSpec()
                {
                    Name = "mySingleTextLine", Type = "Text"
                }
            });

            string foldername = "a/b/";

            var td = new[]
            {
                new { withFolder = true, root = 1, folder = 1 },
                new { withFolder = false, root = 2, folder = 1 },
                new { withFolder = false, root = 3, folder = 1 },
                new { withFolder = true, root = 3, folder = 2 },
            };

            verifyFolderContent(spoc, spol, "", 0);
            verifyFolderContent(spoc, spol, foldername, -1);

            for (int i = 0; i != td.Length; i++)
            {
                addDocument(spoc, spol, (td[i].withFolder ? foldername : string.Empty) + "Document_" + i + ".pdf");
                verifyFolderContent(spoc, spol, "", td[i].root);
                verifyFolderContent(spoc, spol, foldername, td[i].folder);
            }
            deleteListOrLibrary(spoc, listname);
        }
Ejemplo n.º 3
0
        private void t05_AddDocument1(SPOTestSystem ts, bool isLibrary, string listName)
        {
            SPOClient spoc = createClient(ts) as SPOClient;

            spoc.Login();

            // Create list or library with one column
            SPOList spol = createListOrLibrary(spoc, isLibrary, listName,
                                               new List <SPOClient.FieldSpec>()
            {
                new SPOClient.FieldSpec()
                {
                    Name = "mySingleTextLine", Type = "Text"
                }
            });

            // Test without and with subfodlers.
            // Always twice to handle the case where stuff already exists.
            addDocument(spoc, spol, "/MyFirstDocument.pdf");
            addDocument(spoc, spol, "MyFirstDocument.pdf");
            addDocument(spoc, spol, "sub/subsub/MyFirstDocument.pdf");
            addDocument(spoc, spol, "/sub/subsub/MySecondDocument.pdf");

            deleteListOrLibrary(spoc, listName);
        }
Ejemplo n.º 4
0
 private SPOList createListOrLibrary(
     SPOClient spoc,
     bool isLibrary,
     string name, List <SPOClient.FieldSpec> fieldSpecs = null)
 {
     try { spoc.DeleteList(name); } catch (Exception e) { var x = e.Message; }
     return(spoc.CreateList(name, isLibrary, fieldSpecs));
 }
Ejemplo n.º 5
0
        private ISPOClient createClient(SPOTestSystem ts)
        {
            SPOClient spoClient = new SPOClient();

            spoClient.Office365 = ts.Office365;
            spoClient.SiteUrl   = ts.SiteUrl;
            spoClient.Username  = ts.Username;
            spoClient.SetPassowrd(ts.Password);
            spoClient.ClientCulture = new CultureInfo("en-US", false);
            return(spoClient);
        }
Ejemplo n.º 6
0
        /// This is not really a unit test but some place to play around.
        public void t00_TestAndExplore()
        {
            CultureInfo ci = new CultureInfo("en-US", false);
            DateTime    dt;

            dt = DateTime.Parse("february/15/2017", ci);
            dt = DateTime.Parse("02/15/2017", ci);

            SPOClient spoc = createClient(testsystems.Where(n => n.TestSystemName == "vmsp2013").First()) as SPOClient;

            spoc.Login();
        }
Ejemplo n.º 7
0
 public void t08_ListItemCount()
 {
     foreach (SPOTestSystem ts in testsystems)
     {
         if (ts.Active)
         {
             SPOClient spoc = createClient(ts) as SPOClient;
             spoc.Login();
             t08_ListItemCount1(spoc, false, unitTestList);
             t08_ListItemCount1(spoc, true, unitTestLibrary);
         }
     }
 }
Ejemplo n.º 8
0
        private void t06_ColumnTypes1(SPOTestSystem ts)
        {
            SPOClient spoc = createClient(ts) as SPOClient;

            spoc.Login();

            SPOList spol = createListOrLibrary(spoc, false, unitTestList);

            var td = new[]
            {
                new { n = 00, type = "Text", value = "HelloWorld", culture = "en-US" },
                new { n = 10, type = "DateTime", value = "02/15/2017", culture = "en-US" },
                new { n = 11, type = "DateTime", value = "15.02.2017", culture = "de-DE" },
                new { n = 12, type = "DateTime", value = "", culture = "de-DE" },
                new { n = 20, type = "Note", value = "Line1\nLine2", culture = "en-US" },
                new { n = 30, type = "Choice", value = "Berlin", culture = "en-US" },
                new { n = 40, type = "Number", value = "12.34", culture = "en-US" },
                new { n = 41, type = "Number", value = "12,34", culture = "de-DE" },
                new { n = 42, type = "Number", value = "", culture = "de-DE" },
                new { n = 50, type = "Currency", value = "14.22", culture = "en-US" },
                new { n = 51, type = "Currency", value = "", culture = "en-US" },
                new { n = 60, type = "Boolean", value = "False", culture = "en-US" },
                //new { n = 7, type = "Lookup", value = "abc", },
                //new { n = 8, type = "User", value = @"0#.w|vmsp2013\administrator", },
            };
            int doOnly = -1;

            for (int i = 0; i != td.Length; i++)
            {
                if (doOnly > 0 && td[i].n != doOnly)
                {
                    continue;
                }

                string name = "a" + td[i].type;
                string type = td[i].type;
                spoc.AddFieldToList(spol, new SPOClient.FieldSpec()
                {
                    Name = name, Type = type
                });
                spoc.ClientCulture = new CultureInfo(td[i].culture, false);
                testOneType(spoc, spol, type, name, td[i].value);
                spoc.DeleteField(spol, name);
            }
            Assert.IsTrue(doOnly < 0, "Not all tests executed");

            deleteListOrLibrary(spoc, unitTestList);
        }
Ejemplo n.º 9
0
        private void reallyRemoveTestLists(SPOTestSystem ts, string listname)
        {
            // http://stackoverflow.com/questions/42146301/deleting-list-does-not-work-list-does-not-exist

            SPOClient spoc = createClient(ts) as SPOClient;

            spoc.Login();

            try { spoc.DeleteList(listname); } catch (Exception e) { var x = e.Message; }
            spoc.CreateList(listname, false);

            spoc = createClient(ts) as SPOClient;
            spoc.Login();

            spoc.DeleteList(listname);
            spoc.Dispose();
        }
Ejemplo n.º 10
0
        private void t08_ListCreation1(SPOTestSystem ts)
        {
            SPOClient spoc = createClient(ts) as SPOClient;

            spoc.Login();

            string listname = unitTestList;

            //string listname = "abc";

            try { spoc.DeleteList(listname); } catch (Exception e) { var x = e.Message; }
            spoc.CreateList(listname, false);

            spoc = createClient(ts) as SPOClient;
            spoc.Login();

            spoc.DeleteList(listname);
        }
Ejemplo n.º 11
0
        private void addDocument(SPOClient spoc, SPOList spol, string documentPath)
        {
            // fields should contain just the one custom column..
            List <SPOField> fields = spoc.GetFields(spol).Where(n => n.Title != "Title").ToList();

            // Set a field value and upload document
            foreach (SPOField f in fields)
            {
                f.Value = "Hello World!";
            }
            int itemId = spoc.AddDocument(spol, documentPath, testDocument, fields);

            // Verify that the attribute is set
            foreach (SPOField f in fields)
            {
                f.Value = null;
            }
            spoc.GetFieldValues(spol, itemId, fields);
            foreach (SPOField f in fields)
            {
                Assert.AreEqual("Hello World!", f.Value);
            }
            //spoc.DeleteItem(spol, itemId);
        }
Ejemplo n.º 12
0
 private void deleteListOrLibrary(SPOClient spoc, string name)
 {
     try { spoc.DeleteList(name); } catch { }
 }
Ejemplo n.º 13
0
 public void verifyFolderContent(SPOClient spoc, SPOList spol, string foldername, int folderCnt)
 {
     Assert.AreEqual(folderCnt, spoc.GetFolderCount(spol, foldername));
 }
Ejemplo n.º 14
0
        public void t07_CalculateMissingFolders()
        {
            SPOClient     spoClient = createClient(testsystems.First()) as SPOClient; // pick arbitrarily
            PrivateObject po        = new PrivateObject(spoClient);

            po.SetField("serverUrl", "http://Server/mySite/");
            po.SetField("serverAuthority", "http://Server");
            po.SetField("serverPath", "/mySite/");

            List <string> existingFolders = new List <string>()
            {
                "/mySite/Lists/listTitle/a/b/c/d",
                "/mySite/Lists/listTitle/a/b/c",
                "/mySite/Lists/listTitle/a/b",
                "/mySite/Lists/listTitle/a",
                "/mySite/Lists/listTitle/xyz",
            };
            string filename = "a/b/c/Document.pdf";
            List <SPOClient.FolderCreationSpec> result;
            string basepath          = "http://Server/mySite/Lists/listTitle";
            string serverRelativeUrl = "/mySite/Lists/listTitle";

            var td = new[]
            {
                new { n = 0, result = new List <SPOClient.FolderCreationSpec>()
                      {
                      }, },
                new { n = 1, result = new List <SPOClient.FolderCreationSpec>()
                      {
                      }, },
                new { n = 2, result = new List <SPOClient.FolderCreationSpec>()
                      {
                          new SPOClient.FolderCreationSpec()
                          {
                              Path = basepath + "/a/b", Foldername = "c",
                          },
                      }, },
                new { n = 3, result = new List <SPOClient.FolderCreationSpec>()
                      {
                          new SPOClient.FolderCreationSpec()
                          {
                              Path = basepath + "/a", Foldername = "b",
                          },
                          new SPOClient.FolderCreationSpec()
                          {
                              Path = basepath + "/a/b", Foldername = "c",
                          },
                      }, },
                new { n = 4, result = new List <SPOClient.FolderCreationSpec>()
                      {
                          new SPOClient.FolderCreationSpec()
                          {
                              Path = basepath, Foldername = "a",
                          },
                          new SPOClient.FolderCreationSpec()
                          {
                              Path = basepath + "/a", Foldername = "b",
                          },
                          new SPOClient.FolderCreationSpec()
                          {
                              Path = basepath + "/a/b", Foldername = "c",
                          },
                      }, },
            };
            int doOnly = -1;

            for (int i = 0; i != td.Length; i++)
            {
                if (doOnly != -1 && td[i].n != doOnly)
                {
                    continue;
                }

                List <string> ef = existingFolders.Skip(td[i].n).ToList();
                result = (List <SPOClient.FolderCreationSpec>)
                         po.Invoke("calculateFolderCreationSequence",
                                   new object[3] {
                    serverRelativeUrl, ef, filename
                });

                Assert.AreEqual(td[i].result.Count, result.Count);
                for (int j = 0; j < td[i].result.Count; j++)
                {
                    Assert.AreEqual(td[i].result[j].Path, result[j].Path);
                    Assert.AreEqual(td[i].result[j].Foldername, result[j].Foldername);
                }
            }
            foreach (string fn in new List <string>()
            {
                "Document.pdf", "/Dokument.pdf"
            })
            {
                result = (List <SPOClient.FolderCreationSpec>)
                         po.Invoke("calculateFolderCreationSequence",
                                   new object[3] {
                    "listTitle", existingFolders, fn
                });
                Assert.AreEqual(0, result.Count());
            }
            Assert.AreEqual(-1, doOnly, "Not all tests executed");
        }