leadercraft/Leadercraft/Server/Tests.cs

108 lines
4 KiB
C#

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
}