Ejemplo n.º 1
0
        public void TestImagePathVariants()
        {
            IFileServer server1 = new FileServerAzure("/Uploads/", "http://www.testdomain.com", null, AzureBucket);
            IFileQuery file1 = new FileQuery("Awesome.jpg", "Images");

            IFileServer server2 = new FileServerAzure("/Uploads/", "http://www.anotherdomain.com", null, AzureBucket);
            IFileQuery file2 = new FileQuery("Coolness.png", "ExPhotoImageFile", "/");

            string strURL, strLocalRelativePath, strPhysicalPath, strBasePath, strCDNPath;
            bool blnExistsLocal = false;
            Model.URL.URLCheckExistsResult enuExistsRemote = Model.URL.URLCheckExistsResult.Unknown;
            // Assert
            strURL = server1.GetLocalURL(file1);
            strPhysicalPath = server1.GetLocalDiskPath(file1);
            strLocalRelativePath = server1.GetLocalRelativePath(file1);
            strBasePath = server1.GetBasePath(file1);
            strCDNPath = server1.GetCDNPath(file1, true);
            blnExistsLocal = server1.FileExistsLocal(file1);
            enuExistsRemote = server1.FileExistsLocal_HTTPCheck(file1);

            Assert.IsNotNull(strURL);
            Assert.AreEqual(strURL, "http://www.testdomain.com/Uploads/Images/Awesome.jpg");
            Assert.IsNotNull(strPhysicalPath);
            Assert.IsNotNull(strLocalRelativePath);
            Assert.IsNotNull(strBasePath);
            Assert.IsNotNull(strCDNPath);
            Assert.IsTrue(Uri.IsWellFormedUriString(strURL, UriKind.Absolute));
            Assert.IsTrue(strPhysicalPath.IndexOfAny(System.IO.Path.GetInvalidPathChars()) == -1);
            Assert.IsTrue(Uri.IsWellFormedUriString(strLocalRelativePath, UriKind.Relative));
            Assert.IsTrue(Uri.IsWellFormedUriString(strBasePath, UriKind.Relative));
            Assert.IsTrue(Uri.IsWellFormedUriString(strCDNPath, UriKind.Relative));
            Assert.IsTrue(Model.URL.IsValid(strURL));
            //Assert.IsTrue(enuExistsRemote == General.Model.URL.URLCheckExistsResult.Exists);

            strURL = server2.GetLocalURL(file2);
            strPhysicalPath = server2.GetLocalDiskPath(file2);
            strLocalRelativePath = server2.GetLocalRelativePath(file2);
            strBasePath = server2.GetBasePath(file2);
            strCDNPath = server1.GetCDNPath(file1, true);
            blnExistsLocal = server2.FileExistsLocal(file2);
            enuExistsRemote = server2.FileExistsLocal_HTTPCheck(file2);

            Assert.IsNotNull(strURL);
            Assert.AreEqual(strURL, "http://www.anotherdomain.com/Uploads/ExPhotoImageFile/Coolness.png");
            Assert.IsNotNull(strPhysicalPath);
            Assert.IsNotNull(strLocalRelativePath);
            Assert.IsNotNull(strBasePath);
            Assert.IsNotNull(strCDNPath);
            Assert.IsTrue(Uri.IsWellFormedUriString(strURL, UriKind.Absolute));
            Assert.IsTrue(strPhysicalPath.IndexOfAny(System.IO.Path.GetInvalidPathChars()) == -1);
            Assert.IsTrue(Uri.IsWellFormedUriString(strLocalRelativePath, UriKind.Relative));
            Assert.IsTrue(Uri.IsWellFormedUriString(strBasePath, UriKind.Relative));
            Assert.IsTrue(Uri.IsWellFormedUriString(strCDNPath, UriKind.Relative));
            Assert.IsTrue(Model.URL.IsValid(strURL));
            //Assert.IsTrue(enuExistsRemote == General.Model.URL.URLCheckExistsResult.Exists);

            //This should not exist because it's the wrong server for the file.
            //Assert.IsTrue(server2.FileExistsLocal_HTTPCheck(file1) == General.Model.URL.URLCheckExistsResult.DoesNotExist);

        }
