Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CAP
Commits
a162d488
Commit
a162d488
authored
Aug 21, 2017
by
yangxiaodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ConsumerInvokerFactory unit test.
parent
ab0ccc92
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
0 deletions
+84
-0
ConsumerInvokerFactoryTest.cs
test/DotNetCore.CAP.Test/ConsumerInvokerFactoryTest.cs
+72
-0
Sample.cs
test/DotNetCore.CAP.Test/Sample.cs
+12
-0
No files found.
test/DotNetCore.CAP.Test/ConsumerInvokerFactoryTest.cs
0 → 100644
View file @
a162d488
using
System
;
using
System.Linq
;
using
System.Reflection
;
using
DotNetCore.CAP.Abstractions
;
using
DotNetCore.CAP.Internal
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.Logging
;
using
Xunit
;
namespace
DotNetCore.CAP.Test
{
public
class
ConsumerInvokerFactoryTest
{
IConsumerInvokerFactory
consumerInvokerFactory
;
public
ConsumerInvokerFactoryTest
()
{
var
services
=
new
ServiceCollection
();
services
.
AddLogging
();
var
provider
=
services
.
BuildServiceProvider
();
var
logFactory
=
provider
.
GetRequiredService
<
ILoggerFactory
>();
var
binder
=
new
ModelBinderFactory
();
consumerInvokerFactory
=
new
ConsumerInvokerFactory
(
logFactory
,
binder
,
provider
);
}
[
Fact
]
public
void
CreateInvokerTest
()
{
var
methodInfo
=
typeof
(
Sample
).
GetRuntimeMethods
()
.
Single
(
x
=>
x
.
Name
==
nameof
(
Sample
.
ThrowException
));
var
description
=
new
ConsumerExecutorDescriptor
{
MethodInfo
=
methodInfo
,
ImplTypeInfo
=
typeof
(
Sample
).
GetTypeInfo
()
};
var
messageContext
=
new
MessageContext
();
var
context
=
new
ConsumerContext
(
description
,
messageContext
);
var
invoker
=
consumerInvokerFactory
.
CreateInvoker
(
context
);
Assert
.
NotNull
(
invoker
);
}
[
Theory
]
[
InlineData
(
nameof
(
Sample
.
ThrowException
))]
[
InlineData
(
nameof
(
Sample
.
AsyncMethod
))]
public
async
void
InvokeMethodTest
(
string
methodName
)
{
var
methodInfo
=
typeof
(
Sample
).
GetRuntimeMethods
()
.
Single
(
x
=>
x
.
Name
==
methodName
);
var
description
=
new
ConsumerExecutorDescriptor
{
MethodInfo
=
methodInfo
,
ImplTypeInfo
=
typeof
(
Sample
).
GetTypeInfo
()
};
var
messageContext
=
new
MessageContext
();
var
context
=
new
ConsumerContext
(
description
,
messageContext
);
var
invoker
=
consumerInvokerFactory
.
CreateInvoker
(
context
);
await
Assert
.
ThrowsAsync
(
typeof
(
Exception
),
async
()
=>
{
await
invoker
.
InvokeAsync
();
});
}
}
}
test/DotNetCore.CAP.Test/Sample.cs
View file @
a162d488
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Text
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
DotNetCore.CAP.Test
namespace
DotNetCore.CAP.Test
{
{
...
@@ -36,6 +37,17 @@ namespace DotNetCore.CAP.Test
...
@@ -36,6 +37,17 @@ namespace DotNetCore.CAP.Test
{
{
}
}
public
void
ThrowException
()
{
throw
new
Exception
();
}
public
async
Task
<
int
>
AsyncMethod
()
{
await
Task
.
FromResult
(
3
);
throw
new
Exception
();
}
}
}
public
class
ComplexType
public
class
ComplexType
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment