Skip to content

Commit

Permalink
Merge pull request #10 from FrendsPlatform/Convert_to_netstandard
Browse files Browse the repository at this point in the history
Converted Task to multitarget framework 461 and netstandard 2.0
  • Loading branch information
jvuoti authored Mar 12, 2019
2 parents fce99c6 + fbc57c8 commit 06785c0
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 460 deletions.
112 changes: 56 additions & 56 deletions Frends.File.Tests/CopyTest.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using NUnit.Framework;

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using Xunit;

namespace Frends.File.Tests
{
[TestFixture]
public class CopyTest : FileTestBase
{
[Test]
[Fact]
public async Task ShouldCopySingleFile()
{
TestFileContext.CreateFile("dir/sub/test.txt", "testing");
Expand All @@ -27,20 +27,20 @@ public async Task ShouldCopySingleFile()
new CopyOptions { CreateTargetDirectories = true },
CancellationToken.None);

Assert.That(results.Count, Is.EqualTo(1));
Assert.Single(results);
var result = results[0];
Assert.That(result.Path, Is.EqualTo(TestFileContext.GetAbsolutePath("out/test.txt")));
Assert.That(result.SourcePath, Is.EqualTo(TestFileContext.GetAbsolutePath("dir/sub/test.txt")));
Assert.Equal(TestFileContext.GetAbsolutePath("out/test.txt"), result.Path);
Assert.Equal(TestFileContext.GetAbsolutePath("dir/sub/test.txt"), result.SourcePath);

Assert.That(TestFileContext.FileExists("out/test.txt"), "Output file should have been written");
Assert.True(TestFileContext.FileExists("out/test.txt"), "Output file should have been written");
}

[Test]
public void ShouldThrowErrorIfTargetDirectoryDoesNotExist()
[Fact]
public async Task ShouldThrowErrorIfTargetDirectoryDoesNotExist()
{
TestFileContext.CreateFile("dir/sub/test.txt", "testing");

var error = Assert.ThrowsAsync<DirectoryNotFoundException>(async () => await File.Copy(
var error = await Assert.ThrowsAsync<DirectoryNotFoundException>(async () => await File.Copy(
new CopyInput
{
Directory = TestFileContext.GetAbsolutePath("dir/sub"),
Expand All @@ -50,10 +50,10 @@ public void ShouldThrowErrorIfTargetDirectoryDoesNotExist()
new CopyOptions { CreateTargetDirectories = false },
CancellationToken.None));

Assert.That(error.Message, Does.Contain(TestFileContext.GetAbsolutePath("out")));
Assert.Contains(TestFileContext.GetAbsolutePath("out"), error.Message);
}

[Test]
[Fact]
public async Task ShouldNotCopyFilesIfNoMatch()
{
TestFileContext.CreateFile("dir/sub/test.txt", "testing");
Expand All @@ -68,10 +68,10 @@ public async Task ShouldNotCopyFilesIfNoMatch()
new CopyOptions { CreateTargetDirectories = true },
CancellationToken.None);

Assert.That(results.Count, Is.EqualTo(0));
Assert.Empty(results);
}

[Test]
[Fact]
public async Task ShouldCopyFilesFromSubDirectories()
{
TestFileContext.CreateFile("dir/sub/test1.txt", "testing");
Expand All @@ -90,15 +90,15 @@ public async Task ShouldCopyFilesFromSubDirectories()
new CopyOptions { CreateTargetDirectories = true },
CancellationToken.None);

Assert.That(results.Count, Is.EqualTo(3));
Assert.That(results.Select(r => Path.GetFileName(r.Path)), Is.EquivalentTo(new[] { "test1.txt", "test2.txt", "test3.txt" }));
Assert.Equal(3, results.Count);
Assert.Equal(results.Select(r => Path.GetFileName(r.Path)), new[] { "test1.txt", "test2.txt", "test3.txt" });

Assert.That(TestFileContext.FileExists("out/test1.txt"), "Output file should have been written");
Assert.That(TestFileContext.FileExists("out/test2.txt"), "Output file should have been written");
Assert.That(TestFileContext.FileExists("out/test3.txt"), "Output file should have been written");
Assert.True(TestFileContext.FileExists("out/test1.txt"), "Output file should have been written");
Assert.True(TestFileContext.FileExists("out/test2.txt"), "Output file should have been written");
Assert.True(TestFileContext.FileExists("out/test3.txt"), "Output file should have been written");
}

[Test]
[Fact]
public async Task ShouldCopyFilesFromSubDirectoriesPreservingDirectoryStructure()
{
TestFileContext.CreateFile("dir/test1.txt", "testing");
Expand All @@ -119,19 +119,19 @@ public async Task ShouldCopyFilesFromSubDirectoriesPreservingDirectoryStructure(
},
CancellationToken.None);

Assert.That(results.Count, Is.EqualTo(3));
Assert.That(results.Select(r => r.Path), Is.EquivalentTo(new[] {
Assert.Equal(3, results.Count);
Assert.Equal(results.Select(r => r.Path), new[] {
TestFileContext.GetAbsolutePath("out/test1.txt"),
TestFileContext.GetAbsolutePath("out/sub/test2.txt"),
TestFileContext.GetAbsolutePath("out/sub/nestedSub/test3.txt")
}));
});

Assert.That(TestFileContext.FileExists("out/test1.txt"), "Output file should have been written");
Assert.That(TestFileContext.FileExists("out/sub/test2.txt"), "Output file should have been written");
Assert.That(TestFileContext.FileExists("out/sub/nestedSub/test3.txt"), "Output file should have been written");
Assert.True(TestFileContext.FileExists("out/test1.txt"), "Output file should have been written");
Assert.True(TestFileContext.FileExists("out/sub/test2.txt"), "Output file should have been written");
Assert.True(TestFileContext.FileExists("out/sub/nestedSub/test3.txt"), "Output file should have been written");
}

[Test]
[Fact]
public async Task ShouldOverwriteExistingFiles()
{
var expectedFileContents = "testing " + DateTime.UtcNow.ToString("o");
Expand All @@ -154,20 +154,20 @@ public async Task ShouldOverwriteExistingFiles()
},
CancellationToken.None);

