Skip to content

Commit

Permalink
transform use of await to use Tasks and waits (#439)
Browse files Browse the repository at this point in the history
* refactor awaits in async unittests to use invoke pattern
  • Loading branch information
j0shuams authored Sep 25, 2020
1 parent e57b67c commit a7748a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
9 changes: 7 additions & 2 deletions UnitTest/TestComponentCSharp_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public TestCSharp()
TestObject = new Class();
}

[Fact]
public async Task TestWriteBuffer()
async Task InvokeWriteBufferAsync()
{
var random = new Random(42);
byte[] data = new byte[256];
Expand All @@ -46,6 +45,12 @@ public async Task TestWriteBuffer()
await stream.WriteAsync(buffer);
}

[Fact]
public void TestWriteBuffer()
{
Assert.True(InvokeWriteBufferAsync().Wait(1000));
}

[Fact]
public void TestUri()
{
Expand Down
18 changes: 13 additions & 5 deletions UnitTest/TestComponentCSharp_Tests.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public TestCSharpNet5()
TestObject = new Class();
}


[Fact]
public void TestAsStream()
{
Expand All @@ -28,9 +27,7 @@ public void TestAsStream()
normalStream.CopyTo(memoryStream);
}


[Fact]
static async void TestReadToEndAsync()
async Task InvokeReadToEndAsync()
{
StorageFolder localFolder = await StorageFolder.GetFolderFromPathAsync(System.IO.Path.GetTempPath());
StorageFile file = await localFolder.CreateFileAsync("temp.txt", CreationCollisionOption.ReplaceExisting);
Expand All @@ -42,7 +39,12 @@ static async void TestReadToEndAsync()
}

[Fact]
public async Task TestStreamWriteAndRead()
public void TestReadToEndAsync()
{
Assert.True(InvokeReadToEndAsync().Wait(1000));
}

async Task InvokeStreamWriteAndReadAsync()
{
var random = new Random(42);
byte[] data = new byte[256];
Expand All @@ -56,5 +58,11 @@ public async Task TestStreamWriteAndRead()
await stream.ReadAsync(read, 0, read.Length);
Assert.Equal(read, data);
}

[Fact]
public void TestStreamWriteAndRead()
{
Assert.True(InvokeStreamWriteAndReadAsync().Wait(1000));
}
}
}

0 comments on commit a7748a9

Please sign in to comment.