Example #1
0
        protected IDeleteItemService <TItem> BuildDeleteItemService <TItem>(IComponentContext context)
        {
            var httpService = BuildWriteHttpService(context);
            var deleteItemServiceBuildRequest = new DeleteItemServiceBuildRequest(httpService);
            var itemUrlBuilder            = context.Resolve <IItemWriteUrlBuilder <TItem> >();
            var deleteItemServiceBuildUrl = new DeleteItemServiceBuildUrl <TItem>(itemUrlBuilder, deleteItemServiceBuildRequest);

            return(new DeleteItemService <TItem>(deleteItemServiceBuildUrl));
        }
        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());
        }