-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#526 Preparing unit tests for generic async method issue
- Loading branch information
1 parent
4bb81b7
commit 8a1c5ac
Showing
3 changed files
with
173 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
Tests/AssemblyTesterSets/WithoutInterceptorTests.async.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
public partial class WithoutInterceptorTests | ||
{ | ||
[Fact] | ||
public void MethodWithEmptyAsync() | ||
{ | ||
var type = testResult.Assembly.GetType("ClassWithAsyncMethod"); | ||
var instance = (dynamic)Activator.CreateInstance(type); | ||
var message = TraceRunner.Capture(() => | ||
{ | ||
var task = (Task)instance.MethodWithEmptyAsync(); | ||
task.Wait(); | ||
}); | ||
|
||
Assert.Single(message); | ||
Assert.StartsWith("ClassWithAsyncMethod.MethodWithEmptyAsync ", message.First()); | ||
} | ||
|
||
[Fact] | ||
public void ClassWithAsyncMethod() | ||
{ | ||
var type = testResult.Assembly.GetType("ClassWithAsyncMethod"); | ||
var instance = (dynamic)Activator.CreateInstance(type); | ||
var message = TraceRunner.Capture(() => | ||
{ | ||
var task = (Task)instance.MethodWithAwaitAsync(); | ||
task.Wait(); | ||
}); | ||
|
||
Assert.Single(message); | ||
Assert.StartsWith("ClassWithAsyncMethod.MethodWithAwaitAsync ", message.First()); | ||
} | ||
|
||
[Fact] | ||
public void ClassWithAsyncMethodThatThrowsException() | ||
{ | ||
var type = testResult.Assembly.GetType("ClassWithAsyncMethod"); | ||
var instance = (dynamic)Activator.CreateInstance(type); | ||
var message = TraceRunner.Capture(() => | ||
{ | ||
try | ||
{ | ||
var task = (Task)instance.MethodWithAwaitAndExceptionAsync(); | ||
task.Wait(); | ||
} | ||
catch (Exception) | ||
{ | ||
// Expected | ||
} | ||
}); | ||
|
||
Assert.Single(message); | ||
Assert.StartsWith("ClassWithAsyncMethod.MethodWithAwaitAndExceptionAsync ", message.First()); | ||
} | ||
|
||
[Fact] | ||
public void ClassWithInheritedGenericTaskAsyncMethod() | ||
{ | ||
var type = testResult.Assembly.GetType("ClassWithGenericResultAsyncMethod"); | ||
var instance = (dynamic)Activator.CreateInstance(type); | ||
var message = TraceRunner.Capture(() => | ||
{ | ||
var task = (Task)instance.DoSomethingAsync<int>(); | ||
task.Wait(); | ||
}); | ||
|
||
Assert.Single(message); | ||
Assert.StartsWith("ClassWithGenericResultAsyncMethod.DoSomethingAsync", message.First()); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true)] | ||
[InlineData(false)] | ||
public void ClassWithAsyncMethodWithFastPath(bool recurse) | ||
{ | ||
var type = testResult.Assembly.GetType("ClassWithAsyncMethod"); | ||
var instance = (dynamic)Activator.CreateInstance(type); | ||
var message = TraceRunner.Capture(() => | ||
{ | ||
var task = (Task)instance.MethodWithFastPathAsync(recurse); | ||
task.Wait(); | ||
}); | ||
|
||
Assert.Equal(recurse ? 2 : 1, message.Count); | ||
Assert.StartsWith("ClassWithAsyncMethod.MethodWithFastPathAsync ", message.First()); | ||
} | ||
|
||
[Fact] | ||
public void ClassWithExceptionAsyncMethod() | ||
{ | ||
var type = testResult.Assembly.GetType("ClassWithAsyncMethod"); | ||
var instance = (dynamic)Activator.CreateInstance(type); | ||
var message = TraceRunner.Capture(() => | ||
{ | ||
var task = (Task)instance.ComplexMethodWithAwaitAsync(-1); | ||
task.Wait(); | ||
}); | ||
|
||
Assert.Single(message); | ||
Assert.StartsWith("ClassWithAsyncMethod.ComplexMethodWithAwaitAsync ", message.First()); | ||
} | ||
|
||
[Fact] | ||
public void ClassWithFastComplexAsyncMethod() | ||
{ | ||
var type = testResult.Assembly.GetType("ClassWithAsyncMethod"); | ||
var instance = (dynamic)Activator.CreateInstance(type); | ||
var message = TraceRunner.Capture(() => | ||
{ | ||
var task = (Task)instance.ComplexMethodWithAwaitAsync(0); | ||
task.Wait(); | ||
}); | ||
|
||
Assert.Single(message); | ||
Assert.StartsWith("ClassWithAsyncMethod.ComplexMethodWithAwaitAsync ", message.First()); | ||
} | ||
|
||
[Fact] | ||
public void ClassWithMediumComplexAsyncMethod() | ||
{ | ||
var type = testResult.Assembly.GetType("ClassWithAsyncMethod"); | ||
var instance = (dynamic)Activator.CreateInstance(type); | ||
var message = TraceRunner.Capture(() => | ||
{ | ||
var task = (Task)instance.ComplexMethodWithAwaitAsync(2); | ||
task.Wait(); | ||
}); | ||
|
||
Assert.Single(message); | ||
Assert.StartsWith("ClassWithAsyncMethod.ComplexMethodWithAwaitAsync ", message.First()); | ||
} | ||
|
||
[Fact] | ||
public void ClassWithSlowComplexAsyncMethod() | ||
{ | ||
var type = testResult.Assembly.GetType("ClassWithAsyncMethod"); | ||
var instance = (dynamic)Activator.CreateInstance(type); | ||
var message = TraceRunner.Capture(() => | ||
{ | ||
var task = (Task)instance.ComplexMethodWithAwaitAsync(100); | ||
task.Wait(); | ||
}); | ||
|
||
Assert.Single(message); | ||
Assert.StartsWith("ClassWithAsyncMethod.ComplexMethodWithAwaitAsync ", message.First()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters