Skip to content

Commit

Permalink
More tests for OpenApiAnyFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
domaindrivendev committed Mar 14, 2019
1 parent a3ac584 commit 4caddac
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 36 deletions.

This file was deleted.

@@ -0,0 +1,25 @@
using System.Runtime.Serialization;

namespace Swashbuckle.AspNetCore.SwaggerGen.Test
{
public enum ShortEnum:short
{
Value2 = 2,
Value4 = 4,
Value8 = 8,
}

public enum IntEnum:int
{
Value2 = 2,
Value4 = 4,
Value8 = 8,
}

public enum LongEnum:long
{
Value2 = 2,
Value4 = 4,
Value8 = 8,
}
}

This file was deleted.

This file was deleted.

@@ -0,0 +1,35 @@
using System;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Xunit;

namespace Swashbuckle.AspNetCore.SwaggerGen.Test
{
public class OpenApiAnyFactoryTests
{
[Theory]
[InlineData("boolean", null, true, typeof(OpenApiBoolean))]
[InlineData("integer", "int32", (short)10, typeof(OpenApiInteger))]
[InlineData("integer", "int32", ShortEnum.Value2, typeof(OpenApiInteger))]
[InlineData("integer", "int32", 10, typeof(OpenApiInteger))]
[InlineData("integer", "int32", IntEnum.Value2, typeof(OpenApiInteger))]
[InlineData("integer", "int64", 4294967295L, typeof(OpenApiLong))]
[InlineData("number", "float", 1.2F, typeof(OpenApiFloat))]
[InlineData("number", "double", 1.25D, typeof(OpenApiDouble))]
[InlineData("string", "uuid", "d3966535-2637-48fa-b911-e3c27405ee09", typeof(OpenApiString))]
[InlineData("string", null, "foobar", typeof(OpenApiString))]
public void TryCreateFor_CreatesAnInstance_ForProvidedSchemaAndValue(
string schemaType,
string schemaFormat,
object value,
Type expectedInstanceType)
{
var schema = new OpenApiSchema { Type = schemaType, Format = schemaFormat };

OpenApiAnyFactory.TryCreateFor(schema, value, out IOpenApiAny instance);

Assert.NotNull(instance);
Assert.IsType(expectedInstanceType, instance);
}
}
}
Expand Up @@ -6,8 +6,6 @@
using Newtonsoft.Json;
using Xunit;
using Swashbuckle.AspNetCore.Swagger;
using Microsoft.Extensions.Options;
using Microsoft.AspNetCore.Mvc;

namespace Swashbuckle.AspNetCore.SwaggerGen.Test
{
Expand Down
Expand Up @@ -90,6 +90,7 @@ public void GenerateSchema_GeneratesFileSchema_IfFormFileOrFileResultType(Type t
[InlineData(typeof(IntEnum), "IntEnum", "integer", "int32", 3)]
[InlineData(typeof(LongEnum), "LongEnum", "integer", "int64", 3)]
[InlineData(typeof(IntEnum?), "IntEnum", "integer", "int32", 3)]
[InlineData(typeof(IntEnum?), "IntEnum", "integer", "int32", 3)]
public void GenerateSchema_GeneratesEnumSchema_IfEnumType(
Type type,
string expectedSchemaId,
Expand Down

0 comments on commit 4caddac

Please sign in to comment.