Beispiel #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);
            }
        }