Ejemplo n.º 2
0
        private void Example()
        {
            //Simple example for S3...
            AmazonS3Client objAWSClient = new AmazonS3Client(Amazon.RegionEndpoint.USEast1);
            IFileServer server1 = new FileServerAmazonS3("/LocalFolder/"
            , "http://localhostedurl.com", objAWSClient, "S3BucketName");

            IFileQuery file1 = new FileQuery("Desert.jpg", "uploads/images");
            server1.StoreImage("C:\\SomeFile.jpg", file1);
            //Cleanup
            if (server1.FileExistsInCDN(file1) || server1.FileExistsLocal(file1))
                server1.Delete(file1);



            //Simple example for Azure
            Microsoft.WindowsAzure.Storage.CloudStorageAccount objCDNClient
                = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(
                ConfigurationManager.ConnectionStrings["AzureStorageConnectionString"].ConnectionString);
            IFileServer server2 = new FileServerAzure("/LocalFolder/"
            , "http://localhostedurl.com", objCDNClient, "AzureBucketName");

            IFileQuery file2 = new FileQuery("Jellyfish.jpg", "Images");
            server2.StoreImage("C:\\SomeFile.jpg", file2);
            //Cleanup
            if (server2.FileExistsInCDN(file2) || server2.FileExistsLocal(file2))
                server2.Delete(file2);






            //Look at all the ways an IFileQuery can be turned into useful paths, the file server setup 
            //is designed so that every node can store it's files in different disk paths, but a given 
            //FileQuery will find the correct file at any node, regardless of their specific configurations. 
            //The "Base" path is the portion that is common to all nodes, local and remote.

            IFileServer server3 = new FileServerAzure("/Uploads/", "http://www.testdomain.com", null, "AzureBucketName");
            IFileQuery file3 = new FileQuery("Awesome.jpg", "Images");
            string strURL, strLocalRelativePath, strPhysicalPath, strBasePath, strCDNPath;

            strURL = server3.GetLocalURL(file3);
            //http://www.testdomain.com/Uploads/Images/Awesome.jpg

            strPhysicalPath = server3.GetLocalDiskPath(file3);
            //C:\\Users\\MyUser\\Documents\\General.CDN\\General.CDN.Tests\\bin\\Debug\\Uploads\\Images\\Awesome.jpg

            strLocalRelativePath = server3.GetLocalRelativePath(file3);
            //Uploads/Images/Awesome.jpg

            strBasePath = server3.GetBasePath(file3);
            //Images/Awesome.jpg

            strCDNPath = server3.GetCDNPath(file3, true);
            //unittest/Images/Awesome.jpg

            var blnExistsLocal = server3.FileExistsLocal(file3);
            var enuExistsHTTP = server3.FileExistsLocal_HTTPCheck(file3);
            var blnExistsRemote = server3.FileExistsInCDN(file3);


            //Would you like to know if a file on your local node is up to date... try this...
            //IsCurrentVersionOf uses MD5 hash matching for files less than 10MB
            //if the file is larger or MD5 is not available in remote server... file byte size will be used for comparison
            var props1CDN = server3.GetFilePropertiesFromCDN(file3);
            var props1Local = server3.GetFilePropertiesLocal(file3);
            bool blnUpToDate = props1Local.IsCurrentVersionOf(props1CDN); 
        }
Ejemplo n.º 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));

        }
Ejemplo n.º 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));
        }
Ejemplo n.º 5
0
        private void Example()
        {
            //Simple example for S3...
            AmazonS3Client objAWSClient = new AmazonS3Client(Amazon.RegionEndpoint.USEast1);
            IFileServer    server1      = new FileServerAmazonS3("/LocalFolder/"
                                                                 , "http://localhostedurl.com", objAWSClient, "S3BucketName");

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

            server1.StoreImage("C:\\SomeFile.jpg", file1);
            //Cleanup
            if (server1.FileExistsInCDN(file1) || server1.FileExistsLocal(file1))
            {
                server1.Delete(file1);
            }



            //Simple example for Azure
            Microsoft.WindowsAzure.Storage.CloudStorageAccount objCDNClient
                = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(
                      ConfigurationManager.ConnectionStrings["AzureStorageConnectionString"].ConnectionString);
            IFileServer server2 = new FileServerAzure("/LocalFolder/"
                                                      , "http://localhostedurl.com", objCDNClient, "AzureBucketName");

            IFileQuery file2 = new FileQuery("Jellyfish.jpg", "Images");

            server2.StoreImage("C:\\SomeFile.jpg", file2);
            //Cleanup
            if (server2.FileExistsInCDN(file2) || server2.FileExistsLocal(file2))
            {
                server2.Delete(file2);
            }



            //Look at all the ways an IFileQuery can be turned into useful paths, the file server setup
            //is designed so that every node can store it's files in different disk paths, but a given
            //FileQuery will find the correct file at any node, regardless of their specific configurations.
            //The "Base" path is the portion that is common to all nodes, local and remote.

            IFileServer server3 = new FileServerAzure("/Uploads/", "http://www.testdomain.com", null, "AzureBucketName");
            IFileQuery  file3 = new FileQuery("Awesome.jpg", "Images");
            string      strURL, strLocalRelativePath, strPhysicalPath, strBasePath, strCDNPath;

            strURL = server3.GetLocalURL(file3);
            //http://www.testdomain.com/Uploads/Images/Awesome.jpg

            strPhysicalPath = server3.GetLocalDiskPath(file3);
            //C:\\Users\\MyUser\\Documents\\General.CDN\\General.CDN.Tests\\bin\\Debug\\Uploads\\Images\\Awesome.jpg

            strLocalRelativePath = server3.GetLocalRelativePath(file3);
            //Uploads/Images/Awesome.jpg

            strBasePath = server3.GetBasePath(file3);
            //Images/Awesome.jpg

            strCDNPath = server3.GetCDNPath(file3, true);
            //unittest/Images/Awesome.jpg

            var blnExistsLocal  = server3.FileExistsLocal(file3);
            var enuExistsHTTP   = server3.FileExistsLocal_HTTPCheck(file3);
            var blnExistsRemote = server3.FileExistsInCDN(file3);


            //Would you like to know if a file on your local node is up to date... try this...
            //IsCurrentVersionOf uses MD5 hash matching for files less than 10MB
            //if the file is larger or MD5 is not available in remote server... file byte size will be used for comparison
            var  props1CDN   = server3.GetFilePropertiesFromCDN(file3);
            var  props1Local = server3.GetFilePropertiesLocal(file3);
            bool blnUpToDate = props1Local.IsCurrentVersionOf(props1CDN);
        }
Ejemplo n.º 6
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));
            
        }
Ejemplo n.º 7
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");
        }