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");
        }
Beispiel #3
0
        public async Task TestAmazonCDN()
        {
            string         strDesertPath = TestContent.GetContentFilePhysicalPath("/Images/Desert.jpg");
            AmazonS3Client objAWSClient  = new AmazonS3Client(Amazon.RegionEndpoint.USEast1);

            //Test 1: Delete a file if it exists, then store an image, check it's existance, get it's properties, and compare file versions
            IFileServer server1 = new FileServerAmazonS3("LocalFolder", "http://web.com", objAWSClient, AmazonS3Bucket);

            IFileQuery file1 = new FileQuery("Desert.jpg", "uploads/images");

            if (server1.FileExistsInCDN(file1) || server1.FileExistsLocal(file1))
            {
                server1.Delete(file1);
            }
            Assert.IsFalse(server1.FileExistsInCDN(file1));
            Assert.IsFalse(server1.FileExistsLocal(file1));
            file1.MetaData.Add("test", "Value");
            server1.StoreImage(strDesertPath, file1);
            var props = server1.GetFilePropertiesFromCDN(file1);

            props.MetaData.Remove("nothing");
            Assert.IsTrue(server1.FileExistsLocal(file1));
            Assert.IsTrue(server1.FileExistsInCDN(file1));
            var props1CDN   = server1.GetFilePropertiesFromCDN(file1);
            var props1Local = server1.GetFilePropertiesLocal(file1);

            Assert.IsNotNull(props1CDN);
            Assert.IsNotNull(props1Local);
            Assert.IsTrue(props1Local.IsCurrentVersionOf(props1CDN));

            //Run Test1 with async modifiers
            IFileServer server2 = new FileServerAmazonS3("LocalFolder2", "http://web.com", objAWSClient, AmazonS3Bucket);
            IFileQuery  file21  = new FileQuery("Desert.jpg", "SiteImageFile");

            if (server1.FileExistsInCDN(file21) || server1.FileExistsLocal(file21))
            {
                server1.Delete(file21);
            }
            Assert.IsFalse(server1.FileExistsInCDN(file21));
            Assert.IsFalse(server1.FileExistsLocal(file21));
            await server2.StoreImageAsync(strDesertPath, file21);

            Assert.IsTrue(server2.FileExistsLocal(file21));
            Assert.IsTrue(server2.FileExistsInCDN(file21));
            var props2CDN   = server2.GetFilePropertiesFromCDN(file21);
            var props2Local = server2.GetFilePropertiesLocal(file21);

            Assert.IsNotNull(props2CDN);
            Assert.IsNotNull(props2Local);
            Assert.IsTrue(props2Local.IsCurrentVersionOf(props2CDN));

            //Test 2: Store a file from a Unicode text string, then retreive it and compare the strings
            IFileQuery file2 = new FileQuery("Test.txt", "Scripts");

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

            Assert.AreEqual(strFile2Text, "this is some text § how was that");
            server1.DeleteFileLocal(file2);
            Assert.IsFalse(server1.FileExistsLocal(file2));
            string test = server1.LoadFileText(file2);

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

            //Test 3: Make sure that this file, which was never uploaded, reflects that reality
            IFileQuery file3 = new FileQuery("Redfish.jpg", "uploads/images");

            Assert.IsFalse(server1.FileExistsLocal(file3));
            Assert.IsFalse(server1.FileExistsInCDN(file3));
            var strURL3 = server1.GetCDNURL(file3);

            Assert.IsTrue(Model.URL.IsValid(strURL3));
            var props2 = server1.GetFilePropertiesFromCDN(file3);

            Assert.IsNull(props2);

            //Test 4: Test each upload method
            string strKoalaPath = TestContent.GetContentFilePhysicalPath("/Images/Koala.jpg");

            System.Drawing.Image imgKoala = System.Drawing.Image.FromFile(strKoalaPath);
            IFileQuery           file4    = new FileQuery("Upload.jpg", "Images");
            string strURL;

            file4.FileName = "UploadFromFile.jpg";
            strURL         = server1.GetCDNURL(file4);
            server1.StoreImage(strKoalaPath, file4);
            Assert.IsTrue(server1.FileExistsLocal(file4));
            Assert.IsTrue(server1.FileExistsInCDN(file4));
            Assert.IsFalse(server1.FileExpiredLocal(file4));

            file4.FileName = "UploadFromImage.jpg";
            strURL         = server1.GetCDNURL(file4);
            server1.StoreImage(imgKoala, file4);
            Assert.IsTrue(server1.FileExistsLocal(file4));
            Assert.IsTrue(server1.FileExistsInCDN(file4));
            Assert.IsFalse(server1.FileExpiredLocal(file4));

            file4.FileName = "UploadFromImage.png";
            strURL         = server1.GetCDNURL(file4);
            server1.StoreImage(imgKoala, file4, System.Drawing.Imaging.ImageFormat.Png);
            Assert.IsTrue(server1.FileExistsLocal(file4));
            Assert.IsTrue(server1.FileExistsInCDN(file4));
            Assert.IsFalse(server1.FileExpiredLocal(file4));

            file4.FileName = "UploadFromStream.png";
            strURL         = server1.GetCDNURL(file4);
            var stream = new System.IO.MemoryStream();

            imgKoala.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            stream.Position = 0;
            server1.StoreImage(stream, file4);
            Assert.IsTrue(server1.FileExistsLocal(file4));
            Assert.IsTrue(server1.FileExistsInCDN(file4));
            Assert.IsFalse(server1.FileExpiredLocal(file4));

            file4.FileName = "UploadFromFileAsFile.jpg";
            strURL         = server1.GetCDNURL(file4);
            server1.StoreFile(strKoalaPath, file4);
            Assert.IsTrue(server1.FileExistsLocal(file4));
            Assert.IsTrue(server1.FileExistsInCDN(file4));
            Assert.IsFalse(server1.FileExpiredLocal(file4));

            file4.FileName = "UploadFromStreamAsFile.jpg";
            strURL         = server1.GetCDNURL(file4);
            var stream2 = new System.IO.MemoryStream();

            imgKoala.Save(stream2, System.Drawing.Imaging.ImageFormat.Jpeg);
            stream2.Position = 0;
            server1.StoreFile(stream2, file4);
            Assert.IsTrue(server1.FileExistsLocal(file4));
            Assert.IsTrue(server1.FileExistsInCDN(file4));
            Assert.IsFalse(server1.FileExpiredLocal(file4));
        }
