Пример #1
0
        public async Task ExecuteRemote_CallsRemoteServer_WithSuccess(HttpStatusCode statusCode)
        {
            var client = GetMockClient();

            MockHandler.AddResponse(statusCode);

            var sut = new DeleteOperation("test", "1234")
            {
                Item = testObject
            };
            var result = await sut.ExecuteOperationOnRemoteServiceAsync(client);

            Assert.Null(result);
            Assert.Single(MockHandler.Requests);
            Assert.Equal(HttpMethod.Delete, MockHandler.Requests[0].Method);
            Assert.Equal(new Uri(Endpoint, "/tables/test/1234"), MockHandler.Requests[0].RequestUri);
        }
Пример #2
0
        public async Task ExecuteRemote_ReturnsNull_WhenCancelled()
        {
            var client = GetMockClient();

            MockHandler.AddResponse(HttpStatusCode.OK, new IdEntity {
                Id = "1234", StringValue = "foo"
            });

            var sut = new DeleteOperation("test", "1234")
            {
                Item = testObject
            };

            sut.Cancel();
            var actual = await sut.ExecuteOperationOnRemoteServiceAsync(client);

            Assert.Null(actual);
        }
Пример #3
0
        public async Task ExecuteRemote_WithInternalFailure()
        {
            var table = new Mock <IRemoteTable>();

            table.Setup(x => x.DeleteItemAsync(It.IsAny <JObject>(), It.IsAny <CancellationToken>())).ThrowsAsync(new DatasyncInvalidOperationException());
            var client = new Mock <DatasyncClient>();

            client.Setup(x => x.GetRemoteTable(It.IsAny <string>())).Returns(table.Object);

            var sut = new DeleteOperation("test", "1234")
            {
                Item = testObject
            };
            var exception = await Assert.ThrowsAsync <DatasyncInvalidOperationException>(() => sut.ExecuteOperationOnRemoteServiceAsync(client.Object));
        }
Пример #4
0
        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 DeleteOperation("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);
        }
Пример #5
0
        public async Task ExecuteRemote_ThrowsError_WithNoItem(HttpStatusCode statusCode)
        {
            var client = GetMockClient();

            MockHandler.AddResponse(statusCode);

            var sut       = new DeleteOperation("test", "1234");
            var exception = await Assert.ThrowsAsync <DatasyncInvalidOperationException>(() => sut.ExecuteOperationOnRemoteServiceAsync(client));

            Assert.Empty(MockHandler.Requests);
            Assert.Contains("must have an item", exception.Message);
        }