Ejemplo n.º 1
0
        /// <summary>
        /// Opens the component.
        /// </summary>
        /// <param name="correlationId">(optional) transaction id to trace execution through call chain.</param>
        /// <returns></returns>
        public async virtual Task OpenAsync(string correlationId)
        {
            if (IsOpen())
            {
                return;
            }

            if (_endpoint == null)
            {
                _endpoint = CreateLocalEndpoint();
                _endpoint.Register(this);
                _localEndpoint = true;
            }

            if (_localEndpoint)
            {
                await _endpoint.OpenAsync(correlationId).ContinueWith(task =>
                {
                    _opened = task.Exception == null;
                });
            }
            else
            {
                _opened = true;
            }
        }
Ejemplo n.º 2
0
        public DummyHttpEndpointTest()
        {
            _ctrl      = new DummyController();
            _serviceV1 = new DummyCommandableHttpService();
            _serviceV2 = new DummyCommandableHttpService();

            _httpEndpoint = new HttpEndpoint();

            var references = References.FromTuples(
                new Descriptor("pip-services3-dummies", "controller", "default", "default", "1.0"), _ctrl,
                new Descriptor("pip-services3", "endpoint", "http", "default", "1.0"), _httpEndpoint
                );

            _serviceV1.Configure(ConfigParams.FromTuples(
                                     "base_route", "/api/v1/dummy"
                                     ));

            _serviceV2.Configure(ConfigParams.FromTuples(
                                     "base_route", "/api/v2/dummy"
                                     ));

            _httpEndpoint.Configure(RestConfig);

            _serviceV1.SetReferences(references);
            _serviceV2.SetReferences(references);

            _httpEndpoint.OpenAsync(null).Wait();
        }
Ejemplo n.º 3
0
        public async Task It_Should_Return_OpenApi_FileAsync()
        {
            // create temp file
            var openApiContent = "swagger yaml content from file";
            var fileName       = Path.GetTempFileName();

            File.WriteAllText(fileName, openApiContent);

            // recreate service with new configuration
            await _httpEndpoint.CloseAsync(null);

            await _service.CloseAsync(null);

            _httpEndpoint = new HttpEndpoint();
            _service      = CreateService(_httpEndpoint, ConfigParams.FromTuples(
                                              "base_route", "/api/v1",
                                              "openapi_file", fileName, // for test only
                                              "swagger.enable", "true"
                                              ));

            _httpEndpoint.Configure(RestConfig);
            await _httpEndpoint.OpenAsync(null);

            var result = await SendRequestAsync("get", "/api/v1/swagger", new { });

            Assert.Equal(openApiContent, result);

            File.Delete(fileName);
        }
Ejemplo n.º 4
0
        public DummyRestServiceTest()
        {
            _httpClient   = new HttpClient();
            _httpEndpoint = new HttpEndpoint();
            _service      = CreateService(_httpEndpoint, ServiceConfig);

            _httpEndpoint.Configure(RestConfig);
            _httpEndpoint.OpenAsync(null).Wait();
        }
Ejemplo n.º 5
0
        public async Task It_Should_Return_OpenApi_ResourceAsync()
        {
            var openApiContent = "swagger yaml content from resource";

            // recreate service with new configuration
            await _httpEndpoint.CloseAsync(null);

            await _service.CloseAsync(null);

            _httpEndpoint = new HttpEndpoint();
            _service      = CreateService(_httpEndpoint, ConfigParams.FromTuples(
                                              "base_route", "/api/v1",
                                              "openapi_resource", "DummyRestServiceSwagger.yaml", // for test only
                                              "swagger.enable", "true"
                                              ));

            _httpEndpoint.Configure(RestConfig);
            await _httpEndpoint.OpenAsync(null);

            var result = await SendRequestAsync("get", "/api/v1/swagger", new { });

            Assert.Equal(openApiContent, result);
        }