Ejemplo n.º 1
0
        public async Task When_AppendTextAsyncIgnoresEncoding()
        {
            StorageFile targetFile = null;

            try
            {
                var originalContent = "First line3527535205šěššýétžščžíé";
                var appendedContent = "New line33251164535205věšřěšřčžčšžž";

                var fileName = GenerateRandomFileName();
                var filePath = Path.Combine(ApplicationData.Current.LocalFolder.Path, fileName);
                File.WriteAllText(filePath, originalContent, Encoding.Unicode);
                targetFile = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName);

                await PathIO.AppendTextAsync(targetFile.Path, appendedContent);

                var realContents    = File.ReadAllBytes(targetFile.Path).Skip(2).ToArray();              // Skip BOM at start
                var expectedContent = Encoding.Unicode.GetBytes(originalContent).Concat(Encoding.Default.GetBytes(appendedContent)).ToArray();
                CollectionAssert.AreEqual(expectedContent, realContents);
            }
            finally
            {
                DeleteFile(targetFile);
            }
        }
Ejemplo n.º 2
0
        public async Task When_AppendTextAsyncWithEncoding()
        {
            StorageFile targetFile = null;

            try
            {
                var originalContent = "First line3527535205šěššýétžščžíé";
                var appendedContent = "New line33251164535205věšřěšřčžčšžž";

                var fileName = GenerateRandomFileName();
                var filePath = Path.Combine(ApplicationData.Current.LocalFolder.Path, fileName);
                File.WriteAllText(filePath, originalContent, Encoding.BigEndianUnicode);
                targetFile = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName);

                await PathIO.AppendTextAsync(targetFile.Path, appendedContent, Windows.Storage.Streams.UnicodeEncoding.Utf16BE);

                var realContents = File.ReadAllText(targetFile.Path, Encoding.BigEndianUnicode);
                Assert.AreEqual(originalContent + appendedContent, realContents);
            }
            finally
            {
                DeleteFile(targetFile);
            }
        }