Beispiel #4
0
        public async Task TestAzureCDN()
        {
            string strFishPath = TestContent.GetContentFilePhysicalPath("/Images/Jellyfish.jpg");

            Microsoft.WindowsAzure.Storage.CloudStorageAccount objCDNClient
                = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["AzureStorageConnectionString"].ConnectionString);
            IFileServer server1 = new FileServerAzure("LocalFolder", "", objCDNClient, AzureBucket);

            //Test 1: Delete a file if it exists, then store an image, check it's existance, get it's properties, and compare file versions
            IFileQuery file1 = new FileQuery("Jellyfish.jpg", "Images");

            if (server1.FileExistsInCDN(file1) || server1.FileExistsLocal(file1))
            {
                server1.Delete(file1);
            }
            Assert.IsFalse(server1.FileExistsInCDN(file1));
            Assert.IsFalse(server1.FileExistsLocal(file1));
            file1.MetaData.Add("test", "Value");
            server1.StoreImage(strFishPath, file1);
            var props = server1.GetFilePropertiesFromCDN(file1);

            props.MetaData.Remove("nothing");
            Assert.IsTrue(server1.FileExistsLocal(file1));
            Assert.IsTrue(server1.FileExistsInCDN(file1));
            var props1CDN   = server1.GetFilePropertiesFromCDN(file1);
            var props1Local = server1.GetFilePropertiesLocal(file1);

            Assert.IsNotNull(props1CDN);
            Assert.IsNotNull(props1Local);
            Assert.IsTrue(props1Local.IsCurrentVersionOf(props1CDN));

            //Test 2: Store a file from a Unicode text string, then retreive it and compare the strings
            IFileQuery file2 = new FileQuery("Test.txt", "Scripts");

            server1.StoreFileFromString("this is some text § how was that", file2);
            //server2.StoreFileFromString("some text", file2);
            string strFile2Text = server1.LoadFileText(file2);

            Assert.AreEqual(strFile2Text, "this is some text § how was that");
            server1.DeleteFileLocal(file2);
            Assert.IsFalse(server1.FileExistsLocal(file2));
            string test = server1.LoadFileText(file2);

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

            //Test 3: Make sure that this file, which was never uploaded, reflects that reality
            IFileQuery file3 = new FileQuery("Redfish.jpg", "uploads/images");

            Assert.IsFalse(server1.FileExistsLocal(file3));
            Assert.IsFalse(server1.FileExistsInCDN(file3));
            var strURL3 = server1.GetCDNURL(file3);

            Assert.IsTrue(Model.URL.IsValid(strURL3));
            var props2 = server1.GetFilePropertiesFromCDN(file3);

            Assert.IsNull(props2);

            //Test 4: Test each upload method
            string strKoalaPath = TestContent.GetContentFilePhysicalPath("/Images/Koala.jpg");

            System.Drawing.Image imgKoala = System.Drawing.Image.FromFile(strKoalaPath);
            IFileQuery           file4    = new FileQuery("Upload.jpg", "Images");
            string strURL;

            file4.FileName = "UploadFromFile.jpg";
            strURL         = server1.GetCDNURL(file4);
            server1.StoreImage(strKoalaPath, file4);
            Assert.IsTrue(server1.FileExistsLocal(file4));
            Assert.IsTrue(server1.FileExistsInCDN(file4));
            Assert.IsFalse(server1.FileExpiredLocal(file4));

            file4.FileName = "UploadFromImage.jpg";
            strURL         = server1.GetCDNURL(file4);
            server1.StoreImage(imgKoala, file4);
            Assert.IsTrue(server1.FileExistsLocal(file4));
            Assert.IsTrue(server1.FileExistsInCDN(file4));
            Assert.IsFalse(server1.FileExpiredLocal(file4));

            file4.FileName = "UploadFromImage.png";
            strURL         = server1.GetCDNURL(file4);
            server1.StoreImage(imgKoala, file4, System.Drawing.Imaging.ImageFormat.Png);
            Assert.IsTrue(server1.FileExistsLocal(file4));
            Assert.IsTrue(server1.FileExistsInCDN(file4));
            Assert.IsFalse(server1.FileExpiredLocal(file4));

            file4.FileName = "UploadFromStream.png";
            strURL         = server1.GetCDNURL(file4);
            var stream = new System.IO.MemoryStream();

            imgKoala.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            stream.Position = 0;
            server1.StoreImage(stream, file4);
            Assert.IsTrue(server1.FileExistsLocal(file4));
            Assert.IsTrue(server1.FileExistsInCDN(file4));
            Assert.IsFalse(server1.FileExpiredLocal(file4));

            file4.FileName = "UploadFromFileAsFile.jpg";
            strURL         = server1.GetCDNURL(file4);
            server1.StoreFile(strKoalaPath, file4);
            Assert.IsTrue(server1.FileExistsLocal(file4));
            Assert.IsTrue(server1.FileExistsInCDN(file4));
            Assert.IsFalse(server1.FileExpiredLocal(file4));

            file4.FileName = "UploadFromStreamAsFile.jpg";
            strURL         = server1.GetCDNURL(file4);
            var stream2 = new System.IO.MemoryStream();

            imgKoala.Save(stream2, System.Drawing.Imaging.ImageFormat.Jpeg);
            stream2.Position = 0;
            server1.StoreFile(stream2, file4);
            Assert.IsTrue(server1.FileExistsLocal(file4));
            Assert.IsTrue(server1.FileExistsInCDN(file4));
            Assert.IsFalse(server1.FileExpiredLocal(file4));
        }