Beispiel #1
0
        public void RestSharpTestWeather()
        {
            RestApiHelper <Parameters> restApi         = new RestApiHelper <Parameters>();
            NameValueCollection        paramCollection = new NameValueCollection();
            string operationName = "weather";

            paramCollection.Add("q", "London");
            paramCollection.Add("APPID", appid);

            var        restUrl     = restApi.SetUrl(restApi.QueryBuilder(operationName, paramCollection));
            var        restRequest = restApi.CreateGetRequest();
            var        response    = restApi.GetResponse(restUrl, restRequest);
            Parameters content     = restApi.GetContent <Parameters>(response);

            Assert.AreEqual(200, content.cod);
            Assert.AreEqual("London", content.name);
            Assert.IsNotNull(content.main.temp);
        }
Beispiel #2
0
        public void RestSharpTestForecast()
        {
            RestApiHelper <Parameters> restApi         = new RestApiHelper <Parameters>();
            NameValueCollection        paramCollection = new NameValueCollection();
            string operationName = "forecast";

            paramCollection.Add("id", "524901");
            paramCollection.Add("APPID", appid);

            var        restUrl     = restApi.SetUrl(restApi.QueryBuilder(operationName, paramCollection));
            var        restRequest = restApi.CreateGetRequest();
            var        response    = restApi.GetResponse(restUrl, restRequest);
            Parameters content     = restApi.GetContent <Parameters>(response);

            Assert.AreEqual(200, content.cod);
            Assert.AreEqual(524901, content.city.id);
            Assert.AreEqual("Moscow", content.city.name);
        }
Beispiel #3
0
        public void RestSharpTestStationsPut()
        {
            RestApiHelper <Parameters> restApi = new RestApiHelper <Parameters>("3.0");
            string operationName = "stations";
            string id            = "5d3afec76c634e000131c036";
            NameValueCollection paramCollection = new NameValueCollection();

            paramCollection.Add("APPID", appid);

            var        restUrl     = restApi.SetUrl(restApi.QueryBuilder(operationName, id, paramCollection));
            var        restRequest = restApi.CreateGetRequest();
            var        response    = restApi.GetResponse(restUrl, restRequest);
            Parameters content     = restApi.GetContent <Parameters>(response);

            Assert.AreEqual("San Francisco Test Station", content.name); string nameValueBefore = content.name;
            Assert.AreEqual(-122.43, content.longitude); double longitudeValueBefore            = content.longitude;
            Assert.AreEqual(37.76, content.latitude); double    latitudeValueBefore             = content.latitude;
            Assert.AreEqual(150, content.altitude); int         altitudeValueBefore             = content.altitude;


            string jsonRequest = @"{
                                    ""external_id"": ""SF_UPD001"",
                                    ""name"": ""Wowa-City"",
                                    ""latitude"": 20.20,
                                    ""longitude"": -20.20,
                                    ""altitude"": 20
                                  }";


            restRequest = restApi.CreatePutRequest(jsonRequest);
            response    = restApi.GetResponse(restUrl, restRequest);
            content     = restApi.GetContent <Parameters>(response);
            Assert.AreNotEqual(nameValueBefore, content.name);
            Assert.AreNotEqual(longitudeValueBefore, content.longitude);
            Assert.AreNotEqual(latitudeValueBefore, content.latitude);
            Assert.AreNotEqual(altitudeValueBefore, content.altitude);
        }