The library helps us create the test server and client. Ok, so here we have the simplest test possible. Var response = await client.GetAsync("/api/owner") Īssert.Equal(HttpStatusCode.OK, response.StatusCode) UseConfiguration(new ConfigurationBuilder() Var server = new TestServer(new WebHostBuilder() Public async Task GetAllOwners_ReturnsAListOfOwners() Great! Let’s proceed to the integration test.įirst, we should rename the UnitTests1.cs file to something more appropriate like IntegrationTests.cs. You can quickly run the dotnet build to check if it compiles. That’s all we need to set up the project. ![]() We need it because we have to use the real server and configuration. \AccountOwnerServer\AccountOwnerServer.csproj This time around, we need to reference our main project AccountOwnerServer instead of just the Contracts project:ĭotnet add reference. We don’t mock stuff in integration tests. \Integration\Integration.csprojĪnd like the previous time add and restore the required packages:ĭotnet add package -version 3.1.0Īs you can see instead of using the Moq library, we’ve added the package because it provides a nice interface for writing integration tests in ASP.NET Core projects. So we start with navigating to the project root and adding a new xUnit project:Īfter that we need to add the newly created project to our solution:ĭotnet sln AccountOwnerServer.sln add. Like we did with our unit tests project in part 1 of the series, we are going to add a new one for integration tests. In our case, we are going to make sure that our app communicates with the database.įor that purpose, we are going to create a new project for integration tests, and add some simple tests. ![]() This is something every production-grade application should have because integration tests ensure that all of your application parts communicate properly. We already have a unit test, but since we are using TeamCity now, this is a great opportunity to introduce integration tests. We are going to add some integration tests to our application. How to Add an Integration Test to the Asp.Net Core Appįirst things first. Adding the Integration Build Configuration.How to Add an Integration Test to the Asp.Net Core App.Here’s what we are going to learn this time: This is really important if you want to follow along with the steps of the article and get the most out of it since we will be doing incremental changes to the branch. Important note: This time around, if you haven’t worked like that already, you need to fork the repo to follow along since we’ll be using it in TeamCity builds. Specify the server and a temporary path to upload to.The starting point for this part is the docker-series-prepare-ci-end branch of the docker-series repo on our GitHub.The Compress Command Line step looks like this: %system.7ZIP_PATH%\7z a -r -ttar deploy.tar. We use 7zip because our TC instance is hosted in Windows: We then use the SSH Exec runner to swap the new code into place: We tar the files first because it is slower to SSH many files instead of one file of the same size. ![]() We can place our code on the Linux server by using TeamCity’s built-in SSH Upload Runner. ![]() Adding keys is buried in the TeamCity Project Configuration screens:Īdministration -> Your Project Name -> SSH KeysĬlick “Upload SSH Key” and select the private key you wish to use: TeamCity supports storing SSH keys so they can be used in SSH Upload and SSH Exec build steps. Our server has already been configured to trust the SSH key we created. And really, TeamCity is pretty cool! Storing SSH Keys in TeamCity We use TeamCity because we already have our build artifacts there, TeamCity supports SSH and we’d rather not add anything else to our tech stack.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |