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
4d5af5db
Commit
4d5af5db
authored
Jul 01, 2017
by
yangxiaodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Unit Tests.
parent
4b348315
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
0 deletions
+92
-0
ConsumerServiceSelectorTest.cs
test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs
+92
-0
No files found.
test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs
0 → 100644
View file @
4d5af5db
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
System.Threading.Tasks
;
using
DotNetCore.CAP.Abstractions
;
using
DotNetCore.CAP.Internal
;
using
Microsoft.Extensions.DependencyInjection
;
using
Xunit
;
namespace
DotNetCore.CAP.Test
{
public
class
ConsumerServiceSelectorTest
{
private
IServiceProvider
_provider
;
public
ConsumerServiceSelectorTest
()
{
var
services
=
new
ServiceCollection
();
//services.AddSingleton<IConsumerServiceSelector, DefaultConsumerServiceSelector>();
services
.
AddScoped
<
IFooTest
,
CandidatesFooTest
>();
services
.
AddScoped
<
IBarTest
,
CandidatesBarTest
>();
services
.
AddLogging
();
services
.
AddCap
();
_provider
=
services
.
BuildServiceProvider
();
}
[
Fact
]
public
void
CanFindAllConsumerService
()
{
var
selector
=
_provider
.
GetRequiredService
<
IConsumerServiceSelector
>();
var
candidates
=
selector
.
SelectCandidates
(
_provider
);
Assert
.
Equal
(
2
,
candidates
.
Count
);
}
[
Fact
]
public
void
CanFindSpecifiedTopic
()
{
var
selector
=
_provider
.
GetRequiredService
<
IConsumerServiceSelector
>();
var
candidates
=
selector
.
SelectCandidates
(
_provider
);
var
bestCandidates
=
selector
.
SelectBestCandidate
(
"Candidates.Foo"
,
candidates
);
Assert
.
NotNull
(
bestCandidates
);
Assert
.
NotNull
(
bestCandidates
.
MethodInfo
);
Assert
.
Equal
(
bestCandidates
.
MethodInfo
.
ReturnType
,
typeof
(
Task
));
}
}
public
class
CandidatesTopic
:
TopicAttribute
{
public
CandidatesTopic
(
string
topicName
)
:
base
(
topicName
)
{
}
}
public
interface
IFooTest
{
}
public
interface
IBarTest
{
}
public
class
CandidatesFooTest
:
IFooTest
,
IConsumerService
{
[
CandidatesTopic
(
"Candidates.Foo"
)]
public
Task
GetFoo
()
{
Console
.
WriteLine
(
"GetFoo() method has bee excuted."
);
return
Task
.
CompletedTask
;
}
[
CandidatesTopic
(
"Candidates.Foo2"
)]
public
void
GetFoo2
()
{
Console
.
WriteLine
(
"GetFoo2() method has bee excuted."
);
}
}
public
class
CandidatesBarTest
:
IBarTest
{
[
CandidatesTopic
(
"Candidates.Bar"
)]
public
Task
GetBar
()
{
Console
.
WriteLine
(
"GetBar() method has bee excuted."
);
return
Task
.
CompletedTask
;
}
[
CandidatesTopic
(
"Candidates.Bar2"
)]
public
void
GetBar2
()
{
Console
.
WriteLine
(
"GetBar2() method has bee excuted."
);
}
}
}
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