コード例 #1
0
ファイル: TestEnvironment.cs プロジェクト: fiftin/oblqo
        /// <summary>
        /// Creates environmant with next drive FS structure:
        //  c:
        //      documents
        //          resume.txt
        //          my-photos.jpg
        //      photos
        //          photos2015
        //              lenovo
        //              turkey
        //              PHOTO1.jpg
        //              PHOTO2.jpg
        //              PHOTO3.jpg
        //              info.txt
        //
        //  Root directory: c:/photos.
        /// </summary>
        public static async Task<TestEnvironment> CreateSimpleAsync()
        {
            byte[] info_txt = Encoding.ASCII.GetBytes("Hello, World!");
            byte[] photo1_jpg = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            var storage = new MockStorage("mock-1");
            storage.AddFile(new MockStorageFile(storage, "PHOTO1.jpg") { content = photo1_jpg });
            storage.AddFile(new MockStorageFile(storage, "info.txt") { content = info_txt });

            var account = new Account(storage);
            var drive = new MockDrive(account);
            var root = new MockDriveFile(drive, "c:", isFolder: true);

            var docs = root.Add(new MockDriveFile(drive, "documents", isFolder: true));
            docs.Add(new MockDriveFile(drive, "resume.txt"));
            docs.Add(new MockDriveFile(drive, "my-photo.jpg"));
            var photos = root.Add(new MockDriveFile(drive, "photos", isFolder: true));
            var photos2015 = photos.Add(new MockDriveFile(drive, "photos2015", isFolder: true));
            var lenovo = photos.Add(new MockDriveFile(drive, "lenovo", isFolder: true));
            var turkey = photos.Add(new MockDriveFile(drive, "turkey", isFolder: true));
            await photos2015.Add(new MockDriveFile(drive, "PHOTO1.jpg", isImage: true) { content = photo1_jpg }).SetStorageFileIdAsync("photo1-jpg", CancellationToken.None);
            var image2 = new MockDriveFile(drive, "PHOTO2.jpg", isImage: true);
            image2.content = new byte[] {
                1, 1, 1, 1, 1,
                0, 0, 0, 0, 0,
                1, 1, 1, 1, 1
            };
            photos2015.Add(image2); // unsync
            photos2015.Add(new MockDriveFile(drive, "PHOTO3.jpg", isImage: true)); // unsync
            await photos2015.Add(new MockDriveFile(drive, "info.txt") { content = info_txt }).SetStorageFileIdAsync("info-txt", CancellationToken.None);
            drive.root = root;
            drive.rootFolder = photos;
            return new TestEnvironment(storage, drive);
        }
コード例 #2
0
        internal DriveFile CreateFolder(string folderName)
        {
            var ret = new MockDriveFile(Drive, folderName, isFolder: true);

            files.Add(ret);
            return(ret);
        }
コード例 #3
0
ファイル: MockDrive.cs プロジェクト: fiftin/oblqo
 public override async Task<DriveFile> GetFileAsync(System.Xml.Linq.XElement xml, CancellationToken token)
 {
     var file = new MockDriveFile(this,
         xml.Attribute("name").Value,
         bool.Parse(xml.Attribute("isFolder").Value),
         bool.Parse(xml.Attribute("isImage").Value),
         bool.Parse(xml.Attribute("isRoot").Value));
     return file;
 }
コード例 #4
0
ファイル: MockDrive.cs プロジェクト: fiftin/oblqo
        public override async Task <DriveFile> GetFileAsync(System.Xml.Linq.XElement xml, CancellationToken token)
        {
            var file = new MockDriveFile(this,
                                         xml.Attribute("name").Value,
                                         bool.Parse(xml.Attribute("isFolder").Value),
                                         bool.Parse(xml.Attribute("isImage").Value),
                                         bool.Parse(xml.Attribute("isRoot").Value));

            return(file);
        }
コード例 #5
0
ファイル: MockDrive.cs プロジェクト: fiftin/oblqo
        public override async Task <DriveFile> UploadFileAsync(Stream fileStream, string fileName, DriveFile destFolder, string storageFileId, CancellationToken token)
        {
            var file = new MockDriveFile(this, fileName, false);

            file.content = new byte[fileStream.Length];
            fileStream.Read(file.content, 0, (int)fileStream.Length);
            MockDriveFile folder = (MockDriveFile)destFolder;

            folder.Add(file);
            return(file);
        }
コード例 #6
0
ファイル: TestEnvironment.cs プロジェクト: fiftin/oblqo
 public static async Task<TestEnvironment> CreateTwoDrivesSimpleAsync()
 {
     var env = await CreateSimpleAsync();
     var drive2 = new MockDrive(env.Account);
     var root = new MockDriveFile(drive2, "/", isFolder: true);
     var home = new MockDriveFile(drive2, "home", isFolder: true);
     root.Add(home);
     var fiftin = new MockDriveFile(drive2, "fiftin", isFolder: true);
     home.Add(fiftin);
     var photos = new MockDriveFile(drive2, "photos", isFolder: true);
     fiftin.Add(photos);
     drive2.root = root;
     drive2.rootFolder = photos;
     env.Account.Drives.Add(drive2);
     return new TestEnvironment((MockStorage)env.Account.Storage, env.Account.Drives.Cast<MockDrive>());
 }
