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
0f573d5e
Commit
0f573d5e
authored
Jul 19, 2017
by
yangxiaodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add unit tests of Dispatcher.
parent
4e9249b1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
93 additions
and
0 deletions
+93
-0
DefaultDispatcherTest.cs
test/DotNetCore.CAP.Test/Processor/DefaultDispatcherTest.cs
+93
-0
No files found.
test/DotNetCore.CAP.Test/Processor/DefaultDispatcherTest.cs
0 → 100644
View file @
0f573d5e
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
DotNetCore.CAP.Infrastructure
;
using
DotNetCore.CAP.Models
;
using
DotNetCore.CAP.Processor
;
using
DotNetCore.CAP.Processor.States
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.Options
;
using
Moq
;
using
Xunit
;
namespace
DotNetCore.CAP.Test
{
public
class
DefaultDispatcherTest
{
private
CancellationTokenSource
_cancellationTokenSource
;
private
ProcessingContext
_context
;
private
IServiceProvider
_provider
;
private
Mock
<
IStorageConnection
>
_mockStorageConnection
;
private
Mock
<
IQueueExecutorFactory
>
_mockQueueExecutorFactory
;
private
Mock
<
IQueueExecutor
>
_mockQueueExecutor
;
public
DefaultDispatcherTest
()
{
_mockStorageConnection
=
new
Mock
<
IStorageConnection
>();
_mockQueueExecutorFactory
=
new
Mock
<
IQueueExecutorFactory
>();
_mockQueueExecutor
=
new
Mock
<
IQueueExecutor
>();
_mockQueueExecutorFactory
.
Setup
(
x
=>
x
.
GetInstance
(
MessageType
.
Publish
)).
Returns
(
_mockQueueExecutor
.
Object
);
_cancellationTokenSource
=
new
CancellationTokenSource
();
var
services
=
new
ServiceCollection
();
services
.
AddTransient
<
DefaultDispatcher
>();
services
.
AddLogging
();
services
.
Configure
<
IOptions
<
CapOptions
>>(
x
=>
{
});
services
.
AddOptions
();
services
.
AddSingleton
(
_mockStorageConnection
.
Object
);
services
.
AddSingleton
(
_mockQueueExecutorFactory
.
Object
);
_provider
=
services
.
BuildServiceProvider
();
_context
=
new
ProcessingContext
(
_provider
,
_cancellationTokenSource
.
Token
);
}
[
Fact
]
public
void
MockTest
()
{
Assert
.
NotNull
(
_provider
.
GetServices
<
IStorageConnection
>());
}
[
Fact
]
public
async
void
ProcessAsync_CancellationTokenCancelled_ThrowsImmediately
()
{
// Arrange
_cancellationTokenSource
.
Cancel
();
var
fixture
=
Create
();
// Act
await
Assert
.
ThrowsAsync
<
OperationCanceledException
>(()
=>
fixture
.
ProcessAsync
(
_context
));
}
[
Fact
]
public
async
Task
ProcessAsync
()
{
// Arrange
var
job
=
new
CapPublishedMessage
{
};
var
mockFetchedJob
=
Mock
.
Get
(
Mock
.
Of
<
IFetchedMessage
>(
fj
=>
fj
.
MessageId
==
42
&&
fj
.
MessageType
==
MessageType
.
Publish
));
_mockStorageConnection
.
Setup
(
m
=>
m
.
FetchNextMessageAsync
())
.
ReturnsAsync
(
mockFetchedJob
.
Object
).
Verifiable
();
_mockQueueExecutor
.
Setup
(
x
=>
x
.
ExecuteAsync
(
_mockStorageConnection
.
Object
,
mockFetchedJob
.
Object
))
.
Returns
(
Task
.
FromResult
(
OperateResult
.
Success
));
var
fixture
=
Create
();
// Act
await
fixture
.
ProcessAsync
(
_context
);
// Assert
_mockStorageConnection
.
VerifyAll
();
}
private
DefaultDispatcher
Create
()
=>
_provider
.
GetService
<
DefaultDispatcher
>();
}
}
\ No newline at end of file
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