Exemple #1
0
            public void NullEncoding_ExceptionThrown()
            {
                var contents = Enumerable.Repeat("This is a test line.", 150).ToList();
                var path     = Path.Combine(appendAllLinesTestFolder, nameof(NullEncoding_ExceptionThrown));

                Directory.CreateDirectory(appendAllLinesTestFolder);

                Assert.ThrowsAsync <ArgumentNullException>(async() => await AsyncFile.AppendAllLinesAsync(path, contents, null));
            }
Exemple #2
0
            public async Task LinesAppendedWithEncoding(Encoding encoding)
            {
                var contents = Enumerable.Repeat("This is a test line.", 150).ToList();
                var path     = Path.Combine(appendAllLinesTestFolder, nameof(LinesAppendedWithEncoding));

                Directory.CreateDirectory(appendAllLinesTestFolder);
                File.WriteAllLines(path, contents, encoding);

                await AsyncFile.AppendAllLinesAsync(path, contents, encoding);

                contents.AddRange(Enumerable.Repeat("This is a test line.", 150));

                var result = File.ReadAllLines(path, encoding);

                CollectionAssert.AreEqual(contents, result);
            }
Exemple #3
0
            public void CancellationToken_LinesAppended()
            {
                var contents = Enumerable.Repeat("This is a test line.", 150).ToList();
                var path     = Path.Combine(appendAllLinesTestFolder, nameof(CancellationToken_LinesAppended));

                Directory.CreateDirectory(appendAllLinesTestFolder);
                File.WriteAllLines(path, contents);

                contents.AddRange(Enumerable.Repeat("This is a test line.", 150000));

                var cancellationTokenSource = new CancellationTokenSource();

                Assert.ThrowsAsync <TaskCanceledException>(
                    async() =>
                {
                    var task = AsyncFile.AppendAllLinesAsync(path, contents, cancellationTokenSource.Token);
                    cancellationTokenSource.Cancel();
                    await task;
                });

                var result = File.ReadAllLines(path);

                Assert.IsTrue(contents.Count > result.Length);
            }