public async Task GetAsyncShouldReturnNullContentWhenKeyDoesNotExist() { // Arrange var handler = new Mock<HttpMessageHandler>() .WithResponse(HttpStatusCode.NotFound, ""); HttpClient client = new HttpClient(handler.Object) { BaseAddress = new Uri("http://localhost/") }; var ops = new KeyValueOperations(client); // Act var response = await ops.GetAsync("does-not-exist"); // Assert response.StatusCode.Should().Be(HttpStatusCode.NotFound); response.Content.Should().BeEmpty(); }
public async Task GetAsyncShouldReturnContentWhenKeyExists() { // Arrange JToken json = _loader.LoadEmbeddedJson("KeyValueGetSingleKeyResponse"); var handler = new Mock<HttpMessageHandler>() .WithResponse(HttpStatusCode.OK, json); HttpClient client = new HttpClient(handler.Object) { BaseAddress = new Uri("http://localhost/") }; var ops = new KeyValueOperations(client); // Act var response = await ops.GetAllAsync(); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); response.Content.Should().NotBeNull().And.HaveCount(1); }
public async Task GetAsyncShouldReturnNullContentWhenKeyDoesNotExist() { // Arrange var handler = new Mock <HttpMessageHandler>() .WithResponse(HttpStatusCode.NotFound, ""); HttpClient client = new HttpClient(handler.Object) { BaseAddress = new Uri("http://localhost/") }; var ops = new KeyValueOperations(client); // Act var response = await ops.GetAsync("does-not-exist"); // Assert response.StatusCode.Should().Be(HttpStatusCode.NotFound); response.Content.Should().BeEmpty(); }
public async Task GetAsyncShouldReturnContentWhenKeyExists() { // Arrange JToken json = _loader.LoadEmbeddedJson("KeyValueGetSingleKeyResponse"); var handler = new Mock <HttpMessageHandler>() .WithResponse(HttpStatusCode.OK, json); HttpClient client = new HttpClient(handler.Object) { BaseAddress = new Uri("http://localhost/") }; var ops = new KeyValueOperations(client); // Act var response = await ops.GetAllAsync(); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); response.Content.Should().NotBeNull().And.HaveCount(1); }