public void GetPermsTest()
        {
            var perms = GoogleDriveUtility.GetResourcePermissions(GetConnection(), testFolder.Id);

            Assert.IsTrue(perms.IsSucceed);
            Assert.IsTrue(perms.Data.Any(x => x.Role == GoogleDriveRole.owner && x.Type == GoogleDrivePermType.user));
        }
        public void DeleteFolderTest()
        {
            GoogleDriveResultWithData <GoogleDriveFolder> createdFolder = null;

            try
            {
                createdFolder = GoogleDriveUtility.CreateFolder(GetConnection(), TestData.TestFolderName, testFolder.Id);
                Assert.IsTrue(createdFolder.IsSucceed);

                var folderListBefore = GoogleDriveUtility.GetFolders(GetConnection(), testFolder.Id);
                Assert.IsTrue(folderListBefore.IsSucceed);

                GoogleDriveUtility.DeleteResource(GetConnection(), createdFolder.Data.Id);

                var folderListAfter = GoogleDriveUtility.GetFolders(GetConnection(), testFolder.Id);
                Assert.IsTrue(folderListAfter.IsSucceed);

                Assert.AreEqual(1, folderListBefore.Data.Length - folderListAfter.Data.Length);
            }
            finally
            {
                try
                {
                    if (createdFolder != null)
                    {
                        GoogleDriveUtility.DeleteResource(GetConnection(), createdFolder.Data.Id);
                    }
                }
                catch { }
            }
        }
Пример #3
0
        public void DeleteFileTest()
        {
            var uploadResult = GoogleDriveUtility.UploadFile(GetConnection(), TestFileFullName, null, testFolder.Id);

            try
            {
                var fileListBefore = GoogleDriveUtility.GetFiles(GetConnection(), testFolder.Id);
                Assert.IsTrue(fileListBefore.IsSucceed);

                var delResult = GoogleDriveUtility.DeleteResource(GetConnection(), uploadResult.Data.Id);
                Assert.IsTrue(delResult.IsSucceed);

                var fileListAfter = GoogleDriveUtility.GetFiles(GetConnection(), testFolder.Id);
                Assert.IsTrue(fileListAfter.IsSucceed);

                Assert.AreEqual(1, fileListBefore.Data.Length - fileListAfter.Data.Length);
            }
            finally
            {
                try
                {
                    GoogleDriveUtility.DeleteResource(GetConnection(), uploadResult.Data.Id);
                }
                catch { }
            }
        }
Пример #4
0
        public void SetIncorrectPermsTest()
        {
            var newPermission    = new GoogleDrivePermission(null, TestData.TestEmail, GoogleDrivePermType.user, GoogleDriveRole.writer);
            var permissionResult = GoogleDriveUtility.SetResourcePermissions(GetConnection(), "incorrect Id", newPermission);

            Assert.IsFalse(permissionResult.IsSucceed);
        }
        public void ListFoldersTest()
        {
            var rootFileList = GoogleDriveUtility.GetFolders(GetConnection(), null);

            Assert.IsTrue(rootFileList.IsSucceed);

            var testFolderFileList = GoogleDriveUtility.GetFolders(GetConnection(), testFolder.Id);

            Assert.IsTrue(rootFileList.IsSucceed);
        }
        public void SetPermsTest()
        {
            var permission = GoogleDriveUtility.SetResourcePermissions(GetConnection(), testFolder.Id, new GoogleDrivePermission(null, TestData.TestEmail, GoogleDrivePermType.user, GoogleDriveRole.writer));

            Assert.IsTrue(permission.IsSucceed);
            Assert.IsTrue(permission.Data.Id != "");

            var perms = GoogleDriveUtility.GetResourcePermissions(GetConnection(), testFolder.Id);

            var res = Enumerable.Any(perms.Data, (it) => { return(it.Id == permission.Data.Id); });

            Assert.IsTrue(res);
        }
Пример #7
0
        public void InitTests()
        {
            const int LINE_COUNT = 3;
            var       stream     = new System.IO.StreamWriter(TestFileFullName);

            for (int i = 0; i < LINE_COUNT; i++)
            {
                stream.Write($"{i}qwertyuiop\n");
            }
            stream.Close();

            testFolder = GoogleDriveUtility.CreateFolder(GetConnection(), TestData.TestFolderName, null).Data;
        }
Пример #8
0
        public void DownloadIncorrectFileTest()
        {
            string localFileName = TestFileFullName + "_";

            try
            {
                var downloadResult = GoogleDriveUtility.DownloadFile(GetConnection(), "incorrect id", localFileName);
                Assert.IsFalse(downloadResult.IsSucceed);
            }
            finally
            {
                System.IO.File.Delete(localFileName);
            }
        }
Пример #9
0
        public void GetPermsTest()
        {
            var uploadResult = GoogleDriveUtility.UploadFile(GetConnection(), TestFileFullName, null, testFolder.Id);

            try
            {
                var permissionResult = GoogleDriveUtility.GetResourcePermissions(GetConnection(), uploadResult.Data.Id);
                Assert.IsTrue(permissionResult.IsSucceed);
                Assert.IsTrue(permissionResult.Data.Length > 0);
            }
            finally
            {
                GoogleDriveUtility.DeleteResource(GetConnection(), uploadResult.Data.Id);
            }
        }
