public async Task DeleteItemAsync() { var url = "https://qtb3.com"; HttpRequestMessage sentMessage = null; var httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK); var httpService = new Mock <IHttpWriteService>(); httpService .Setup(s => s.SendAsync(It.IsAny <HttpRequestMessage>())) .ReturnsAsync(httpResponseMessage) .Callback <HttpRequestMessage>((request) => sentMessage = request); var uut = new DeleteItemServiceBuildRequest(httpService.Object); await uut.DeleteItemAsync(url); Assert.AreEqual(HttpMethod.Delete, sentMessage.Method); Assert.AreEqual(url + "/", sentMessage.RequestUri.ToString()); }
public void DeleteItemAsync_InternalServerError() { var url = "https://qtb3.com"; HttpRequestMessage sentMessage = null; var httpResponseMessage = new HttpResponseMessage(HttpStatusCode.InternalServerError); var httpService = new Mock <IHttpWriteService>(); httpService .Setup(s => s.SendAsync(It.IsAny <HttpRequestMessage>())) .ReturnsAsync(httpResponseMessage) .Callback <HttpRequestMessage>((request) => sentMessage = request); var uut = new DeleteItemServiceBuildRequest(httpService.Object); Assert.ThrowsAsync <FailedRequestException>( async() => await uut.DeleteItemAsync(url) ); Assert.AreEqual(HttpMethod.Delete, sentMessage.Method); Assert.AreEqual(url + "/", sentMessage.RequestUri.ToString()); }