Follow the leader
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

109 lines
4.0KB

  1. using System;
  2. # if DEBUG
  3. using NUnit.Framework;
  4. #endif
  5. namespace Leadercraft.Server
  6. {
  7. #if DEBUG
  8. [TestFixture]
  9. public class Tests
  10. {
  11. private static readonly string tokenUrl = "http://192.168.122.229:1337/token";
  12. private static readonly string criteriaUrl = "http://192.168.122.229:7048/criteria";
  13. private LeadercraftApi api;
  14. [SetUp]
  15. public void SetUp()
  16. {
  17. api = new LeadercraftApi(15, tokenUrl, criteriaUrl);
  18. }
  19. [Test]
  20. public void TokenIntegrationTest()
  21. {
  22. LeadercraftResult<KeyStruct> result = api.RequestPOSTToken();
  23. Assert.AreEqual(200, result.StatusCode, "Expected HTTP 200 Ok StatusCode");
  24. ResultStruct<KeyStruct> resultStruct = result.ParseResult();
  25. Assert.Greater(resultStruct.Items.Length, 0, "Expected a non-zero item count");
  26. Assert.AreEqual(1, resultStruct.Items.Length, "Expected one result item");
  27. Assert.IsNotEmpty(resultStruct.Items[0].Token, "Expected a non-empty token string");
  28. }
  29. [Test]
  30. public void CriteriaIntegrationTest()
  31. {
  32. CriteriaStruct criteria = new CriteriaStruct
  33. {
  34. Location = new float[][] { new float[] { 1, 1, 0 }, new float[] { 1, 1, 0 } },
  35. Time = 42,
  36. GameID = 2,
  37. PlayerID = 333,
  38. Complete = true
  39. };
  40. // this may fail when TokenIntegrationTest also fails
  41. string token = api.RequestPOSTToken().ParseResult().Items[0].Token;
  42. LeadercraftResult<string> result = api.RequestPOSTCriteria(criteria, token);
  43. Assert.AreEqual(200, result.StatusCode, "Expected HTTP 200 Ok StatusCode");
  44. }
  45. [Test]
  46. public void TokenServiceUnavailableTest()
  47. {
  48. api = new LeadercraftApi(13, "http://invalid.exmods.org:1337/token", "http://invalid.exmods.org:7048/criteria");
  49. LeadercraftResult<KeyStruct> result = api.RequestPOSTToken();
  50. Assert.True(result.IsError, "No error occured");
  51. Assert.AreNotEqual(200, result.StatusCode, "Expected StatusCode other than HTTP 200 Ok");
  52. }
  53. [Test]
  54. public void CriteriaServiceUnavailableTest()
  55. {
  56. api = new LeadercraftApi(13, tokenUrl, "http://invalid.exmods.org:7048/criteria");
  57. CriteriaStruct criteria = new CriteriaStruct
  58. {
  59. Location = new float[][] { new float[] { 1, 1, 0 }, new float[] { 1, 1, 0 } },
  60. Time = 42,
  61. GameID = 2,
  62. PlayerID = 333,
  63. Complete = true
  64. };
  65. // this may fail when TokenIntegrationTest also fails
  66. string token = api.RequestPOSTToken().ParseResult().Items[0].Token;
  67. LeadercraftResult<string> result = api.RequestPOSTCriteria(criteria, token);
  68. Assert.True(result.IsError, "No error occured");
  69. Assert.AreNotEqual(200, result.StatusCode, "Expected StatusCode other than HTTP 200 Ok");
  70. }
  71. [Test]
  72. public void TokenServiceErrorTest()
  73. {
  74. api = new LeadercraftApi(13, "http://exmods.org/wpojapowjdpoajd/token", "http://invalid.exmods.org:7048/criteria");
  75. LeadercraftResult<KeyStruct> result = api.RequestPOSTToken();
  76. Assert.True(result.IsError, "No error occured");
  77. Assert.AreNotEqual(200, result.StatusCode, "Expected StatusCode other than HTTP 200 Ok");
  78. }
  79. [Test]
  80. public void CriteriaServiceErrorTest()
  81. {
  82. api = new LeadercraftApi(13, tokenUrl, "http://google.com/woahdoiwahdoiaw/criteria");
  83. CriteriaStruct criteria = new CriteriaStruct
  84. {
  85. Location = new float[][] { new float[] { 1, 1, 0 }, new float[] { 1, 1, 0 } },
  86. Time = 42,
  87. GameID = 2,
  88. PlayerID = 333,
  89. Complete = true
  90. };
  91. // this may fail when TokenIntegrationTest also fails
  92. string token = api.RequestPOSTToken().ParseResult().Items[0].Token;
  93. LeadercraftResult<string> result = api.RequestPOSTCriteria(criteria, token);
  94. Assert.True(result.IsError, "No error occured");
  95. Assert.AreNotEqual(200, result.StatusCode, "Expected StatusCode other than HTTP 200 Ok");
  96. }
  97. }
  98. #endif
  99. }