add unit test for OpenApiDocumentGenerator

This commit is contained in:
Sam Xu 2017-11-27 10:22:09 -08:00
parent 265984c888
commit 6a7203d088
6 changed files with 62 additions and 6 deletions

View file

@ -46,11 +46,17 @@ namespace Microsoft.OpenApi.OData.Generator
// It allows defining responses that can be reused across operations of the service.
Responses = context.CreateResponses(),
// Make others as null.
RequestBodies = null,
Examples = null,
SecuritySchemes = null,
Links = null,
Callbacks = null,
Extensions = null
};
}

View file

@ -46,7 +46,11 @@ namespace Microsoft.OpenApi.OData.Generator
Paths = context.CreatePaths(),
Components = context.CreateComponents()
Components = context.CreateComponents(),
SecurityRequirements = null,
ExternalDocs = null
};
}
}

View file

@ -78,7 +78,7 @@ namespace Microsoft.OpenApi.OData.Generator
// TODO: https://github.com/Microsoft/OpenAPI.NET.OData/issues/2
// or the entity container
if (context.Model.EntityContainer != null)
if (context.EntityContainer != null)
{
string longDescription = context.Model.GetLongDescriptionAnnotation(context.Model.EntityContainer);
if (longDescription != null)

View file

@ -36,7 +36,7 @@ namespace Microsoft.OpenApi.OData.Generator
// and it optionally can contain the field description, whose value is the value of the unqualified annotation
// Core.Description of the entity set or singleton.
IList<OpenApiTag> tags = new List<OpenApiTag>();
if (context.Model.EntityContainer != null)
if (context.EntityContainer != null)
{
foreach (IEdmEntityContainerElement element in context.Model.EntityContainer.Elements)
{
@ -81,8 +81,7 @@ namespace Microsoft.OpenApi.OData.Generator
}
}
// Tags is optional.
return tags.Any() ? tags : null;
return tags;
}
private static OpenApiTag CreateOperationImportTag(this ODataContext context, IEdmOperationImport operationImport)

View file

@ -0,0 +1,48 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
using System;
using Microsoft.OData.Edm;
using Microsoft.OpenApi.OData.Tests;
using Xunit;
namespace Microsoft.OpenApi.OData.Generator.Tests
{
public class OpenApiDocumentGeneratorTest
{
[Fact]
public void CreateDocumentThrowArgumentNullContext()
{
// Arrange
ODataContext context = null;
// Act & Assert
Assert.Throws<ArgumentNullException>("context", () => context.CreateDocument());
}
[Fact]
public void CreateDocumentReturnsForEmptyModel()
{
// Arrange
IEdmModel model = EdmModelHelper.EmptyModel;
ODataContext context = new ODataContext(model);
// Act
var document = context.CreateDocument();
// Assert
Assert.NotNull(document);
Assert.Equal("3.0.0", document.SpecVersion.ToString());
Assert.NotNull(document.Info);
Assert.NotNull(document.Tags);
Assert.NotNull(document.Servers);
Assert.NotNull(document.Paths);
Assert.NotNull(document.Components);
Assert.Null(document.ExternalDocs);
Assert.Null(document.SecurityRequirements);
}
}
}

View file

@ -5,7 +5,6 @@
using System;
using System.Linq;
using Microsoft.OData.Edm;
using Microsoft.OpenApi.OData.Tests;
using Xunit;