Пример #10
0
        public void UploadFileTest()
        {
            GoogleDriveResultWithData <GoogleDriveFile> uploadResult = null;

            try
            {
                uploadResult = GoogleDriveUtility.UploadFile(GetConnection(), TestFileFullName, null, testFolder.Id);
                Assert.IsTrue(uploadResult.IsSucceed);
                Assert.IsNotNull(uploadResult.Data);
            }
            finally
            {
                if (uploadResult != null && uploadResult.Data != null)
                {
                    GoogleDriveUtility.DeleteResource(GetConnection(), uploadResult.Data.Id);
                }
            }
        }
        public void CreateFolderTest()
        {
            GoogleDriveResultWithData <GoogleDriveFolder> createdFolder = null;

            try
            {
                createdFolder = GoogleDriveUtility.CreateFolder(GetConnection(), TestData.TestFolderName, testFolder.Id);
                Assert.IsTrue(createdFolder.IsSucceed);
                Assert.IsNotNull(createdFolder.Data);
            }
            finally
            {
                if (createdFolder != null)
                {
                    GoogleDriveUtility.DeleteResource(GetConnection(), createdFolder.Data.Id);
                }
            }
        }
Пример #12
0
        public void SetPermsTest()
        {
            var uploadResult = GoogleDriveUtility.UploadFile(GetConnection(), TestFileFullName, null, testFolder.Id);

            try
            {
                var newPermission = new GoogleDrivePermission(null, TestData.TestEmail, GoogleDrivePermType.user, GoogleDriveRole.writer);
                var permission    = GoogleDriveUtility.SetResourcePermissions(GetConnection(), uploadResult.Data.Id, newPermission);
                Assert.IsTrue(permission.IsSucceed);

                var perms = GoogleDriveUtility.GetResourcePermissions(GetConnection(), uploadResult.Data.Id);
                var res   = Enumerable.Any(perms.Data, (it) => { return(it.Id == permission.Data.Id); });
                Assert.IsTrue(res);
            }
            finally
            {
                GoogleDriveUtility.DeleteResource(GetConnection(), uploadResult.Data.Id);
            }
        }
Пример #13
0
        public void DoesResourceExistTest()
        {
            var ShoulBeUnavailable = GoogleDriveUtility.DoesResourceExist(GetConnection(), "incorrect Id");

            Assert.AreEqual(GoogleDriveResourceType.Unavailable, ShoulBeUnavailable.Data);

            var ShoulBeFolder = GoogleDriveUtility.DoesResourceExist(GetConnection(), testFolder.Id);

            Assert.AreEqual(GoogleDriveResourceType.Folder, ShoulBeFolder.Data);

            var uploadResult = GoogleDriveUtility.UploadFile(GetConnection(), TestFileFullName, null, testFolder.Id);

            try
            {
                var ShoulBeFile = GoogleDriveUtility.DoesResourceExist(GetConnection(), uploadResult.Data.Id);
                Assert.AreEqual(GoogleDriveResourceType.File, ShoulBeFile.Data);
            }
            finally
            {
                GoogleDriveUtility.DeleteResource(GetConnection(), uploadResult.Data.Id);
            }
        }
Пример #14
0
        public void DownloadFileTest()
        {
            var    uploadResult  = GoogleDriveUtility.UploadFile(GetConnection(), TestFileFullName, null, testFolder.Id);
            string localFileName = TestFileFullName + "_";

            try
            {
                var downloadResult = GoogleDriveUtility.DownloadFile(GetConnection(), uploadResult.Data.Id, localFileName);
                Assert.IsTrue(downloadResult.IsSucceed);
                Assert.IsTrue(File.Exists(localFileName));

                var origLen   = new System.IO.FileInfo(TestFileFullName).Length;
                var actualLen = new System.IO.FileInfo(localFileName).Length;

                Assert.AreEqual(origLen, actualLen);
            }
            finally
            {
                GoogleDriveUtility.DeleteResource(GetConnection(), uploadResult.Data.Id);
                System.IO.File.Delete(localFileName);
            }
        }
Пример #15
0
        public void GetLongFileListTest()
        {
            const int FILE_COUNT = 110;
            List <GoogleDriveFile> uploadedFiles = new List <GoogleDriveFile>(FILE_COUNT);

            try
            {
                var rootFileList = GoogleDriveUtility.GetFiles(GetConnection(), null);
                Assert.IsTrue(rootFileList.IsSucceed);

                for (int i = 0; i < FILE_COUNT; i++)
                {
                    uploadedFiles.Add(GoogleDriveUtility.UploadFile(GetConnection(), TestFileFullName, null, testFolder.Id).Data);
                }

                var testFolderFileList = GoogleDriveUtility.GetFiles(GetConnection(), testFolder.Id);
                Assert.IsTrue(testFolderFileList.IsSucceed);
                Assert.AreEqual(FILE_COUNT, testFolderFileList.Data.Length);
            }
            finally
            {
                uploadedFiles.ForEach(file => GoogleDriveUtility.DeleteResource(GetConnection(), file.Id));
            }
        }
Пример #16
0
        public void GetFileListTest()
        {
            var rootFileList = GoogleDriveUtility.GetFiles(GetConnection(), null);

            Assert.IsTrue(rootFileList.IsSucceed);
        }
Пример #17
0
 public void CleanupTests()
 {
     File.Delete(TestFileFullName);
     GoogleDriveUtility.DeleteResource(GetConnection(), testFolder.Id);
 }
Пример #18
0
        public void ListFilesInIncorrectFolderTest()
        {
            var testFolderFileList = GoogleDriveUtility.GetFiles(GetConnection(), "incorrect Id");

            Assert.IsFalse(testFolderFileList.IsSucceed);
        }
 public void InitTests()
 {
     testFolder = GoogleDriveUtility.CreateFolder(GetConnection(), TestData.TestFolderName, null).Data;
 }
 public void CleanupTests()
 {
     GoogleDriveUtility.DeleteResource(GetConnection(), testFolder.Id);
 }