Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
Lesson49
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
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
Пасько Виталий
Lesson49
Commits
2e424701
Commit
2e424701
authored
Oct 14, 2022
by
Пасько Виталий
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: добавил в индексацию проект с тестами.
parent
6e40b765
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
136 additions
and
0 deletions
+136
-0
PhoneControllerTests.cs
PhoneStore.Tests/PhoneControllerTests.cs
+108
-0
PhoneStore.Tests.csproj
PhoneStore.Tests/PhoneStore.Tests.csproj
+28
-0
No files found.
PhoneStore.Tests/PhoneControllerTests.cs
0 → 100644
View file @
2e424701
using
System
;
using
System.Net.Http
;
using
System.Text
;
using
System.Text.Json
;
using
System.Threading.Tasks
;
using
FluentAssertions
;
using
Microsoft.Extensions.DependencyInjection
;
using
PhoneStore.Enums
;
using
PhoneStore.Models
;
using
PhoneStore.Tests.Helpers
;
using
PhoneStore.ViewModels.PhoneViewModels
;
using
Xunit
;
using
StatusCodes
=
Microsoft
.
AspNetCore
.
Http
.
StatusCodes
;
namespace
PhoneStore.Tests
{
public
class
PhoneControllerTests
{
private
HttpClient
_httpClient
;
private
MobileContext
_context
;
public
PhoneControllerTests
()
{
var
webHost
=
Utilities
.
SubstituteDbOnTestDb
();
_httpClient
=
webHost
.
CreateClient
();
_context
=
webHost
.
Services
.
CreateScope
().
ServiceProvider
.
GetService
<
MobileContext
>();
}
[
Fact
]
public
async
Task
Send_Create_Phone_Returns_Success
()
{
var
phone
=
new
PhoneCreateViewModel
{
Name
=
"Test"
,
Price
=
3000
M
,
BrandId
=
Utilities
.
CreateBrandAndReturnBrandId
(
_context
)
};
string
json
=
JsonSerializer
.
Serialize
(
phone
);
var
content
=
new
StringContent
(
json
,
Encoding
.
UTF8
,
"application/json"
);
var
response
=
await
_httpClient
.
PostAsync
(
$"Phones/Create"
,
content
);
response
.
StatusCode
.
Should
().
Be
(
StatusCodes
.
Status200OK
);
}
[
Fact
]
public
async
Task
Send_Create_Phone_With_NotValidName_Returns_BadRequest
()
{
var
phone
=
new
PhoneCreateViewModel
{
Name
=
null
,
Price
=
0
,
BrandId
=
Utilities
.
CreateBrandAndReturnBrandId
(
_context
)
};
string
json
=
JsonSerializer
.
Serialize
(
phone
);
var
content
=
new
StringContent
(
json
,
Encoding
.
UTF8
,
"application/json"
);
var
response
=
await
_httpClient
.
PostAsync
(
$"Phones/Create"
,
content
);
response
.
StatusCode
.
Should
().
Be
(
StatusCodes
.
Status400BadRequest
);
}
[
Fact
]
public
async
Task
Send_Create_Phone_With_NotValidPrice_Returns_ValidationProblem
()
{
var
phone
=
new
PhoneCreateViewModel
{
Name
=
"Test"
,
Price
=
0
,
BrandId
=
Utilities
.
CreateBrandAndReturnBrandId
(
_context
)
};
string
json
=
JsonSerializer
.
Serialize
(
phone
);
var
content
=
new
StringContent
(
json
,
Encoding
.
UTF8
,
"application/json"
);
var
response
=
await
_httpClient
.
PostAsync
(
$"Phones/Create"
,
content
);
response
.
StatusCode
.
Should
().
Be
(
StatusCodes
.
Status400BadRequest
);
}
[
Fact
]
public
async
Task
Send_Create_Phone_With_NegativePrice_Returns_ValidationProblem
()
{
var
phone
=
new
PhoneCreateViewModel
{
Name
=
"Test"
,
Price
=
-
3000
M
,
BrandId
=
Utilities
.
CreateBrandAndReturnBrandId
(
_context
)
};
string
json
=
JsonSerializer
.
Serialize
(
phone
);
var
content
=
new
StringContent
(
json
,
Encoding
.
UTF8
,
"application/json"
);
var
response
=
await
_httpClient
.
PostAsync
(
$"Phones/Create"
,
content
);
response
.
StatusCode
.
Should
().
Be
(
StatusCodes
.
Status400BadRequest
);
}
[
Fact
]
public
async
Task
Get_Phone_By_Id_Returns_PhoneVM
()
{
var
phoneId
=
Utilities
.
CreatePhoneAndReturnPhoneId
(
_context
);
HttpResponseMessage
response
=
await
_httpClient
.
GetAsync
(
$"Phones/About?phoneId=
{
phoneId
}
"
);
var
jsonString
=
await
response
.
Content
.
ReadAsStringAsync
();
var
phoneVm
=
JsonSerializer
.
Deserialize
<
PhoneViewModel
>(
jsonString
);
response
.
StatusCode
.
Should
().
Be
(
StatusCodes
.
Status200OK
);
phoneVm
.
Should
().
NotBeNull
();
phoneVm
.
Brand
.
Should
().
NotBeNull
();
phoneVm
.
Id
.
Should
().
Be
(
phoneId
);
}
}
}
\ No newline at end of file
PhoneStore.Tests/PhoneStore.Tests.csproj
0 → 100644
View file @
2e424701
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.17" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PhoneStore\PhoneStore.csproj" />
</ItemGroup>
</Project>
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