Пример #1
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();
        }
Пример #2
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);
        }
Пример #3
0
        public DummyRestServiceTest()
        {
            _httpClient   = new HttpClient();
            _httpEndpoint = new HttpEndpoint();
            _service      = CreateService(_httpEndpoint, ServiceConfig);

            _httpEndpoint.Configure(RestConfig);
            _httpEndpoint.OpenAsync(null).Wait();
        }
Пример #4
0
        private HttpEndpoint CreateLocalEndpoint()
        {
            var endpoint = new HttpEndpoint();

            if (_config != null)
            {
                endpoint.Configure(_config);
            }

            if (_references != null)
            {
                endpoint.SetReferences(_references);
            }

            return(endpoint);
        }
Пример #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);
        }