public async Task ExecuteRemote_CallsRemoteServer_ThrowsWhenInvalidResponse() { var client = GetMockClient(); MockHandler.AddResponse(HttpStatusCode.OK, new string[] { "test" }); var sut = new InsertOperation("test", "1234") { Item = testObject }; await Assert.ThrowsAsync <DatasyncInvalidOperationException>(() => sut.ExecuteOperationOnRemoteServiceAsync(client)); }
public async Task ExecuteRemote_ReturnsNull_WhenCancelled() { var client = GetMockClient(); MockHandler.AddResponse(HttpStatusCode.OK, new IdEntity { Id = "1234", StringValue = "foo" }); var sut = new InsertOperation("test", "1234") { Item = testObject }; sut.Cancel(); var actual = await sut.ExecuteOperationOnRemoteServiceAsync(client); Assert.Null(actual); }
public async Task ExecuteRemote_CallsRemoteServer_WithSuccess() { var client = GetMockClient(); MockHandler.AddResponse(HttpStatusCode.OK, new IdEntity { Id = "1234", StringValue = "foo" }); var sut = new InsertOperation("test", "1234") { Item = testObject }; await sut.ExecuteOperationOnRemoteServiceAsync(client); Assert.Single(MockHandler.Requests); Assert.Equal(HttpMethod.Post, MockHandler.Requests[0].Method); Assert.Equal(new Uri(Endpoint, "/tables/test"), MockHandler.Requests[0].RequestUri); Assert.Equal(testObject.ToString(Formatting.None), await MockHandler.Requests[0].Content.ReadAsStringAsync()); }
public async Task ExecuteRemote_CallsRemoteServer_WithFailure(HttpStatusCode statusCode) { var client = GetMockClient(); if (statusCode == HttpStatusCode.Conflict || statusCode == HttpStatusCode.PreconditionFailed) { MockHandler.AddResponse(statusCode, new IdEntity { Id = "1234", StringValue = "movie" }); } else { MockHandler.AddResponse(statusCode); } var sut = new InsertOperation("test", "1234") { Item = testObject }; var exception = await Assert.ThrowsAnyAsync <DatasyncInvalidOperationException>(() => sut.ExecuteOperationOnRemoteServiceAsync(client)); if (statusCode == HttpStatusCode.Conflict || statusCode == HttpStatusCode.PreconditionFailed) { Assert.IsAssignableFrom <DatasyncConflictException>(exception); Assert.NotNull(exception.Value); } Assert.NotNull(exception.Request); Assert.NotNull(exception.Response); Assert.Equal(statusCode, exception.Response?.StatusCode); }
public async Task ExecuteRemote_ThrowsError_WithNoItem() { var client = GetMockClient(); MockHandler.AddResponse(HttpStatusCode.OK); var sut = new InsertOperation("test", "1234"); var exception = await Assert.ThrowsAsync <DatasyncInvalidOperationException>(() => sut.ExecuteOperationOnRemoteServiceAsync(client)); Assert.Empty(MockHandler.Requests); Assert.Contains("must have an item", exception.Message); }