Assert.That(results.Count, Is.EqualTo(2));
Assert.That(results.Select(r => r.Path), Is.EquivalentTo(new[] {
Assert.Equal(2, results.Count);
Assert.Equal(results.Select(r => r.Path), new[] {
TestFileContext.GetAbsolutePath("target/test1.txt"),
TestFileContext.GetAbsolutePath("target/test2.txt")
}));
});

Assert.That(TestFileContext.FileExists("target/test1.txt"), "Output file should have been written");
Assert.That(TestFileContext.FileExists("target/test2.txt"), "Output file should have been written");
Assert.True(TestFileContext.FileExists("target/test1.txt"), "Output file should have been written");
Assert.True(TestFileContext.FileExists("target/test2.txt"), "Output file should have been written");

var resultFileContents = System.IO.File.ReadAllText(TestFileContext.GetAbsolutePath("target/test2.txt"));
Assert.That(resultFileContents, Is.EqualTo(expectedFileContents));
Assert.Equal(expectedFileContents, resultFileContents);
}

[Test]
[Fact]
public async Task ShouldOverwriteExistingFilesInSubDirectories()
{
var expectedFileContents = "testing " + DateTime.UtcNow.ToString("o");
Expand All @@ -191,19 +191,19 @@ public async Task ShouldOverwriteExistingFilesInSubDirectories()
},
CancellationToken.None);

Assert.That(results.Count, Is.EqualTo(2));
Assert.That(results.Select(r => r.Path), Is.EquivalentTo(new[] {
Assert.Equal(2, results.Count);
Assert.Equal(results.Select(r => r.Path), new[] {
TestFileContext.GetAbsolutePath("target/test.txt"),
TestFileContext.GetAbsolutePath("target/sub/test.txt")
}));
});

Assert.That(TestFileContext.FileExists("target/sub/test.txt"), "Output file should have been written");
Assert.True(TestFileContext.FileExists("target/sub/test.txt"), "Output file should have been written");

var resultFileContents = System.IO.File.ReadAllText(TestFileContext.GetAbsolutePath("target/sub/test.txt"));
Assert.That(resultFileContents, Is.EqualTo(expectedFileContents));
Assert.Equal(expectedFileContents, resultFileContents);
}

