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
d8570384
Commit
d8570384
authored
May 01, 2018
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add unit tests for Helper.cs
parent
027156c5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
154 additions
and
0 deletions
+154
-0
HelperTest.cs
test/DotNetCore.CAP.Test/HelperTest.cs
+154
-0
No files found.
test/DotNetCore.CAP.Test/HelperTest.cs
0 → 100644
View file @
d8570384
using
System
;
using
System.Reflection
;
using
DotNetCore.CAP.Diagnostics
;
using
DotNetCore.CAP.Infrastructure
;
using
Newtonsoft.Json.Linq
;
using
Xunit
;
namespace
DotNetCore.CAP.Test
{
public
class
HelperTest
{
[
Fact
]
public
void
ToTimestampTest
()
{
//Arrange
var
time
=
DateTime
.
Parse
(
"2018-01-01 00:00:00"
);
//Act
var
result
=
Helper
.
ToTimestamp
(
time
);
//Assert
Assert
.
Equal
(
1514764800
,
result
);
}
[
Fact
]
public
void
FromTimestampTest
()
{
//Arrange
var
time
=
DateTime
.
Parse
(
"2018-01-01 00:00:00"
);
//Act
var
result
=
Helper
.
FromTimestamp
(
1514764800
);
//Assert
Assert
.
Equal
(
time
,
result
);
}
[
Fact
]
public
void
IsControllerTest
()
{
//Arrange
var
typeInfo
=
typeof
(
HomeController
).
GetTypeInfo
();
//Act
var
result
=
Helper
.
IsController
(
typeInfo
);
//Assert
Assert
.
True
(
result
);
}
[
Theory
]
[
InlineData
(
typeof
(
string
))]
[
InlineData
(
typeof
(
decimal
))]
[
InlineData
(
typeof
(
DateTime
))]
[
InlineData
(
typeof
(
DateTimeOffset
))]
[
InlineData
(
typeof
(
Guid
))]
[
InlineData
(
typeof
(
TimeSpan
))]
[
InlineData
(
typeof
(
Uri
))]
public
void
IsSimpleTypeTest
(
Type
type
)
{
//Act
var
result
=
Helper
.
IsComplexType
(
type
);
//Assert
Assert
.
False
(
result
);
}
[
Theory
]
[
InlineData
(
typeof
(
HomeController
))]
[
InlineData
(
typeof
(
Exception
))]
[
InlineData
(
typeof
(
Person
))]
public
void
IsComplexTypeTest
(
Type
type
)
{
//Act
var
result
=
Helper
.
IsComplexType
(
type
);
//Assert
Assert
.
True
(
result
);
}
[
Fact
]
public
void
AddExceptionPropertyTest
()
{
//Arrange
var
json
=
"{}"
;
var
exception
=
new
Exception
(
"Test Exception Message"
)
{
Source
=
"Test Source"
,
InnerException
=
{
}
};
var
expected
=
new
{
ExceptionMessage
=
new
{
Source
=
"Test Source"
,
Message
=
"Test Exception Message"
,
InnerMessage
=
new
{
}
}
};
//Act
var
result
=
Helper
.
AddExceptionProperty
(
json
,
exception
);
//Assert
var
jObj
=
JObject
.
Parse
(
result
);
Assert
.
Equal
(
jObj
[
"ExceptionMessage"
][
"Source"
].
Value
<
string
>(),
expected
.
ExceptionMessage
.
Source
);
Assert
.
Equal
(
jObj
[
"ExceptionMessage"
][
"Message"
].
Value
<
string
>(),
expected
.
ExceptionMessage
.
Message
);
}
[
Theory
]
[
InlineData
(
"10.0.0.1"
)]
[
InlineData
(
"172.16.0.1"
)]
[
InlineData
(
"192.168.1.1"
)]
public
void
IsInnerIPTest
(
string
ipAddress
)
{
Assert
.
True
(
Helper
.
IsInnerIP
(
ipAddress
));
}
[
Fact
]
public
void
AddTracingHeaderPropertyTest
()
{
//Arrange
var
json
=
"{}"
;
var
header
=
new
TracingHeaders
{
{
"key"
,
"value"
}
};
//Act
var
result
=
Helper
.
AddTracingHeaderProperty
(
json
,
header
);
//Assert
var
expected
=
"{\"TracingHeaders\":{\"key\":\"value\"}}"
;
Assert
.
Equal
(
expected
,
result
);
}
[
Fact
]
public
void
TryExtractTracingHeadersTest
()
{
//Arrange
var
json
=
"{\"TracingHeaders\":{\"key\":\"value\"}}"
;
TracingHeaders
header
=
null
;
string
removedHeadersJson
=
""
;
//Act
var
result
=
Helper
.
TryExtractTracingHeaders
(
json
,
out
header
,
out
removedHeadersJson
);
//Assert
Assert
.
True
(
result
);
Assert
.
NotNull
(
header
);
Assert
.
Single
(
header
);
Assert
.
Equal
(
"{}"
,
removedHeadersJson
);
}
}
}
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