Edition 0 Updated to asp. Net core 0



Yüklə 11,82 Mb.
Pdf görüntüsü
səhifə141/288
tarix12.07.2023
ölçüsü11,82 Mb.
#136458
1   ...   137   138   139   140   141   142   143   144   ...   288
public
class
PrimeWebDefaultRequestShould 

private
readonly
TestServer _server; 
private
readonly
HttpClient _client; 
public
PrimeWebDefaultRequestShould
() 

// Arrange
_server = 
new
TestServer
(
new
WebHostBuilder
() 
.
UseStartup
()); 
_client = _server.
CreateClient
(); 

[Fact] 
public
async Task 
ReturnHelloWorld
() 

// Act
var
response = await _client.
GetAsync
(
"/"
); 
response.
EnsureSuccessStatusCode
(); 
var
responseString = await response.
Content
.
ReadAsStringAsync
(); 
// Assert
Assert.
Equal
(
"Hello World!"
, responseString); 




155 
CHAPTER 5 | Designing and Developing Multi-Container and Microservice-Based .NET Applications 
Additional resources 

Steve Smith. Testing controllers
(ASP.NET Core) 
https://learn.microsoft.com/aspnet/core/mvc/controllers/testing
 

Steve Smith. Integration testing
(ASP.NET Core) 
https://learn.microsoft.com/aspnet/core/test/integration-tests
 

Unit testing in .NET using dotnet test
https://learn.microsoft.com/dotnet/core/testing/unit-testing-with-dotnet-test
 

xUnit.net
. Official site. 
https://xunit.net/
 

Unit Test Basics.
https://learn.microsoft.com/visualstudio/test/unit-test-basics
 

Moq
. GitHub repo. 
https://github.com/moq/moq
 

NUnit
. Official site. 
https://nunit.org/
 
Implementing service tests on a multi-container application 
As noted earlier, when you test multi-container applications, all the microservices need to be running 
within the Docker host or container cluster. End-to-end service tests that include multiple operations 
involving several microservices require you to deploy and start the whole application in the Docker 
host by running docker-compose up (or a comparable mechanism if you are using an orchestrator). 
Once the whole application and all its services is running, you can execute end-to-end integration and 
functional tests. 
There are a few approaches you can use. In the docker-compose.yml file that you use to deploy the 
application at the solution level you can expand the entry point to use 
dotnet test
. You can also use 
another compose file that would run your tests in the image you are targeting. By using another 
compose file for integration tests that includes your microservices and databases on containers, you 
can make sure that the related data is always reset to its original state before running the tests. 
Once the compose application is up and running, you can take advantage of breakpoints and 
exceptions if you are running Visual Studio. Or you can run the integration tests automatically in your 
CI pipeline in Azure DevOps Services or any other CI/CD system that supports Docker containers. 
Testing in eShopOnContainers 
The reference application (eShopOnContainers) tests were recently restructured and now there are 
four categories: 
1.
Unit
tests, just plain old regular unit tests, contained in the 
{MicroserviceName}.UnitTests
projects 


156 
CHAPTER 5 | Designing and Developing Multi-Container and Microservice-Based .NET Applications 
2.

Yüklə 11,82 Mb.

Dostları ilə paylaş:
1   ...   137   138   139   140   141   142   143   144   ...   288




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin