PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Geocoding/Artem.GoogleGeocoding.Tests/GeoRequestTest.cs

#
C# | 138 lines | 62 code | 26 blank | 50 comment | 0 complexity | e0a4cd8bf63588b2556afa0169d1bc7e MD5 | raw file
  1using Artem.Google.Net;
  2using Microsoft.VisualStudio.TestTools.UnitTesting;
  3using System;
  4
  5namespace Artem.GoogleGeocoding.Tests {
  6
  7
  8    /// <summary>
  9    ///This is a test class for GeoRequestTest and is intended
 10    ///to contain all GeoRequestTest Unit Tests
 11    ///</summary>
 12    [TestClass()]
 13    public class GeoRequestTest {
 14
 15        #region Construct /////////////////////////////////////////////////////////////////////////
 16
 17        private TestContext testContextInstance;
 18
 19        /// <summary>
 20        ///Gets or sets the test context which provides
 21        ///information about and functionality for the current test run.
 22        ///</summary>
 23        public TestContext TestContext {
 24            get {
 25                return testContextInstance;
 26            }
 27            set {
 28                testContextInstance = value;
 29            }
 30        }
 31
 32        #region Additional test attributes
 33        // 
 34        //You can use the following additional attributes as you write your tests:
 35        //
 36        //Use ClassInitialize to run code before running the first test in the class
 37        //[ClassInitialize()]
 38        //public static void MyClassInitialize(TestContext testContext)
 39        //{
 40        //}
 41        //
 42        //Use ClassCleanup to run code after all tests in a class have run
 43        //[ClassCleanup()]
 44        //public static void MyClassCleanup()
 45        //{
 46        //}
 47        //
 48        //Use TestInitialize to run code before running each test
 49        //[TestInitialize()]
 50        //public void MyTestInitialize()
 51        //{
 52        //}
 53        //
 54        //Use TestCleanup to run code after each test has run
 55        //[TestCleanup()]
 56        //public void MyTestCleanup()
 57        //{
 58        //}
 59        //
 60        #endregion
 61        #endregion
 62
 63        #region Methods ///////////////////////////////////////////////////////////////////////////
 64
 65        /// <summary>
 66        /// Gets the response_ address.
 67        /// </summary>
 68        [TestMethod]
 69        public void GetResponse_Address() {
 70
 71            GeoRequest request = new GeoRequest("plovdiv bulgaria");
 72            GeoResponse response = request.GetResponse();
 73
 74            GeoLocation actual = response.Results[0].Geometry.Location;
 75            GeoLocation expected = new GeoLocation(42.1438409, 24.7495615);
 76
 77            Assert.AreEqual(expected, actual);
 78        }
 79
 80        /// <summary>
 81        /// Gets the response_ location.
 82        /// </summary>
 83        [TestMethod]
 84        public void GetResponse_Location() {
 85
 86            GeoRequest request = new GeoRequest(42.1438409, 24.7495615);
 87            GeoResponse response = request.GetResponse();
 88
 89            string actual = response.Results[0].FormattedAddress;
 90            string expected = "ul. Gen. Gurko 13, Plovdiv, Bulgaria";
 91
 92            Assert.AreEqual(expected, actual);
 93        }
 94
 95        /// <summary>
 96        /// Test GeoResponse with status <code>OK</code>.
 97        ///</summary>
 98        [TestMethod]
 99        public void GetResponse_Status_OK() {
100
101            GeoRequest target = new GeoRequest("plovdiv bulgaria");
102            GeoResponse actual = target.GetResponse();
103            GeoStatus expected = GeoStatus.OK;
104            Assert.AreEqual(expected, actual.Status);
105        }
106
107        /// <summary>
108        /// Test GeoResponse with status <code>ZERO_RESULTS</code>.
109        /// </summary>
110        [TestMethod]
111        public void GetResponse_Status_ZERO_RESULTS() {
112
113            GeoRequest target = new GeoRequest();
114            GeoStatus actual = target.GetResponse().Status;
115            GeoStatus expected = GeoStatus.ZERO_RESULTS;
116            Assert.AreEqual(expected, actual);
117        }
118
119        /// <summary>
120        /// Gets the response_ with_ street_ address.
121        /// </summary>
122        [TestMethod]
123        public void GetResponse_With_Street_Address() {
124
125            GeoRequest request = new GeoRequest("Alice Springs, Northern Territory, 0870, Australia");
126            GeoResponse response = request.GetResponse();
127
128            Assert.AreEqual(GeoStatus.OK, response.Status);
129
130            request.Address = "4 Cassia Ct, Alice Springs, Northern Territory, 0870, Australia";
131            response = request.GetResponse();
132
133            Assert.AreEqual(GeoStatus.OK, response.Status);
134
135        }
136        #endregion
137    }
138}