[Test]
[Fact]
public async Task ShouldRenameFilesIfTargetFilesExist()
{
TestFileContext.CreateFile("source/test.txt", "testing");
Expand All @@ -227,19 +227,19 @@ public async Task ShouldRenameFilesIfTargetFilesExist()
},
CancellationToken.None);

Assert.That(results.Count, Is.EqualTo(3));
Assert.That(results.Select(r => r.Path), Is.EquivalentTo(new[] {
Assert.Equal(3, results.Count);
Assert.Equal(results.Select(r => r.Path), new[] {
TestFileContext.GetAbsolutePath("target/test(2).txt"),
TestFileContext.GetAbsolutePath("target/test(3).txt"),
TestFileContext.GetAbsolutePath("target/test(4).txt")
}));
});

Assert.That(TestFileContext.FileExists("target/test(2).txt"), "Output file should have been written");
Assert.That(TestFileContext.FileExists("target/test(3).txt"), "Output file should have been written");
Assert.That(TestFileContext.FileExists("target/test(4).txt"), "Output file should have been written");
Assert.True(TestFileContext.FileExists("target/test(2).txt"), "Output file should have been written");
Assert.True(TestFileContext.FileExists("target/test(3).txt"), "Output file should have been written");
Assert.True(TestFileContext.FileExists("target/test(4).txt"), "Output file should have been written");
}

[Test]
[Fact]
public async Task ShouldRenameFilesAndPreserveDirectoryStructureIfTargetFilesExist()
{
TestFileContext.CreateFile("source/test.txt", "testing");
Expand All @@ -261,23 +261,23 @@ public async Task ShouldRenameFilesAndPreserveDirectoryStructureIfTargetFilesExi
},
CancellationToken.None);

Assert.That(results.Count, Is.EqualTo(2));
Assert.That(results.Select(r => r.Path), Is.EquivalentTo(new[] {
Assert.Equal(2, results.Count);
Assert.Equal(results.Select(r => r.Path), new[] {
TestFileContext.GetAbsolutePath("target/test.txt"),
TestFileContext.GetAbsolutePath("target/sub/test(1).txt")
}));
});

Assert.That(TestFileContext.FileExists("target/sub/test(1).txt"), "Output file should have been written");
Assert.True(TestFileContext.FileExists("target/sub/test(1).txt"), "Output file should have been written");
}

[Test]
public void ShouldThrowAndRollbackIfTargetFilesExist()
[Fact]
public async Task ShouldThrowAndRollbackIfTargetFilesExist()
{
TestFileContext.CreateFile("source/test.txt", "testing");
TestFileContext.CreateFile("source/sub/test.txt", "testing");
TestFileContext.CreateFile("target/sub/test.txt", "existing");

Assert.ThrowsAsync<IOException>(async () => await File.Copy(
await Assert.ThrowsAsync<IOException>(async () => await File.Copy(
new CopyInput
{
Directory = TestFileContext.GetAbsolutePath("source"),
Expand All @@ -292,8 +292,8 @@ public void ShouldThrowAndRollbackIfTargetFilesExist()
},
CancellationToken.None));

Assert.That(!TestFileContext.FileExists("target/test.txt"), "Output file should have been rolled back");
Assert.That(!TestFileContext.FileExists("target/test(2).txt"), "Output file should have been rolled back");
Assert.False(TestFileContext.FileExists("target/test.txt"), "Output file should have been rolled back");
Assert.False(TestFileContext.FileExists("target/test(2).txt"), "Output file should have been rolled back");
}
}
}
Expand Down
12 changes: 3 additions & 9 deletions Frends.File.Tests/FileTestBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using NUnit.Framework;

using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -11,22 +11,16 @@ public abstract class FileTestBase : IDisposable
{
protected DisposableFileSystem TestFileContext;

[SetUp]
public void Setup()
protected FileTestBase()
{
TestFileContext = new DisposableFileSystem();
}

[TearDown]
public void ClearContext()
{
TestFileContext?.Dispose();
TestFileContext = null;
}

public void Dispose()
{
TestFileContext?.Dispose();
TestFileContext = null;
}
}
}
Loading

0 comments on commit 06785c0

Please sign in to comment.