|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using System;
- # if DEBUG
- using NUnit.Framework;
- #endif
- namespace Leadercraft.Server
- {
- #if DEBUG
- [TestFixture]
- public class Tests
- {
- private static readonly string tokenUrl = "http://192.168.122.229:1337/token";
-
- private static readonly string criteriaUrl = "http://192.168.122.229:7048/criteria";
-
- private LeadercraftApi api;
-
- [SetUp]
- public void SetUp()
- {
- api = new LeadercraftApi(15, tokenUrl, criteriaUrl);
- }
-
- [Test]
- public void TokenIntegrationTest()
- {
- LeadercraftResult<KeyStruct> result = api.RequestPOSTToken();
- Assert.AreEqual(200, result.StatusCode, "Expected HTTP 200 Ok StatusCode");
- ResultStruct<KeyStruct> resultStruct = result.ParseResult();
- Assert.Greater(resultStruct.Items.Length, 0, "Expected a non-zero item count");
- Assert.AreEqual(1, resultStruct.Items.Length, "Expected one result item");
- Assert.IsNotEmpty(resultStruct.Items[0].Token, "Expected a non-empty token string");
- }
-
- [Test]
- public void CriteriaIntegrationTest()
- {
- CriteriaStruct criteria = new CriteriaStruct
- {
- Location = new float[][] { new float[] { 1, 1, 0 }, new float[] { 1, 1, 0 } },
- Time = 42,
- GameID = 2,
- PlayerID = 333,
- Complete = true
- };
- // this may fail when TokenIntegrationTest also fails
- string token = api.RequestPOSTToken().ParseResult().Items[0].Token;
- LeadercraftResult<string> result = api.RequestPOSTCriteria(criteria, token);
- Assert.AreEqual(200, result.StatusCode, "Expected HTTP 200 Ok StatusCode");
- }
-
- [Test]
- public void TokenServiceUnavailableTest()
- {
- api = new LeadercraftApi(13, "http://invalid.exmods.org:1337/token", "http://invalid.exmods.org:7048/criteria");
- LeadercraftResult<KeyStruct> result = api.RequestPOSTToken();
- Assert.True(result.IsError, "No error occured");
- Assert.AreNotEqual(200, result.StatusCode, "Expected StatusCode other than HTTP 200 Ok");
- }
-
- [Test]
- public void CriteriaServiceUnavailableTest()
- {
- api = new LeadercraftApi(13, tokenUrl, "http://invalid.exmods.org:7048/criteria");
- CriteriaStruct criteria = new CriteriaStruct
- {
- Location = new float[][] { new float[] { 1, 1, 0 }, new float[] { 1, 1, 0 } },
- Time = 42,
- GameID = 2,
- PlayerID = 333,
- Complete = true
- };
- // this may fail when TokenIntegrationTest also fails
- string token = api.RequestPOSTToken().ParseResult().Items[0].Token;
- LeadercraftResult<string> result = api.RequestPOSTCriteria(criteria, token);
- Assert.True(result.IsError, "No error occured");
- Assert.AreNotEqual(200, result.StatusCode, "Expected StatusCode other than HTTP 200 Ok");
- }
-
- [Test]
- public void TokenServiceErrorTest()
- {
- api = new LeadercraftApi(13, "http://exmods.org/wpojapowjdpoajd/token", "http://invalid.exmods.org:7048/criteria");
- LeadercraftResult<KeyStruct> result = api.RequestPOSTToken();
- Assert.True(result.IsError, "No error occured");
- Assert.AreNotEqual(200, result.StatusCode, "Expected StatusCode other than HTTP 200 Ok");
- }
-
- [Test]
- public void CriteriaServiceErrorTest()
- {
- api = new LeadercraftApi(13, tokenUrl, "http://google.com/woahdoiwahdoiaw/criteria");
- CriteriaStruct criteria = new CriteriaStruct
- {
- Location = new float[][] { new float[] { 1, 1, 0 }, new float[] { 1, 1, 0 } },
- Time = 42,
- GameID = 2,
- PlayerID = 333,
- Complete = true
- };
- // this may fail when TokenIntegrationTest also fails
- string token = api.RequestPOSTToken().ParseResult().Items[0].Token;
- LeadercraftResult<string> result = api.RequestPOSTCriteria(criteria, token);
- Assert.True(result.IsError, "No error occured");
- Assert.AreNotEqual(200, result.StatusCode, "Expected StatusCode other than HTTP 200 Ok");
- }
- }
- #endif
- }
|