예제 #1
0
        public void Can_Write_ServiceApiDescription_To_Json()
        {
            var apiDescription = new ApiDescriptionBuilder().Build();
            var json           = JsonConvert.SerializeObject(apiDescription, new OpenApiDocumentJsonConverter());

            var newApiDescription = ServiceApiDescription.ReadFromJson(json);

            newApiDescription.Should().NotBeNull();
            newApiDescription.ServiceId.Should().Be("Api1");
            newApiDescription.ApiDocument.Should().NotBeNull();
            newApiDescription.ApiDocument.Info.Should().NotBeNull();
            newApiDescription.ApiDocument.Info.Title.Should().Be("My Api");
        }
예제 #2
0
        public void Can_Read_ServiceApiDescription_From_Json()
        {
            var json = new ApiDocumentBuilder().BuildAsString();

            json = $"{{\"serviceId\": \"Api1\", \"apiDocument\": {json} }}";

            var apiDescription = ServiceApiDescription.ReadFromJson(json);

            apiDescription.Should().NotBeNull();
            apiDescription.ServiceId.Should().Be("Api1");
            apiDescription.ApiDocument.Should().NotBeNull();
            apiDescription.ApiDocument.Info.Should().NotBeNull();
            apiDescription.ApiDocument.Info.Title.Should().Be("My Api");
        }
            public async Task Returns_Registered_Api_By_Id()
            {
                var responseMessage = await _client.GetAsync("/v1/api/Api2");

                responseMessage.StatusCode.Should().Be(HttpStatusCode.OK);

                var content = await responseMessage.Content.ReadAsStringAsync();

                content.Should().NotBeNullOrWhiteSpace();
                var api = ServiceApiDescription.ReadFromJson(content);

                api.ServiceId.Should().Be("Api2");
                api.ApiDocument.Should().NotBeNull();
                api.ApiDocument.Info.Should().NotBeNull();
                api.ApiDocument.Info.Title.Should().Be("My Api");
            }
            public async Task Publishes_An_Api_Description()
            {
                var requestMessage = new HttpRequestMessage(new HttpMethod("POST"), "/v1/api/api1");

                requestMessage.Content = new ApiDocumentBuilder().BuildAsContent();
                var responseMessage = await _client.SendAsync(requestMessage);

                responseMessage.StatusCode.Should().Be(HttpStatusCode.OK);

                // check weather service was registred and is now listed
                responseMessage = await _client.GetAsync("/v1/api/api1");

                responseMessage.StatusCode.Should().Be(HttpStatusCode.OK);

                var content = await responseMessage.Content.ReadAsStringAsync();

                content.Should().NotBeNullOrWhiteSpace();
                var apiDescription = ServiceApiDescription.ReadFromJson(content);

                apiDescription.Should().NotBeNull();
                apiDescription.ApiDocument.Should().NotBeNull();
                apiDescription.ApiDocument.Info.Should().NotBeNull();
                apiDescription.ApiDocument.Info.Title.Should().Be("My Api");
            }