All Questions
Tagged with web-api-testing c#
41 questions
-1
votes
1
answer
105
views
How to call service class in mock Framework with x-unit method ASP Web API .Net 6?
We will be performing unit testing in ASP.NET Web API using .NET 6. We are attempting unit testing using the Moq framework with the xUnit testing method. To begin, we download the Moq package. Next, ...
0
votes
1
answer
57
views
Get function for searching is not giving the search result but returning all the elements while unit testing
I have a function called GetAuthors which takes an expression for checking if given string is in authors names. I have problems while unit testing. The function supposed to find names that contains ...
1
vote
2
answers
233
views
Web API & Postman - Add Multiple Attachments
Hello All I am not able to upload multiple attachments with postman and I don't understand why
Here there is my Api in order to replace existing files
[HttpPost]
[Route("api/attachments/...
0
votes
1
answer
530
views
How to test API that calls a service and that service calls a repository?
I have four projects that need to be tested (my design patter is similar to this https://exceptionnotfound.net/the-repository-service-pattern-with-dependency-injection-and-asp-net-core/). The first ...
0
votes
1
answer
86
views
Long running Task (Deadlock situation because of incorrect async call)
I have a notification project which notifies the user with an Excel report by email. To do it, the notification project calls Project A api endpoint, and Project A calls Project B endpoint which calls ...
7
votes
1
answer
5k
views
Cannot assert Bad Request [HTTP 400 error] using RestSharp. Throws System.Net.Http.HttpRequestException
Using RestSharp I have written the following test and the expected outcome is to return error 400 with some error messages in Json format.
But the following test fails at await client.PostAsync(...
0
votes
3
answers
3k
views
Casting an ActionResult rather than IActionResult to an OKObjectResult for testing a 200 status code?
I am moving to use and ActionResult rather than IActionResult so that Swagger automatically picks up my types, but I am getting an error saying that I cannot cast an ActionResult to an OkObjectResult.
...
3
votes
0
answers
3k
views
Minimal APIs NUnit test: missing testhost.deps.json [duplicate]
In my .NET6 project, I have some minimal APIs and I want to test them. You find the full source code on GitHub. For that, I created a new NUnit test project. In the project file, I added ...
0
votes
1
answer
69
views
How to run my code each and everytime on event based triggering
I've a code in vs-2019, for unit testing with c# and Nunit framework. What I need to do is to trigger this code using a queue message, everytime when the queue got a new message. How can I do that?? ...
0
votes
1
answer
2k
views
How to get element value from response data to json
Im writing an API automation test with RestSharp.Any kind of help will be greatly appreciated!
I'm getting data values from the response & I need to write few values to my json file (which I will ...
0
votes
0
answers
575
views
IMediator mock return null from controller class in xUnit test
I have Web API Controller and trying to test end-point. I am using MediatR in controller class for method 'GetHandHeldByIMEI()' . I have used Setup (x => x.Send( new GetHandHeldByIMEI(imei) but in ...
3
votes
1
answer
3k
views
How to add bearertoken to post/get restsharp automation testing
maybe anyone could help me with RestSharp api automation testing.
I'll try to be as clear as possible.
Basically the scheme is:
I'm sending my username/password credentials & I get BearerToken in ...
2
votes
1
answer
3k
views
Integration Testing multipart/form-data c#
I have trouble trying to create an integration test for my post call that accepts a viewmodel that has amongst other values, an IFormFile, which makes this call from an application/json to a multipart/...
3
votes
1
answer
3k
views
Oauth 2.0 RestSharp passing accesstoken
Following on from my last question I have made some progress but still stuck
I am able to obtain the accessToken using this SetUp method in the test class
but when I try to run the test ...
1
vote
0
answers
1k
views
Restrict my Web API Core to accept HTML tag in POST request?
I am using WebAPI Core and when I am sending some data from Postman as a POST request, it is saved to the database.
I have a requirement to restrict specific characters and HTML tags from the input at ...