Beispiel #1
0
        public async Task TestWriteImagesLocal()
        {
            string strTulipsPath = TestContent.GetContentFilePhysicalPath("/Images/Tulips.jpg");

            IFileServer server1 = new FileServerLocal("Temp", "");
            IFileQuery  file1   = new FileQuery("Tulips.jpg", "SiteImageFile");

            for (int i = 0; i < 100; i++)
            {
                server1.StoreImage(strTulipsPath, file1);
                Assert.IsTrue(server1.FileExistsLocal(file1));
                server1.Delete(file1);
                System.Threading.Thread.Sleep(5); //It seems like Delete returns before the delete is known by the file system, here's some buffer.
                Assert.IsFalse(server1.FileExistsLocal(file1));
            }

            for (int i = 0; i < 100; i++)
            {
                var   tskStore = server1.StoreImageAsync(strTulipsPath, file1);
                await tskStore;
                Assert.IsTrue(server1.FileExistsLocal(file1));
                var   tskDelete = server1.DeleteAsync(file1);
                await tskDelete;
                System.Threading.Thread.Sleep(5); //It seems like Delete returns before the delete is known by the file system, here's some buffer.
                Assert.IsFalse(server1.FileExistsLocal(file1));
            }
            Assert.IsFalse(server1.FileExistsLocal(file1));

            IFileQuery file2 = new FileQuery("TulipsFromImage.jpg", "SiteImageFile");
            IFileQuery file3 = new FileQuery("TulipsFromStream.jpg", "SiteImageFile");
            IFileQuery file4 = new FileQuery("TulipsFromImageWithTypeChange.png", "SiteImageFile");

            //Test System.Drawing.Image
            using (System.Drawing.Image objImage = System.Drawing.Image.FromFile(strTulipsPath))
            {
                await server1.StoreImageAsync(objImage, file2);
            }
            Assert.IsTrue(server1.FileExistsLocal(file2));

            //Test System.Stream
            using (System.IO.Stream stmImage = new System.IO.FileStream(strTulipsPath, System.IO.FileMode.Open))
            {
                await server1.StoreImageAsync(stmImage, file3, System.Drawing.Imaging.ImageFormat.Jpeg);

                stmImage.Close();
            }
            Assert.IsTrue(server1.FileExistsLocal(file3));

            await server1.StoreImageAsync(System.Drawing.Image.FromFile(strTulipsPath), file4, System.Drawing.Imaging.ImageFormat.Png);

            Assert.IsTrue(server1.FileExistsLocal(file4));
        }
Beispiel #2
0
        public void TestWriteFilesLocal()
        {
            string strTestJSPath = TestContent.GetContentFilePhysicalPath("/Scripts/jQuery.validate.js");

            IFileServer server1 = new FileServerLocal("Temp", "");
            IFileQuery  file1   = new FileQuery("validate.js", "Scripts");
            IFileQuery  file2   = new FileQuery("validate2.js", "Scripts");
            IFileQuery  file3   = new FileQuery("validate3.js", "Scripts");

            server1.StoreFile(strTestJSPath, file1);
            Assert.IsTrue(server1.FileExistsLocal(file1));

            server1.StoreFileAsync(strTestJSPath, file2).ContinueWith((t) => {
                Assert.IsTrue(server1.FileExistsLocal(file2));
            });

            //Test System.Stream
            using (System.IO.Stream stmFile = new System.IO.FileStream(strTestJSPath, System.IO.FileMode.Open))
            {
                server1.StoreFile(stmFile, file3);
                stmFile.Close();
            }
            Assert.IsTrue(server1.FileExistsLocal(file3));

            IFileQuery file4 = new FileQuery("text.txt", "Docs");

            server1.StoreFileFromString("this is some text § how was that", file4);
            string strLoaded = server1.LoadFileText(file4);

            Assert.AreEqual(strLoaded, "this is some text § how was that");

            IFileQuery file5 = new FileQuery("textEncodedAscii.txt", "Docs");

            server1.StoreFileFromString("this is some text § how was that", file5, Encoding.ASCII);
            strLoaded = server1.LoadFileText(file5);
            Assert.AreEqual(strLoaded, "this is some text ? how was that");
        }