Add TestUnrecognizedResponse Client test

This commit is contained in:
Jordan Brown
2018-09-15 17:30:10 -04:00
parent 06fb98aaca
commit 537805f86d
@@ -44,5 +44,28 @@ namespace Tgstation.Server.Client.Tests
var result = await client.Read<Byond>(Routes.Byond, default).ConfigureAwait(false);
Assert.AreEqual(sample.Version, result.Version);
}
[TestMethod]
public async Task TestUnrecognizedResponse()
{
var sample = new Byond
{
Version = new Version(511, 1385)
};
var fakeJson = "asdfasd <>F#(*)U*#JLI";
var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(fakeJson)
};
var httpClient = new Mock<IHttpClient>();
httpClient.Setup(x => x.SendAsync(It.IsNotNull<HttpRequestMessage>(), It.IsAny<CancellationToken>())).Returns(Task.FromResult(response));
var client = new ApiClient(httpClient.Object, new Uri("http://fake.com"), new ApiHeaders(new ProductHeaderValue("fake"), "fake"));
await Assert.ThrowsExceptionAsync<UnrecognizedResponseException>(() => client.Read<Byond>(Routes.Byond, default)).ConfigureAwait(false);
}
}
}