public async Task TestDeserializingByondModelsWork() { var sample = new Byond { Version = new Version(511, 1385, 0) }; var sampleJson = JsonConvert.SerializeObject(sample, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver(), Converters = new[] { new VersionConverter() } }); var response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(sampleJson) }; 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"), null); var result = await client.Read <Byond>(Routes.Byond, default).ConfigureAwait(false); Assert.AreEqual(sample.Version, result.Version); Assert.AreEqual(0, result.Version.Build); }
/// <inheritdoc /> public async Task <Byond> SetActiveVersion(Byond byond, Stream zipFileStream, CancellationToken cancellationToken) { var result = await ApiClient.Update <Byond, Byond>( Routes.Byond, byond ?? throw new ArgumentNullException(nameof(byond)), instance.Id, cancellationToken) .ConfigureAwait(false); if (byond.UploadCustomZip == true) { await ApiClient.Upload(result, zipFileStream, cancellationToken).ConfigureAwait(false); } return(result); }
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"), null); await Assert.ThrowsExceptionAsync <UnrecognizedResponseException>(() => client.Read <Byond>(Routes.Byond, default)).ConfigureAwait(false); }
/// <inheritdoc /> public Task <Byond> SetActiveVersion(Byond byond, CancellationToken cancellationToken) => apiClient.Update <Byond, Byond>(Routes.Byond, byond ?? throw new ArgumentNullException(nameof(byond)), instance.Id, cancellationToken);
/// <inheritdoc /> public Task <Byond> Update(Byond byond, CancellationToken cancellationToken) => apiClient.Update <Byond, Byond>(Routes.Byond, byond, instance.Id, cancellationToken);