Esempio n. 1
0
        public void TestDeleteFile()
        {
            // Upload so we have something to delete //
            var jiffyResult = SharpCrush.UploadFile("./TestFiles/jiffy.gif");

            Assert.IsTrue(jiffyResult.Result == FileUploadResults.AlreadyUploaded || jiffyResult.Result == FileUploadResults.Successful);


            // == Try to delete out stuff == //

            var shouldDelete = SharpCrush.DeleteFile(jiffyResult.FileHash);

            // Deletion is broken: https://github.com/MediaCrush/MediaCrush/issues/356 //
            //TODO: Assert.IsTrue(shouldDelete == DeleteFileResult.Successful);



            // == Try to delete not our stuff == //

            var wontDelete = SharpCrush.DeleteFile("CPvuR5lRhmS0");

            Assert.IsTrue(wontDelete == DeleteFileResult.NotAllowed);



            // == Try to delete things that not exist == //

            var cantDelete = SharpCrush.DeleteFile("ThisDoesntExist");

            Assert.IsTrue(cantDelete == DeleteFileResult.FileNotFound);
        }
Esempio n. 2
0
        public void TestUploadFile()
        {
            var jaypegResult = SharpCrush.UploadFile("./TestFiles/jaypeg.jpg");

            Assert.IsTrue(jaypegResult.Result == FileUploadResults.AlreadyUploaded || jaypegResult.Result == FileUploadResults.Successful);

            var jiffyResult = SharpCrush.UploadFile("./TestFiles/jiffy.gif");

            Assert.IsTrue(jiffyResult.Result == FileUploadResults.AlreadyUploaded || jiffyResult.Result == FileUploadResults.Successful);
        }
Esempio n. 3
0
        public void TestGetInfo()
        {
            var shouldBe404 = SharpCrush.GetFileInfo("LxqXxVPAvqqB");

            Assert.IsTrue(shouldBe404.StatusCode == 404);

            var shouldBeGood = SharpCrush.GetFileInfo("tVWMM_ziA3nm");

            Assert.IsTrue(shouldBeGood.StatusCode == 200);
            Assert.IsNotNull(shouldBeGood.Files);
            Assert.IsNotNull(shouldBeGood.Original);
            Assert.IsNotNull(shouldBeGood.OriginalFileType);
        }
Esempio n. 4
0
        public void TestGetFileStatus()
        {
            var jaypeg = SharpCrush.UploadFile("./TestFiles/jaypeg.jpg");

            var stat1 = jaypeg.Status;

            // OR

            var stat2 = SharpCrush.GetFileStatus(jaypeg.FileHash);

            // The only way this would fail, is if they status changed with in the execution of stat1 and stat2. So about ~ 5ms //
            Assert.IsTrue(stat1 == stat2);

            // Will fail. See: https://github.com/MediaCrush/MediaCrush/issues/356 //
            Assert.IsTrue(stat1 == GetFileStatusResult.Done || stat1 == GetFileStatusResult.Processing);
        }
Esempio n. 5
0
        public void TestGetInfos()
        {
            var files = SharpCrush.GetFileInfos("tVWMM_ziA3nm", "CPvuR5lRhmS0");

            Assert.IsTrue(files.Count == 2);

            var firstFile = files["CPvuR5lRhmS0"];

            Assert.IsTrue(firstFile.StatusCode == 200);
            Assert.IsNotNull(firstFile.Files);
            Assert.IsNotNull(firstFile.Original);
            Assert.IsNotNull(firstFile.OriginalFileType);

            var secondFile = files["tVWMM_ziA3nm"];

            Assert.IsTrue(secondFile.StatusCode == 200);
            Assert.IsNotNull(secondFile.Files);
            Assert.IsNotNull(secondFile.Original);
            Assert.IsNotNull(secondFile.OriginalFileType);
        }
Esempio n. 6
0
        public void UploadFile(string file)
        {
            // Modify UI
            if (FileList.Count == 0)
            {
                rowCollapse1.Height = new GridLength(0);
                rowCollapse2.Height = new GridLength(0);
                rowExpand.Height    = new GridLength(5, GridUnitType.Star);
                uploadingFilesContainer.Visibility = Visibility.Visible;
                uploadingFiles.ItemsSource         = FileList;
                clearButton.Visibility             = System.Windows.Visibility.Visible;
            }
            var uploadingFile = new UploadingFile(file);

            FileList.Add(uploadingFile);
            Task.Factory.StartNew(() =>
            {
                var hash           = SharpCrush.GetFileHash(File.ReadAllBytes(file));
                uploadingFile.Hash = hash;
                if (SharpCrush.GetFileExists(hash))
                {
                    uploadingFile.Status = UploadingFile.FileStatus.Finished;
                }
                else
                {
                    // Upload
                    SharpCrush.UploadFileAsync(uploadingFile.File, (s, e) => uploadingFile.Progress = e.ProgressPercentage / 100.0, result =>
                    {
                        uploadingFile.Status = UploadingFile.FileStatus.Processing;
                        while (SharpCrush.GetFileStatus(hash) == GetFileStatusResult.Processing)
                        {
                            ;
                        }
                        uploadingFile.Status = UploadingFile.FileStatus.Finished;
                    });
                }
            });
        }
Esempio n. 7
0
 /// <summary>
 /// Deletes this file.
 /// </summary>
 /// <returns>The result of the file deletion</returns>
 /// <remarks>Same as doing <see cref="SharpCrush.DeleteFile(string)"/></remarks>
 public DeleteFileResult Delete()
 {
     return(SharpCrush.DeleteFile(FileHash));
 }
Esempio n. 8
0
 public void TestFileExists()
 {
     Assert.IsFalse(SharpCrush.GetFileExists("LxqXxVPAvqqB"));
     Assert.IsTrue(SharpCrush.GetFileExists("tVWMM_ziA3nm"));
 }