예제 #1
0
        public void RequestUriShouldBeBuiltCorrectly()
        {
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK);
            mockResponse.Content = new StringContent(String.Empty);

            var mockHttpMessageHandler = new MockHttpMessageHandler(mockResponse);
            string mockAddress = "http://127.0.0.1:5001";
            string expectedRequestUri = String.Format("{0}/api/v0/commands", mockAddress);

            using (var client = new IpfsClient(new Uri(mockAddress), new HttpClient(mockHttpMessageHandler)))
            {
                client.Commands().Wait();
            }

            Assert.IsTrue(Equals(mockHttpMessageHandler.LastRequest.RequestUri, expectedRequestUri));
        }
        public void RequestUriShouldBeBuiltCorrectly()
        {
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK);

            mockResponse.Content = new StringContent(String.Empty);

            var    mockHttpMessageHandler = new MockHttpMessageHandler(mockResponse);
            string mockAddress            = "http://127.0.0.1:5001";
            string expectedRequestUri     = String.Format("{0}/api/v0/commands", mockAddress);

            using (var client = new IpfsClient(new Uri(mockAddress), new HttpClient(mockHttpMessageHandler)))
            {
                client.Commands().Wait();
            }

            Assert.IsTrue(Equals(mockHttpMessageHandler.LastRequest.RequestUri, expectedRequestUri));
        }
예제 #3
0
        public void ClientShouldThrowIfMethodCalledAfterBeingDisposed()
        {
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK);
            mockResponse.Content = new StringContent(String.Empty);

            var mockHttpMessageHandler = new MockHttpMessageHandler(mockResponse);
            string mockAddress = "http://127.0.0.1:5001";
            var client = new IpfsClient(new Uri(mockAddress), new HttpClient(mockHttpMessageHandler));

            client.Dispose();

            try
            {
                client.Commands().Wait();
            }
            catch (AggregateException ex)
            {
                throw ex.InnerException;
            }
        }
        public void ClientShouldThrowIfMethodCalledAfterBeingDisposed()
        {
            var mockResponse = new HttpResponseMessage(HttpStatusCode.OK);

            mockResponse.Content = new StringContent(String.Empty);

            var    mockHttpMessageHandler = new MockHttpMessageHandler(mockResponse);
            string mockAddress            = "http://127.0.0.1:5001";
            var    client = new IpfsClient(new Uri(mockAddress), new HttpClient(mockHttpMessageHandler));

            client.Dispose();

            try
            {
                client.Commands().Wait();
            }
            catch (AggregateException ex)
            {
                throw ex.InnerException;
            }
        }
        public void ShouldBeAbleToCancelGetRequest()
        {
            try
            {
                var mockResponse = new HttpResponseMessage(HttpStatusCode.OK);
                mockResponse.Content = new StringContent(String.Empty);

                var    mockHttpMessageHandler = new MockHttpMessageHandler(mockResponse, TimeSpan.FromSeconds(5));
                string mockAddress            = "http://127.0.0.1:5001";

                var cts = new CancellationTokenSource();
                using (var client = new IpfsClient(new Uri(mockAddress), new HttpClient(mockHttpMessageHandler)))
                {
                    var task = client.Commands(cts.Token);
                    cts.Cancel();
                    task.Wait();
                    throw new Exception("The operation was not cancelled");
                }
            }
            catch (AggregateException ex) when(ex.InnerException is TaskCanceledException)
            {
                Console.WriteLine("The operation has been canceled properly");
            }
        }