Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/damiansuess/test.restunittest
Xamarin REST API sample
https://github.com/damiansuess/test.restunittest
mock restapi restsharp unit-testing xamarin xamarin-forms xeno-innovations
Last synced: 9 days ago
JSON representation
Xamarin REST API sample
- Host: GitHub
- URL: https://github.com/damiansuess/test.restunittest
- Owner: DamianSuess
- Created: 2019-07-15T01:03:25.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T05:49:56.000Z (almost 2 years ago)
- Last Synced: 2024-10-11T19:13:36.302Z (26 days ago)
- Topics: mock, restapi, restsharp, unit-testing, xamarin, xamarin-forms, xeno-innovations
- Language: C#
- Size: 388 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Xamarin REST API sample
This repo shows you how to setup a Unit Testing framework for RESTful API calls using RestSharp and ASP.NET Core. The sample also includes a Xamarin.Forms test app which is under construction.System test examples show you how to perform validations both online and offline!
## Projects
* Test.RestApi.SystemTests
* ``RestTests.cs`` - These tests require an internet connection
* ``RestMockTest.cs`` - Offline tests using our own mock REST API server
* Test.RestApi
* ``Models`` are used for system tests
* The GUI is just garbage noise & can be removed## Tech Used
* [Microsoft.VisualStudio.TestTools.UnitTesting](https://docs.microsoft.com/en-us/visualstudio/test/using-microsoft-visualstudio-testtools-unittesting-members-in-unit-tests?view=vs-2019)
* [RestSharp](http://restsharp.org/)## Sample Snips
### RestSharp - Multiple Rows
```cs
[TestMethod]
[DataTestMethod]
[DataRow("nl", "3825", HttpStatusCode.OK)]
[DataRow("us", "15203", HttpStatusCode.OK)]
public void ContentTypeTest(string countryCode, string zipCode, HttpStatusCode statusCode)
{
RestClient client = new RestClient("http://api.zippopotam.us");
RestRequest request = new RestRequest($"{countryCode}/{zipCode}", Method.GET);IRestResponse response = client.Execute(request);
Assert.AreEqual(statusCode, response.StatusCode);
}
```