public void ResolvableServiceClient_GetProducts()
        {
            const string productId = "008f6f44-9cce-4358-82f0-c7a26675f2b9";

            var restClient             = new RestClient.RestClient();
            var serviceDiscoveryClient = GetServiceDiscoveryClient();

            var serviceClient = new ResolvableServiceClient("products", "v1", serviceDiscoveryClient, restClient);

            var request = new RestRequest()
                          .AddUrlSegment(productId)
                          .AddToken(Token);

            var response = serviceClient.Get <GetProductResponse>(request);

            var result = response;
        }
Ejemplo n.º 2
0
        public void ResolvableServiceClient_Get()
        {
            var serviceDiscoveryClientMock = new Mock <IServiceDiscoveryClient>();

            serviceDiscoveryClientMock.Setup(x => x.GetServiceUrl(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns("http://localhost");

            var httpResponse = new HttpResponse <GetProductResponse>()
            {
                Content = new GetProductResponse
                {
                    Product = new ReadProduct
                    {
                        Id = "TestId"
                    }
                },
                StatusCode = System.Net.HttpStatusCode.OK
            };

            var restClientMock = new Mock <IRestClient>();

            restClientMock.Setup(x => x.Get <GetProductResponse>(It.IsAny <RestRequest>()))
            .Returns(Task.FromResult(httpResponse));

            var resolvableServiceClient = new ResolvableServiceClient(null, null, serviceDiscoveryClientMock.Object, restClientMock.Object);

            var request = new RestRequest();

            var response = resolvableServiceClient.Get <GetProductResponse>(request);

            Assert.IsNotNull(response);
            Assert.AreEqual(response.StatusCode, System.Net.HttpStatusCode.OK);
            Assert.IsNotNull(response.Content);
            Assert.IsNotNull(response.Content.Product);
            Assert.AreEqual(response.Content.Product.Id, "TestId");
        }