Exemple #1
0
        public async Task DesktopStorageGetExisingContainer()
        {
            // Arrange
            IStorage storage = new FileSystemStorage(this._storagePath);

            // Act
            var container = await storage.GetContainerAsync(FileSystemStorageTests._precreatedContainerName);

            // Assert
            Assert.NotNull(container);
        }
        public async Task DesktopStorageGetExisingContainer()
        {
            // Arrange
            IStorage storage = new FileSystemStorage(this._storagePath);

            // Act
            var container = await storage.GetContainerAsync(FileSystemStorageTests._precreatedContainerName);

            // Assert
            Assert.NotNull(container);
        }
Exemple #3
0
        public async Task DesktopStorageGetDirectories()
        {
            // Arrange
            IStorage          storage   = new FileSystemStorage(this._storagePath);
            IStorageContainer container = await storage.GetContainerAsync(DesktopStorageContainerTests._precreatedContainerName);

            // Act
            IEnumerable <string> dirs = await container.GetDirectoriesAsync("");

            // Assert
            Assert.NotNull(dirs);
            Assert.True(dirs.Any(d => string.Equals(d, DesktopStorageContainerTests._precreatedFolderName, StringComparison.OrdinalIgnoreCase)));
        }
Exemple #4
0
        public async Task DesktopStorageGetFilesList()
        {
            // Arrange
            IStorage          storage   = new FileSystemStorage(this._storagePath);
            IStorageContainer container = await storage.GetContainerAsync(DesktopStorageContainerTests._precreatedContainerName);

            // Act
            var files = await container.GetFilesAsync("", StorageSearchOption.AllDirectories | StorageSearchOption.StripPaths);

            var filesFull = await container.GetFilesAsync("", StorageSearchOption.AllDirectories);

            // Assert
            Assert.NotNull(files);
            Assert.NotNull(filesFull);
            Assert.True(files.Any());
            Assert.True(filesFull.Any());
        }
Exemple #5
0
        public async Task DesktopStorageGetNonExisingContainer()
        {
            // Arrange
            IStorage         storage = new FileSystemStorage(this._storagePath);
            StorageException ex      = null;

            // Act
            try {
                await storage.GetContainerAsync(FileSystemStorageTests._precreatedContainerName + "-NOT-EXISTS");
            }
            catch (StorageException e) {
                ex = e;
            }

            // Assert
            Assert.NotNull(ex);
            Assert.Equal(StorageExceptionReason.ContainerNotFound, ex.Reason);
        }
        public async Task DesktopStorageGetNonExisingContainer()
        {
            // Arrange
            IStorage storage = new FileSystemStorage(this._storagePath);
            StorageException ex = null;

            // Act
            try {
                await storage.GetContainerAsync(FileSystemStorageTests._precreatedContainerName + "-NOT-EXISTS");
            }
            catch (StorageException e) {
                ex = e;
            }

            // Assert
            Assert.NotNull(ex);
            Assert.Equal(StorageExceptionReason.ContainerNotFound, ex.Reason);
        }
Exemple #7
0
        public async Task DesktopStorageContainerCreateDirectory()
        {
            // Arrange
            string            dirName   = "CreateDirectory";
            IStorage          storage   = new FileSystemStorage(this._storagePath);
            IStorageContainer container = await storage.GetContainerAsync(DesktopStorageContainerTests._precreatedContainerName);

            // Act
            IEnumerable <string> initialDirs = await container.GetDirectoriesAsync("");

            await container.CreateDirectoryAsync(dirName);

            IEnumerable <string> finalDirs = await container.GetDirectoriesAsync("");

            // Assert
            Assert.False(initialDirs.Any(d => string.Equals(d, dirName, StringComparison.OrdinalIgnoreCase)));
            Assert.True(finalDirs.Any(d => string.Equals(d, dirName, StringComparison.OrdinalIgnoreCase)));
        }
Exemple #8
0
        public async Task DesktopStorageReadFile()
        {
            // Arrange
            IStorage          storage   = new FileSystemStorage(this._storagePath);
            IStorageContainer container = await storage.GetContainerAsync(DesktopStorageContainerTests._precreatedContainerName);

            string result;

            // Act
            using (Stream stream = await container.GetFileStreamAsync("TestFile1.txt")) {
                var buffer = new byte[stream.Length];
                await stream.ReadAsync(buffer, 0, (int)stream.Length);

                result = Encoding.UTF8.GetString(buffer);
            }

            // Assert
            Assert.NotNull(result);
            Assert.Equal("This is test file 1.", result);
        }
Exemple #9
0
        public async Task DesktopStorageWriteReadDeleteFile()
        {
            // Arrange
            IStorage          storage   = new FileSystemStorage(this._storagePath);
            IStorageContainer container = await storage.GetContainerAsync(DesktopStorageContainerTests._precreatedContainerName);

            const string text     = "This is R/W test";
            const string fileName = "rw.txt";

            var memStream = new MemoryStream();
            var writer    = new StreamWriter(memStream);

            writer.Write(text);
            writer.Flush();
            memStream.Position = 0;

            string result;

            // Act
            await container.WriteFileAsync(memStream, fileName);

            using (Stream stream = await container.GetFileStreamAsync(fileName)) {
                var buffer = new byte[stream.Length];
                await stream.ReadAsync(buffer, 0, (int)stream.Length);

                result = Encoding.UTF8.GetString(buffer);
            }

            await container.DeleteFileAsync(fileName);

            var files = await container.GetFilesAsync("", StorageSearchOption.Default);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(text, result);
            Assert.False(files.Any(d => string.Equals(d, fileName, StringComparison.OrdinalIgnoreCase)));
        }