I am exposing a service using asp.net web API. each get/put/post calls internally corresponding WCF method after doing some logic like converting passed objects.
(using apicontroller, not odatacontroller)
I would like to test the written 'logic' but I can't make the WCF call yet as it is being written by some other team (for which I will write stub). I'm planning to write a test hook in each get/put.
My requirement is to write simple client code (not using paid tool, but a simple .exe which can test a running service) to test the logic written.
How do I go about it?
If you want to test Web API i suggest using this neat tool called RestSharp, its free not paid
Here is the URL : http://restsharp.org/
You can get it through Nuget Package Manager.
Once you install it, you would be able to test your service pretty easily.
It has examples to get you started on the first page.
Related
I am using WebApplicationFactory<TStartup> for integration testing of a .NET Core 3.0 web application.
It works when it need to test just one web application.
But what if web application need to send request to WebAPI application. I need somehow to instantiate both WebApplicationFactory<Web.Startup> and WebApplicationFactory<Api.Startup>.
I tried different alternatives with no luck.
Can anybody with experience of similar task point a right way to me.
P.S. Inside web application there is injected internal HttpClient that used internally in Controllers to send requests to API:
services.AddHttpClient<IInternalApiClient, InternalApiClient>();
You wouldn't. What you're talking about would be a "systems test", i.e. testing the whole system. Integration testing is about making sure the sub-components of a single application function together. As such, you'd mock the the service class that calls out to your API: InternalApiClient. In your test server's web host setup, you'd create a mock of IInternalApiClient and stub the appropriate methods to return dummy data instead of actually calling out to the API.
I'm learning ASP.Net MVC and I've read that it is easy to unit test as controllers can be instantiated and have their methods called without needing to deploy to a web server, and that it is easy to mock dependent objects etc. (see http://msdn.microsoft.com/en-us/library/gg416511(VS.98).aspx and multiple other references).
It's also possible to run acceptance level tests on the MVC App through the browser using Selenium or Waitin using your own favourite framework to author and control the tests.
What I'd like to know is if it's possible to run ATDD tests at an acceptance test level by calling the controller methods in a deployed, running MVC application, e.g. from Specflow, rather than having to test through the UI?
Or more generally, is it possible to programatically call the API of the ASP.Net MVC application from a test?
It seems like there is a gap in what it is possible to test between unit testing and browser based UI testing. Has anyone been able to bridge that gap?
Your question isn't clear but if you are asking what I think you are:
MVC controllers (generally) obey REST.
You can call any action on a controller (via a web server like IIS) by sending it a HTTP request. It will return a HTTP response containing the relevant data and data type(HTML, json, XML, etc.). So yes you can programatically call a controller like an API (if by API you mean something you send HTTP requests to and get HTTP responses from) therefore yes you can test the controller without using the UI.
I would like to learn how to test code that I wrote that relies on an external resource.
There is a website that I scrape data from. I then parse it and save to a strongly typed domain object.
I have unit tests that test this but because they rely on an external resource - having an internet connection that has access to the website - I can't depend on the tests being able to execute at all times.
I don't want to moq the website (there is no interface anyhow), or setup local html source text files. What I would prefer is in my nunit Setup() method to create a web server that can dish up the urls just like the external website would do. Perhaps it would redirect to localhost instead of the website.
I'm not looking for a specific solution. I instead would like guidance on best practice for handling this testing situation. Especially if there is a recommended .Net library or guidance from Microsoft.
I have been recently added to a project where I will need to be doing functional and load testing for some existing Web Services (SOAP).
I was wondering if it is possible to call a web service from a console application for testing purposes? I do not have permissions to code in the existing Project so I need to create a new one, which is what my real issue is, I do not know how to call the web services (or the web service code) from outside of their Solution.
I know this will make things more difficult, especially for recording test results, but I have no choice as I am a contractor and can not get the required permissions. I can pull code and see the source code, I just don't want to code in the existing project as my local changes will get blown away every time there is new code to pull down.
I have done some basic testing using SoapUI, but the open Source version does not meet all the requirements I have and would rather just write my own tests then try and find a free 3rd party solution (as I also have no budget).
Thanks,
cwlovell13
You can write a simple WCF client to consume existing Web Services (SOAP).
Maybe you can reference this .
Accessing Services Using a WCF Client
Following the KISS principle, I suddenly realised the following:
In .NET, you can use the Entity Model Framework to wrap around a database.
This model can be exposed as a web service through WCF.
This web service would have a very standardized definition.
A client application could be created which could consume any such RESTful web service.
I don't want to re-invent the wheel and it wouldn't surprise me if someone has already done this, so my question is simple: Has anyone already created a simple (desktop, not web) client application that can consume a RESTful service that's based on the Entity Framework and which will allow the user to read and write data directly to this service?
Otherwise, I'll just have to "invent" this myself. :-)Problem is, the database layer and RESTful service is already finished. The RESTful service will only stay in the project during it's development phase, since we can use the database-layer assembly directly from the web applications that are build around it. When the web application is deployed, the RESTful services are just kept out of the deployment.
But the database has a lot of data to manage over nearly 50 tables. When developing against a local database, we can have straight access to the database so I wouldn't need this tool for this. When it's deployed, the web application would be the only way to access the data so I could not use this tool. But we're also having a test phase where the database is stored on another system outside the local domain and this database is not available for developers. Only administrators have direct access to this database, making tests a bit more complex.
However, through the RESTful service, I can still access the data directly. Thus, when some test goes wrong, I can repair the data through this connection or just create a copy of the data for tests on my local system. There's plenty of other functionality and it's even possible to just open the URL to a table service straight in Excel or XMLSpy to see the contents. But when I want to write something back, I have to write special code to do just that. A generic tool that would allow me to access the data and modify it would be easier. Since it's a generic setup around the ADO.NET Data services, this should be reasonable easy too.
Thus, I can do it but hoped someone else has already done something similar. But it appears that there's no such tool made yet...
You are referring to ADO.Net Data Services. It basically creates an Entity Database Model and adds a REST frontend to the service using ASMX. There is a How To article availble from MSDN here on consuming the service using .Net. I have also done the same thing using the normally WebClient class in .Net in the past.
You can also look at the WCF REST Starter Kit if you want to roll your own based on Entity Framework. The starter kit also contains a handy new WebClient class that can be used to communicate with REST services.
Clarification
There is no prebuilt application client that I am aware off which will talk to these service, since they are pretty much accessing the data using Web Services. There is the Microsoft Smart Client Factory which is most likely the closest thing I have worked with.
I mentioned the above 2 options since they already have libraries in .Net that work with them directly, either as a referenced Web Service, or for the more adventurious, myself included, using the WebClient library or alternatively the new HTTPClient library in the WCF REST Starter kit.
I have used both, in Windows, Web, Silverlight and WCF. The latter being the easiest since they are focussed at REST.
We are currently investigating Prism which strongly leans to using this method when using WCF for front-end development.
Assumption
With regards to this question, you are making a generic assumption that wrapping ADO Entity Framework with a WCF service it will be generic. ADO.Net Data Services is the closest you will get, however the structure of the database will fundamently change the way you interact with it. Going a level higher in a "generic" way would be dangerous, as these 2 technologies, individually or together, are already as generic as possible.
In addition to Data Services (+1), consider RIA Services. It's like a domain-specific version of data services for Silverlight or WPF clients. Less flexible, but easier, than Data Services.