dotnet-testcontainers | support tests with throwaway instances | Unit Testing library
kandi X-RAY | dotnet-testcontainers Summary
kandi X-RAY | dotnet-testcontainers Summary
🐋 A library to support tests with throwaway instances of Docker containers for all compatible .NET Standard versions.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of dotnet-testcontainers
dotnet-testcontainers Key Features
dotnet-testcontainers Examples and Code Snippets
Community Discussions
Trending Discussions on dotnet-testcontainers
QUESTION
I am using dotnet-testcontainers
https://github.com/HofmeisterAn/dotnet-testcontainers to spin up a container with mountebank in my xUnit test.
I can successfully create a mountebank client and create an imposter successfully.
The issue is that when the test is run, the app tries to make a call to the imposter on http://localhost:3000
and gets connection refused.
I can successfully open http://localhost:2525
and can see Mountebank default page. So mountebank is running fine. I also confirmed that the imposter was created successfully on port 3000
by looking at docker container log.
I also tried to use Postman to make a call to my imposter at http:localhost:3000
and get connection refused.
What could be the issue? Is this an issue that port 3000
in the docker container is not exposed or something? Below is my code:
ANSWER
Answered 2021-Dec-02 at 05:38Might be useful for someone else who would face this issue. Figured out what the issue was. I was not mapping the host port and the imposter port in the container. Read about published ports https://docs.docker.com/config/containers/container-networking/ and used WithExposedPort(3000)
and then did port binding of that port with host port using WithPortBinding(3000,3000)
where the first
port in this method is host port and second
port is container port.
QUESTION
I am trying to add keycloak as a testcontainer to my .net core (5) integration tests using the dotnet-testcontainers library .
My Problem is, I am struggling with HTTPS-Support having a container using self-signed certificates and TestServer-Class for my integration tests.
To be precise, I am using Microsofts TestServer class to create real API requests with an in-memory config for using a keycloak-testcontainer with exposed port 8443 and its self-signed certificate.
The Problem is: I can’t add a HttpClientHandler
to TestServers HttpClient(created via serverCreateClient()
) to allow non-trusted certs within this handler. I have created a concrete example here on branch apitests-https. The failing test can be found here, its in the SucceedsWhenGetRequestWithTokenReturnsListOfArticles
test method. I added some Comments to the class and the Startup.cs of DemoApi - Project that shows what i've tried.
As a result, the TestServers internal Jwt Middleware uses the default HttpClient and throws the following AuthenticationException:
...ANSWER
Answered 2021-Feb-06 at 16:26Ok, I worked it out. Imho it is not the best solution, but as long as I don't have another one, this should work. All I had to do was:
- Add
IWebHostEnvironment
as a field to Startup.cs and inject in inStartup()
constructor.
Startup then looks like this:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install dotnet-testcontainers
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page