Пример #1
0
        public WebDavApiTest()
        {
            //Report.LogDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test", "WebDavApiTest");

            if (Directory.Exists(mainDir))
            {
                Directory.Delete(mainDir, true);
            }

            Directory.CreateDirectory(NestedDir1_1);
            Directory.CreateDirectory(NestedDir1_2);
            Directory.CreateDirectory(NestedDir2_1);
            Directory.CreateDirectory(NestedDir2_2);

            foreach (var f in Directory.GetFiles(@"D:\Spectra\2020", "*.cnf", SearchOption.AllDirectories).Take(5).ToArray())
            {
                File.Copy(f, Path.Combine(NestedDir1_1, Path.GetFileName(f)));
                File.Copy(f, Path.Combine(NestedDir1_2, Path.GetFileName(f)));
                File.Copy(f, Path.Combine(NestedDir2_1, Path.GetFileName(f)));
                File.Copy(f, Path.Combine(NestedDir2_2, Path.GetFileName(f)));
            }

            if (WebDavClientApi.IsExistsAsync(mainDir, _cts.Token).Result)
            {
                WebDavClientApi.RemoveFileAsync(mainDir, _cts.Token).Wait();
            }
        }
Пример #2
0
        public async Task UploadAndDownloadFileTest()
        {
            var tokens = new Dictionary <string, string>();
            var files  = Directory.GetFiles(mainDir, "*.cnf", SearchOption.AllDirectories);

            foreach (var f in files)
            {
                Assert.IsTrue(await WebDavClientApi.UploadFileAsync(f, _cts.Token));
                Assert.IsTrue(await WebDavClientApi.IsExistsAsync(f, _cts.Token));
                tokens[await WebDavClientApi.MakeShareableAsync(f, _cts.Token)] = f;
            }

            Assert.AreEqual(files.Length, tokens.Count);

            foreach (var t in tokens.Keys)
            {
                await WebDavClientApi.DownloadFileAsync(t, tokens[t].Replace("WebDavApiTest", "WebDavApiTest_Downloaded"), _cts.Token);

                Assert.IsTrue(File.Exists(tokens[t].Replace("WebDavApiTest", "WebDavApiTest_Downloaded")));
            }

            Assert.IsTrue(await WebDavClientApi.IsExistsAsync(mainDir, _cts.Token));
            Assert.IsTrue(await WebDavClientApi.RemoveFileAsync(mainDir, _cts.Token));
            Assert.IsFalse(await WebDavClientApi.IsExistsAsync(mainDir, _cts.Token));

            Assert.AreEqual(files.Length, Directory.GetFiles(mainDir_Downloaded, "*.cnf", SearchOption.AllDirectories).Length);


            Assert.IsTrue(Directory.Exists(mainDir_Downloaded));
            Directory.Delete(mainDir_Downloaded, true);
            Assert.IsFalse(Directory.Exists(mainDir_Downloaded));
        }
Пример #3
0
        public void Dispose()
        {
            if (Directory.Exists(mainDir))
            {
                Directory.Delete(mainDir, true);
            }

            if (Directory.Exists(mainDir_Downloaded))
            {
                Directory.Delete(mainDir_Downloaded, true);
            }

            if (WebDavClientApi.IsExistsAsync(mainDir, _cts.Token).Result)
            {
                WebDavClientApi.RemoveFileAsync(mainDir, _cts.Token).Wait();
            }
        }
Пример #4
0
        public async Task CreateAndRemoveFolderTest()
        {
            await WebDavClientApi.CreateFolderAsync(NestedDir1_1, _cts.Token);

            Assert.IsTrue(await WebDavClientApi.IsExistsAsync(NestedDir1_1, _cts.Token));

            await WebDavClientApi.CreateFolderAsync(NestedDir1_2, _cts.Token);

            Assert.IsTrue(await WebDavClientApi.IsExistsAsync(NestedDir1_2, _cts.Token));

            await WebDavClientApi.CreateFolderAsync(NestedDir2_1, _cts.Token);

            Assert.IsTrue(await WebDavClientApi.IsExistsAsync(NestedDir2_1, _cts.Token));

            await WebDavClientApi.CreateFolderAsync(NestedDir2_1, _cts.Token);

            Assert.IsTrue(await WebDavClientApi.IsExistsAsync(NestedDir2_1, _cts.Token));

            Assert.IsTrue(await WebDavClientApi.IsExistsAsync(mainDir, _cts.Token));
            Assert.IsTrue(await WebDavClientApi.RemoveFileAsync(mainDir, _cts.Token));
            Assert.IsFalse(await WebDavClientApi.IsExistsAsync(mainDir, _cts.Token));
        }