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
af9d22ed
Commit
af9d22ed
authored
Aug 21, 2017
by
yangxiaodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add model binder tests.
parent
13274160
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
105 additions
and
0 deletions
+105
-0
ModelBinderFactoryTest.cs
test/DotNetCore.CAP.Test/ModelBinderFactoryTest.cs
+47
-0
Sample.cs
test/DotNetCore.CAP.Test/Sample.cs
+58
-0
No files found.
test/DotNetCore.CAP.Test/ModelBinderFactoryTest.cs
0 → 100644
View file @
af9d22ed
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
System.Linq
;
using
System.Reflection
;
using
DotNetCore.CAP.Internal
;
using
Xunit
;
namespace
DotNetCore.CAP.Test
{
public
class
ModelBinderFactoryTest
{
IModelBinderFactory
_factory
;
public
ModelBinderFactoryTest
()
{
_factory
=
new
ModelBinderFactory
();
}
[
Theory
]
[
InlineData
(
nameof
(
Sample
.
DateTimeParam
))]
[
InlineData
(
nameof
(
Sample
.
StringParam
))]
[
InlineData
(
nameof
(
Sample
.
IntegerParam
))]
[
InlineData
(
nameof
(
Sample
.
GuidParam
))]
[
InlineData
(
nameof
(
Sample
.
UriParam
))]
public
void
CreateSimpleTypeBinderTest
(
string
methodName
)
{
var
datetimeMethod
=
typeof
(
Sample
).
GetRuntimeMethods
().
Single
(
x
=>
x
.
Name
==
methodName
);
var
binder
=
_factory
.
CreateBinder
(
datetimeMethod
.
GetParameters
()[
0
]);
Assert
.
NotNull
(
binder
);
Assert
.
True
(
binder
is
SimpleTypeModelBinder
);
Assert
.
False
(
binder
is
ComplexTypeModelBinder
);
}
[
Theory
]
[
InlineData
(
nameof
(
Sample
.
ComplexTypeParam
))]
public
void
CreateComplexTypeBinderTest
(
string
methodName
)
{
var
datetimeMethod
=
typeof
(
Sample
).
GetRuntimeMethods
().
Single
(
x
=>
x
.
Name
==
methodName
);
var
binder
=
_factory
.
CreateBinder
(
datetimeMethod
.
GetParameters
()[
0
]);
Assert
.
NotNull
(
binder
);
Assert
.
False
(
binder
is
SimpleTypeModelBinder
);
Assert
.
True
(
binder
is
ComplexTypeModelBinder
);
}
}
}
test/DotNetCore.CAP.Test/Sample.cs
0 → 100644
View file @
af9d22ed
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
DotNetCore.CAP.Test
{
public
class
Sample
{
public
void
DateTimeParam
(
DateTime
dateTime
)
{
}
public
void
StringParam
(
string
@string
)
{
}
public
void
GuidParam
(
Guid
guid
)
{
}
public
void
UriParam
(
Uri
uri
)
{
}
public
void
IntegerParam
(
int
@int
)
{
}
public
void
ComplexTypeParam
(
ComplexType
complexType
)
{
}
}
public
class
ComplexType
{
public
DateTime
Time
{
get
;
set
;
}
public
string
String
{
get
;
set
;
}
public
Guid
Guid
{
get
;
set
;
}
public
Person
Person
{
get
;
set
;
}
}
public
class
Person
{
public
int
Age
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
}
}
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