예제 #1
0
            public async Task WriteAllLinesAsync_NullEncoding_ExceptionThrown()
            {
                var contents = Enumerable.Repeat("This is a test line.", 150).ToList();
                var path     = Path.Combine(writeAllLinesTestFolder, nameof(NullContent_ExceptionThrown));

                Directory.CreateDirectory(writeAllLinesTestFolder);

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

                Directory.CreateDirectory(writeAllLinesTestFolder);

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

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

                CollectionAssert.AreEqual(contents, result);
            }
예제 #3
0
            public async Task Default_LinesAppended()
            {
                var contents = Enumerable.Repeat("This is a test line.", 150).ToList();
                var path     = Path.Combine(writeAllLinesTestFolder, nameof(Default_LinesAppended));

                Directory.CreateDirectory(writeAllLinesTestFolder);

                await AsyncFile.WriteAllLinesAsync(path, contents);

                var result = File.ReadAllLines(path);

                CollectionAssert.AreEqual(contents, result);
            }
예제 #4
0
            public void CancellationToken_LinesAppendedAndExceptionThrown()
            {
                var contents = Enumerable.Repeat("This is a test line.", 30000).ToList();
                var path     = Path.Combine(writeAllLinesTestFolder, nameof(CancellationToken_LinesAppendedAndExceptionThrown));

                Directory.CreateDirectory(writeAllLinesTestFolder);

                var tokenSource = new CancellationTokenSource();

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

                var result = File.ReadAllLines(path);

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