コード例 #7
0
ファイル: TestEnvironment.cs プロジェクト: fiftin/oblqo
        /// <summary>
        /// Creates environmant with next drive FS structure:
        //  c:
        //      documents
        //          resume.txt
        //          my-photos.jpg
        //      photos
        //          photos2015
        //              lenovo
        //              turkey
        //              PHOTO1.jpg
        //              PHOTO2.jpg
        //              PHOTO3.jpg
        //              info.txt
        //
        //  Root directory: c:/photos.
        /// </summary>
        public static async Task <TestEnvironment> CreateSimpleAsync()
        {
            byte[] info_txt   = Encoding.ASCII.GetBytes("Hello, World!");
            byte[] photo1_jpg = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            var    storage    = new MockStorage("mock-1");

            storage.AddFile(new MockStorageFile(storage, "PHOTO1.jpg")
            {
                content = photo1_jpg
            });
            storage.AddFile(new MockStorageFile(storage, "info.txt")
            {
                content = info_txt
            });

            var account = new Account(storage);
            var drive   = new MockDrive(account);
            var root    = new MockDriveFile(drive, "c:", isFolder: true);

            var docs = root.Add(new MockDriveFile(drive, "documents", isFolder: true));

            docs.Add(new MockDriveFile(drive, "resume.txt"));
            docs.Add(new MockDriveFile(drive, "my-photo.jpg"));
            var photos     = root.Add(new MockDriveFile(drive, "photos", isFolder: true));
            var photos2015 = photos.Add(new MockDriveFile(drive, "photos2015", isFolder: true));
            var lenovo     = photos.Add(new MockDriveFile(drive, "lenovo", isFolder: true));
            var turkey     = photos.Add(new MockDriveFile(drive, "turkey", isFolder: true));
            await photos2015.Add(new MockDriveFile(drive, "PHOTO1.jpg", isImage : true) { content = photo1_jpg }).SetStorageFileIdAsync("photo1-jpg", CancellationToken.None);

            var image2 = new MockDriveFile(drive, "PHOTO2.jpg", isImage: true);

            image2.content = new byte[] {
                1, 1, 1, 1, 1,
                0, 0, 0, 0, 0,
                1, 1, 1, 1, 1
            };
            photos2015.Add(image2);                                                // unsync
            photos2015.Add(new MockDriveFile(drive, "PHOTO3.jpg", isImage: true)); // unsync
            await photos2015.Add(new MockDriveFile(drive, "info.txt") { content = info_txt }).SetStorageFileIdAsync("info-txt", CancellationToken.None);

            drive.root       = root;
            drive.rootFolder = photos;
            return(new TestEnvironment(storage, drive));
        }
コード例 #8
0
ファイル: TestEnvironment.cs プロジェクト: fiftin/oblqo
        public static async Task <TestEnvironment> CreateTwoDrivesSimpleAsync()
        {
            var env = await CreateSimpleAsync();

            var drive2 = new MockDrive(env.Account);
            var root   = new MockDriveFile(drive2, "/", isFolder: true);
            var home   = new MockDriveFile(drive2, "home", isFolder: true);

            root.Add(home);
            var fiftin = new MockDriveFile(drive2, "fiftin", isFolder: true);

            home.Add(fiftin);
            var photos = new MockDriveFile(drive2, "photos", isFolder: true);

            fiftin.Add(photos);
            drive2.root       = root;
            drive2.rootFolder = photos;
            env.Account.Drives.Add(drive2);
            return(new TestEnvironment((MockStorage)env.Account.Storage, env.Account.Drives.Cast <MockDrive>()));
        }
コード例 #9
0
 internal MockDriveFile Add(MockDriveFile file)
 {
     files.Add(file);
     return(file);
 }
コード例 #10
0
ファイル: MockDriveFile.cs プロジェクト: fiftin/oblqo
 internal MockDriveFile Add(MockDriveFile file)
 {
     files.Add(file);
     return file;
 }
コード例 #11
0
ファイル: MockDriveFile.cs プロジェクト: fiftin/oblqo
 internal DriveFile CreateFolder(string folderName)
 {
     var ret = new MockDriveFile(Drive, folderName, isFolder: true);
     files.Add(ret);
     return ret;
 }
コード例 #12
0
ファイル: MockDrive.cs プロジェクト: fiftin/oblqo
 public override async Task<DriveFile> UploadFileAsync(Stream fileStream, string fileName, DriveFile destFolder, string storageFileId, CancellationToken token)
 {
     var file = new MockDriveFile(this, fileName, false);
     file.content = new byte[fileStream.Length];
     fileStream.Read(file.content, 0, (int)fileStream.Length);
     MockDriveFile folder = (MockDriveFile)destFolder;
     folder.Add(file);
     return file;
 }