Ejemplo n.º 1
0
        public async Task Should_not_blow_up_if_file_does_not_exist()
        {
            string fileName = $"{Guid.NewGuid()}.txt";
            var    sut      = new BlobStorageFile(ResourceHelpers.GetLocalDevelopmentContainer(), fileName);

            sut.Exists.Should().BeFalse();

            await sut.DeleteAsync();
        }
        public async Task Should_create_file_when_stream_opened()
        {
            var sut = new BlobStorageFile(ResourceHelpers.GetLocalDevelopmentContainer(), $"{Guid.NewGuid()}.txt");

            sut.Exists.Should().BeFalse();

            using (await sut.OpenWriteAsync()) {}

            sut.Exists.Should().BeTrue();
            await sut.DeleteAsync();
        }
        public async Task Should_return_contents_of_file()
        {
            string fileName = $"{Guid.NewGuid()}.txt";
            await ResourceHelpers.CreateFileWithContentAsync(ResourceHelpers.GetLocalDevelopmentContainer(), fileName, FileContent);

            var sut = new BlobStorageFile(ResourceHelpers.GetLocalDevelopmentContainer(), fileName);

            var bytes = await sut.ReadToEndAsync();

            string contents = Encoding.UTF8.GetString(bytes);

            contents.Should().Be(FileContent);
            await sut.DeleteAsync();
        }
Ejemplo n.º 4
0
        public async Task Should_delete_file_properly()
        {
            string fileName = $"{Guid.NewGuid()}.txt";

            await ResourceHelpers.CreateFileWithContentAsync(ResourceHelpers.GetLocalDevelopmentContainer(), fileName, "test");

            var sut = new BlobStorageFile(ResourceHelpers.GetLocalDevelopmentContainer(), fileName);

            sut.Exists.Should().BeTrue();

            await sut.DeleteAsync();

            sut.Exists.Should().BeFalse();
        }
Ejemplo n.º 5
0
        public async Task Should_give_md5_hash_of_file()
        {
            string fileName = $"{Guid.NewGuid()}.txt";

            await ResourceHelpers.CreateFileWithContentAsync(ResourceHelpers.GetLocalDevelopmentContainer(), fileName, FileContent);

            var sut = new BlobStorageFile(ResourceHelpers.GetLocalDevelopmentContainer(), fileName);

            var hash = await sut.GetHashAsync();

            hash.Should().NotBeEmpty();
            hash.Should().Be("081cb72eaaacae3df4502708ff956d23");

            await sut.DeleteAsync();
        }
Ejemplo n.º 6
0
        public async Task Should_give_stream()
        {
            string fileName = $"{Guid.NewGuid()}.txt";
            await ResourceHelpers.CreateFileWithContentAsync(ResourceHelpers.GetLocalDevelopmentContainer(), fileName, FileContent);

            var sut = new BlobStorageFile(ResourceHelpers.GetLocalDevelopmentContainer(), fileName);

            using (var stream = await sut.OpenReadAsync())
            {
                stream.Should().NotBe(null);
                stream.Position.Should().Be(0);
            }

            await sut.DeleteAsync();
        }
        public async Task Should_write_content_to_file_in_deep_structure()
        {
            var sut = new BlobStorageFile(ResourceHelpers.GetLocalDevelopmentContainer(), $"folder1/folder2/folder3/{Guid.NewGuid()}.txt");

            using (var stream = await sut.OpenWriteAsync())
                using (var writer = new StreamWriter(stream))
                {
                    writer.Write(WRITE_CONTENT);
                }

            string fileContents = await sut.RealPath.MakeHttpRequestAsync();

            fileContents.Should().Be(WRITE_CONTENT);

            await sut.DeleteAsync();
        }
Ejemplo n.º 8
0
        public async Task Should_be_able_to_read_file_contents_from_stream()
        {
            string fileName = $"{Guid.NewGuid()}.txt";
            await ResourceHelpers.CreateFileWithContentAsync(ResourceHelpers.GetLocalDevelopmentContainer(), fileName, FileContent);

            var sut = new BlobStorageFile(ResourceHelpers.GetLocalDevelopmentContainer(), fileName);

            using (var stream = await sut.OpenReadAsync())
                using (var reader = new StreamReader(stream))
                {
                    string content = await reader.ReadToEndAsync();

                    content.Should().NotBeEmpty();
                    content.Should().StartWith(FileContent);
                }

            await sut.DeleteAsync();
        }