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