Пример #1
0
        public async Task CreateOrAppendTextWorksWithExistingFile()
        {
            // --- Arrange
            const string BODY     = "FirstSecond";
            var          wfs      = new WindowsFileStorage(ROOT);
            var          file     = new AbstractFileDescriptor("Container", null, "TestFile.txt");
            var          fileName = WindowsFileStorage.FilePathFromAbstractFile(file);

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            using (var textFile = await wfs.CreateTextAsync(file))
            {
                textFile.Writer.Write("First");
            }

            // --- Act
            using (var textFile = await wfs.CreateOrAppendTextAsync(file))
            {
                textFile.Writer.Write("Second");
            }

            // --- Assert
            using (var savedFile = await wfs.OpenTextAsync(file))
            {
                var text = savedFile.Reader.ReadToEnd();
                text.ShouldBe(BODY);
            }
        }
Пример #2
0
        public async Task AppendTextWorksWithSpecificCulture()
        {
            // --- Arrange
            const string BODY = "1,25-1,25";
            var          wfs  = new WindowsFileStorage(ROOT);
            var          file = new AbstractFileDescriptor("Container", null, "TestFile.txt");

            using (var textFile = await wfs.CreateTextAsync(file, new CultureInfo("hu-hu")))
            {
                textFile.Writer.Write(1.25);
            }

            // --- Act
            using (var textFile = await wfs.AppendTextAsync(file, new CultureInfo("hu-hu")))
            {
                textFile.Writer.Write(-1.25);
            }

            // --- Assert
            using (var savedFile = await wfs.OpenTextAsync(file))
            {
                var text = savedFile.Reader.ReadToEnd();
                text.ShouldBe(BODY);
            }
        }
Пример #3
0
        public async Task AppendTextWorksWithUtf32()
        {
            // --- Arrange
            const string BODY = "FirstSecond";
            var          wfs  = new WindowsFileStorage(ROOT);
            var          file = new AbstractFileDescriptor("Container", null, "TestFile.txt");

            using (var textFile = await wfs.CreateTextAsync(file, encoding: Encoding.UTF32))
            {
                textFile.Writer.Write("First");
            }

            // --- Act
            using (var textFile = await wfs.AppendTextAsync(file, encoding: Encoding.UTF32))
            {
                textFile.Writer.Write("Second");
            }

            // --- Assert
            using (var savedFile = await wfs.OpenTextAsync(file))
            {
                var text = savedFile.Reader.ReadToEnd();
                text.ShouldBe(BODY);
            }
        }
Пример #4
0
        public async Task DeleteWorksWithExistingFile()
        {
            // --- Arrange
            var wfs  = new WindowsFileStorage(ROOT);
            var file = new AbstractFileDescriptor("Container", null, "TestFile.txt");

            using (var textFile = await wfs.CreateTextAsync(file))
            {
                textFile.Writer.Write("Awesome");
            }

            // --- Act
            var deleted = await wfs.DeleteAsync(file);

            // --- Assert
            deleted.ShouldBeTrue();
            (await wfs.ExistsAsync(file)).ShouldBeFalse();
        }
Пример #5
0
        public async Task CreateTextWorksAsExpected()
        {
            // --- Arrange
            const string BODY = "This is a text file";
            var          wfs  = new WindowsFileStorage(ROOT);
            var          file = new AbstractFileDescriptor("Container", null, "TestFile.txt");

            // --- Act
            using (var textFile = await wfs.CreateTextAsync(file))
            {
                textFile.Writer.Write(BODY);
            }

            // --- Assert
            using (var savedFile = await wfs.OpenTextAsync(file))
            {
                var text = savedFile.Reader.ReadToEnd();
                text.ShouldBe(BODY);
            }
        }