/// <summary> /// Finds the file in a filesystem snapshot. The location of the file is ignored, so not 100% but good enough. /// </summary> public CloudItem Find(FilesystemSnapshot filesystem) { var file = TryFind(filesystem); if (file == null) throw new ArgumentException("File was not found in cloud filesystem: " + Name); return file; }
/// <summary> /// Uploads and downloads random bytes of the specified length and verifies content integrity. /// Useful to ensure that we do not freak out with some special size due to math errors. /// </summary> private async Task TestFileUploadAndDownload(int size, FilesystemSnapshot filesystem, IFeedbackChannel feedback) { var data = TestHelper.GetRandomBytes(size); // Just stick it in the root, do not care about what already exists there. CloudItem file; using (var stream = new MemoryStream(data)) file = await filesystem.Files.NewFileAsync(size.ToString(), stream, feedback); var target = Path.GetTempFileName(); try { await file.DownloadContentsAsync(target, feedback); using (var contents = File.OpenRead(target)) using (var expectedContents = new MemoryStream(data)) TestHelper.AssertStreamsAreEqual(expectedContents, contents); } finally { File.Delete(target); } }
/// <summary> /// Attempts to find the file in a filesystem snapshot. The location of the file is ignored, so not 100% but good enough. /// </summary> public CloudItem TryFind(FilesystemSnapshot filesystem) { return filesystem.AllItems .FirstOrDefault(ci => ci.Type == ItemType.File && ci.Name == Name && ci.Size.GetValueOrDefault() == Size); }