Skip to content
Permalink
Browse files

Test for #1653 (#1768)

* Test for #1653

* Remove & Ignore .editorconfig
  • Loading branch information...
ili authored and RSuter committed Feb 19, 2019
1 parent 34f7b94 commit d25cfd2884890d69a7faab2d0684259c800fae57
@@ -1,4 +1,4 @@
src/**/bin/**
src/**/bin/**
src/**/obj/**
src/packages/**

@@ -69,3 +69,6 @@ NSwagStudio*.nupkg
/src/.cr/*
/samples/WithMiddleware/Sample.AspNetCore21.Nginx/.vs
/samples/WithMiddleware/Sample.AspNetCore21.Nginx/Properties


.editorconfig
@@ -2,6 +2,7 @@
using Xunit;
using NSwag.SwaggerGeneration.WebApi;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;

namespace NSwag.CodeGeneration.TypeScript.Tests
{
@@ -12,12 +13,52 @@ public class Foo
public string Bar { get; set; }
}

[Route("[controller]/[action]")]
public class DiscussionController : Controller
{
[HttpPost]
public void AddMessage([FromBody]Foo message)
{
}

[HttpPost]
public void GenericRequestTest1(GenericRequest1 request)
{

}

[HttpPost]
public void GenericRequestTest2(GenericRequest2 request)
{

}
}

public class GenericRequestBase<T>
where T : RequestBodyBase
{
[Required]
public T Request { get; set; }
}

public class RequestBodyBase
{

}

public class RequestBody : RequestBodyBase
{

}

public class GenericRequest1 : GenericRequestBase<RequestBodyBase>
{

}

public class GenericRequest2 : GenericRequestBase<RequestBody>
{

}

[Fact]
@@ -95,5 +136,31 @@ public async Task When_export_types_is_false_then_dont_add_export_before_classes
Assert.DoesNotContain("export class DiscussionClient", code);
Assert.DoesNotContain("export interface IDiscussionClient", code);
}

[Fact]
public async Task When_generic_request()
{
//// Arrange
var generator = new WebApiToSwaggerGenerator(new WebApiToSwaggerGeneratorSettings());
var document = await generator.GenerateForControllerAsync<DiscussionController>();
var json = document.ToJson();

//// Act
var codeGen = new SwaggerToTypeScriptClientGenerator(document, new SwaggerToTypeScriptClientGeneratorSettings
{
Template = TypeScriptTemplate.Angular,
GenerateDtoTypes = true,
TypeScriptGeneratorSettings =
{
TypeScriptVersion = 2.7m,
ExportTypes = false
}
});
var code = codeGen.GenerateFile();

//// Assert
Assert.Contains("this.request = new RequestBodyBase()", code);
Assert.Contains("this.request = new RequestBody()", code);
}
}
}
Oops, something went wrong.

0 comments on commit d25cfd2

Please sign in to comment.
You can’t perform that action at this time.