Permalink
Browse files

Migrate to use Xunit (#1669)

* Migrate to use Xunit

* Migrate ts tests

* Migrate another project, fix build script

* Add more sdk projects to min
  • Loading branch information...
RSuter committed Nov 1, 2018
1 parent 74b41b3 commit d7e1d74a20f932bfa8a0df9bf6a2ac0e1a535307
Showing with 476 additions and 957 deletions.
  1. +5 −5 build/02_RunUnitTests.bat
  2. +3 −7 src/NSwag.CodeGeneration.CSharp.Tests/ArrayParameterTests.cs
  3. +13 −14 src/NSwag.CodeGeneration.CSharp.Tests/CSharpClientSettingsTests.cs
  4. +37 −35 src/NSwag.CodeGeneration.CSharp.Tests/ControllerGenerationFormatTests.cs
  5. +15 −19 src/NSwag.CodeGeneration.CSharp.Tests/Controllers/ControllerGenerationDefaultParameterTests.cs
  6. +9 −10 src/NSwag.CodeGeneration.CSharp.Tests/FileDownloadTests.cs
  7. +21 −19 src/NSwag.CodeGeneration.CSharp.Tests/FormParameterTests.cs
  8. +5 −6 src/NSwag.CodeGeneration.CSharp.Tests/HeadRequestTests.cs
  9. +12 −120 src/NSwag.CodeGeneration.CSharp.Tests/NSwag.CodeGeneration.CSharp.Tests.csproj
  10. +18 −18 src/NSwag.CodeGeneration.CSharp.Tests/OptionalParameterTests.cs
  11. +12 −14 src/NSwag.CodeGeneration.CSharp.Tests/ParameterTests.cs
  12. +0 −36 src/NSwag.CodeGeneration.CSharp.Tests/Properties/AssemblyInfo.cs
  13. +17 −22 src/NSwag.CodeGeneration.CSharp.Tests/UseCancellationTokenTests.cs
  14. +9 −10 src/NSwag.CodeGeneration.CSharp.Tests/WrapResponsesTests.cs
  15. +12 −13 src/NSwag.CodeGeneration.Tests/CodeGenerationTests.cs
  16. +10 −280 src/NSwag.CodeGeneration.Tests/NSwag.CodeGeneration.Tests.csproj
  17. +0 −36 src/NSwag.CodeGeneration.Tests/Properties/AssemblyInfo.cs
  18. +9 −10 src/NSwag.CodeGeneration.TypeScript.Tests/AngularJSTests.cs
  19. +11 −12 src/NSwag.CodeGeneration.TypeScript.Tests/AngularTests.cs
  20. +3 −6 src/NSwag.CodeGeneration.TypeScript.Tests/ArrayParameterTests.cs
  21. +9 −10 src/NSwag.CodeGeneration.TypeScript.Tests/FetchTests.cs
  22. +9 −9 src/NSwag.CodeGeneration.TypeScript.Tests/JQueryCallbacksTests.cs
  23. +9 −9 src/NSwag.CodeGeneration.TypeScript.Tests/JQueryPromisesTests.cs
  24. +14 −179 src/NSwag.CodeGeneration.TypeScript.Tests/NSwag.CodeGeneration.TypeScript.Tests.csproj
  25. +10 −8 src/NSwag.CodeGeneration.TypeScript.Tests/OperationParameterTests.cs
  26. +0 −36 src/NSwag.CodeGeneration.TypeScript.Tests/Properties/AssemblyInfo.cs
  27. +4 −5 src/NSwag.CodeGeneration.TypeScript.Tests/TypeScriptOperationParameterTests.cs
  28. +192 −1 src/NSwag.Min.sln
  29. +8 −8 src/NSwag.sln
@@ -1,9 +1,9 @@
vstest.console /logger:Appveyor "%~dp0../src/NSwag.CodeGeneration.CSharp.Tests/bin/Release/NSwag.CodeGeneration.CSharp.Tests.dll" || goto :error
vstest.console /logger:Appveyor "%~dp0../src\NSwag.CodeGeneration.Tests\bin/Release\NSwag.CodeGeneration.Tests.dll" || goto :error
vstest.console /logger:Appveyor "%~dp0../src\NSwag.CodeGeneration.TypeScript.Tests\bin/Release\NSwag.CodeGeneration.TypeScript.Tests.dll" || goto :error
vstest.console /logger:Appveyor "%~dp0../src\NSwag.SwaggerGeneration.WebApi.Tests\bin/Release/NSwag.SwaggerGeneration.WebApi.Tests.dll" || goto :error
vstest.console /logger:Appveyor "%~dp0../src\NSwag.Tests\bin/Release/NSwag.Tests.dll" || goto :error
vstest.console /logger:Appveyor "%~dp0../src/NSwag.SwaggerGeneration.WebApi.Tests/bin/Release/NSwag.SwaggerGeneration.WebApi.Tests.dll" || goto :error
vstest.console /logger:Appveyor "%~dp0../src/NSwag.Tests/bin/Release/NSwag.Tests.dll" || goto :error
dotnet test "%~dp0/../src/NSwag.CodeGeneration.Tests/NSwag.CodeGeneration.Tests.csproj" -c Release || goto :error
dotnet test "%~dp0/../src/NSwag.CodeGeneration.CSharp.Tests/NSwag.CodeGeneration.CSharp.Tests.csproj" -c Release || goto :error
dotnet test "%~dp0/../src/NSwag.CodeGeneration.TypeScript.Tests/NSwag.CodeGeneration.TypeScript.Tests.csproj" -c Release || goto :error
dotnet test "%~dp0/../src/NSwag.SwaggerGeneration.AspNetCore.Tests/NSwag.SwaggerGeneration.AspNetCore.Tests.csproj" -c Release || goto :error
dotnet test "%~dp0/../src/NSwag.Core.Tests/NSwag.Core.Tests.csproj" -c Release || goto :error
dotnet test "%~dp0/../src/NSwag.Core.Yaml.Tests/NSwag.Core.Yaml.Tests.csproj" -c Release || goto :error
@@ -1,12 +1,11 @@
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xunit;
namespace NSwag.CodeGeneration.CSharp.Tests
{
[TestClass]
public class ArrayParameterTests
{
[TestMethod]
[Fact]
public async Task When_parameter_is_array_then_CSharp_is_correct()
{
//// Arrange
@@ -67,10 +66,7 @@ public async Task When_parameter_is_array_then_CSharp_is_correct()
var code = generator.GenerateFile();
//// Assert
Assert.IsTrue(
code.Contains(
@"foreach (var item_ in elementId) { urlBuilder_.Append(""elementId="").Append(System.Uri.EscapeDataString(ConvertToString(item_, System.Globalization.CultureInfo.InvariantCulture))).Append(""&""); }"));
Assert.Contains(@"foreach (var item_ in elementId) { urlBuilder_.Append(""elementId="").Append(System.Uri.EscapeDataString(ConvertToString(item_, System.Globalization.CultureInfo.InvariantCulture))).Append(""&""); }", code);
}
}
}
@@ -1,22 +1,21 @@
using System.Threading.Tasks;
using System.Web.Http;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.AspNetCore.Mvc;
using NSwag.SwaggerGeneration.WebApi;
using Xunit;
namespace NSwag.CodeGeneration.CSharp.Tests
{
[TestClass]
public class CSharpClientSettingsTests
{
public class FooController : ApiController
public class FooController : Controller
{
public object GetPerson(bool @override = false)
{
return null;
}
}
[TestMethod]
[Fact]
public async Task When_ConfigurationClass_is_set_then_correct_ctor_is_generated()
{
//// Arrange
@@ -33,10 +32,10 @@ public async Task When_ConfigurationClass_is_set_then_correct_ctor_is_generated(
var code = generator.GenerateFile();
//// Assert
Assert.IsTrue(code.Contains("public FooClient(MyConfig configuration) : base(configuration)"));
Assert.Contains("public FooClient(MyConfig configuration) : base(configuration)", code);
}
[TestMethod]
[Fact]
public async Task When_UseHttpRequestMessageCreationMethod_is_set_then_CreateRequestMessage_is_generated()
{
//// Arrange
@@ -54,10 +53,10 @@ public async Task When_UseHttpRequestMessageCreationMethod_is_set_then_CreateReq
var code = generator.GenerateFile();
//// Assert
Assert.IsTrue(code.Contains("var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)"));
Assert.Contains("var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)", code);
}
[TestMethod]
[Fact]
public async Task When_parameter_name_is_reserved_keyword_then_it_is_appended_with_at()
{
//// Arrange
@@ -70,10 +69,10 @@ public async Task When_parameter_name_is_reserved_keyword_then_it_is_appended_wi
var code = generator.GenerateFile();
//// Assert
Assert.IsTrue(code.Contains("Task<object> GetPersonAsync(bool? @override, "));
Assert.Contains("Task<object> GetPersonAsync(bool? @override, ", code);
}
[TestMethod]
[Fact]
public async Task When_code_is_generated_then_by_default_the_system_httpclient_is_used()
{
//// Arrange
@@ -86,10 +85,10 @@ public async Task When_code_is_generated_then_by_default_the_system_httpclient_i
var code = generator.GenerateFile();
//// Assert
Assert.IsTrue(code.Contains("var client_ = new System.Net.Http.HttpClient();"));
Assert.Contains("var client_ = new System.Net.Http.HttpClient();", code);
}
[TestMethod]
[Fact]
public async Task When_custom_http_client_type_is_specified_then_an_instance_of_that_type_is_used()
{
//// Arrange
@@ -105,7 +104,7 @@ public async Task When_custom_http_client_type_is_specified_then_an_instance_of_
var code = generator.GenerateFile();
//// Assert
Assert.IsTrue(code.Contains("var client_ = new CustomNamespace.CustomHttpClient();"));
Assert.Contains("var client_ = new CustomNamespace.CustomHttpClient();", code);
}
}
}
@@ -1,24 +1,26 @@
using System;
using System.Threading.Tasks;
using System.Web.Http;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.AspNetCore.Mvc;
using NSwag.CodeGeneration.CSharp.Models;
using NSwag.SwaggerGeneration.WebApi;
using Xunit;
namespace NSwag.CodeGeneration.CSharp.Tests
{
[TestClass]
public class ControllerGenerationFormatTests
{
public class ComplexType
{
public string Prop1 { get; set; }
public int Prop2 { get; set; }
public bool Prop3 { get; set; }
public ComplexType Prop4 { get; set; }
}
public class TestController : ApiController
public class TestController : Controller
{
[Route("Foo")]
public string Foo(string test, bool test2)
@@ -39,7 +41,7 @@ public void Complex([FromBody] ComplexType complexType)
}
}
[TestMethod]
[Fact]
public async Task When_controllergenerationformat_abstract_then_abstractcontroller_is_generated()
{
//// Arrange
@@ -54,13 +56,13 @@ public async Task When_controllergenerationformat_abstract_then_abstractcontroll
var code = codeGen.GenerateFile();
//// Assert
Assert.IsTrue(code.Contains("abstract class TestController"));
Assert.IsFalse(code.Contains("ITestController"));
Assert.IsFalse(code.Contains("private ITestController _implementation;"));
Assert.IsFalse(code.Contains("partial class TestController"));
Assert.Contains("abstract class TestController", code);
Assert.DoesNotContain("ITestController", code);
Assert.DoesNotContain("private ITestController _implementation;", code);
Assert.DoesNotContain("partial class TestController", code);
}
[TestMethod]
[Fact]
public async Task When_controllergenerationformat_abstract_then_partialcontroller_is_generated()
{
//// Arrange
@@ -75,13 +77,13 @@ public async Task When_controllergenerationformat_abstract_then_partialcontrolle
var code = codeGen.GenerateFile();
//// Assert
Assert.IsTrue(code.Contains("partial class TestController"));
Assert.IsTrue(code.Contains("ITestController"));
Assert.IsTrue(code.Contains("private ITestController _implementation;"));
Assert.IsFalse(code.Contains("abstract class TestController"));
Assert.Contains("partial class TestController", code);
Assert.Contains("ITestController", code);
Assert.Contains("private ITestController _implementation;", code);
Assert.DoesNotContain("abstract class TestController", code);
}
[TestMethod]
[Fact]
public async Task When_controllergenerationformat_notsetted_then_partialcontroller_is_generated()
{
//// Arrange
@@ -95,13 +97,13 @@ public async Task When_controllergenerationformat_notsetted_then_partialcontroll
var code = codeGen.GenerateFile();
//// Assert
Assert.IsTrue(code.Contains("partial class TestController"));
Assert.IsTrue(code.Contains("ITestController"));
Assert.IsTrue(code.Contains("private ITestController _implementation;"));
Assert.IsFalse(code.Contains("abstract class TestController"));
Assert.Contains("partial class TestController", code);
Assert.Contains("ITestController", code);
Assert.Contains("private ITestController _implementation;", code);
Assert.DoesNotContain("abstract class TestController", code);
}
[TestMethod]
[Fact]
public async Task When_controller_has_operation_with_complextype_then_partialcontroller_is_generated_with_frombody_attribute()
{
//// Arrange
@@ -117,13 +119,13 @@ public async Task When_controller_has_operation_with_complextype_then_partialcon
var code = codeGen.GenerateFile();
//// Assert
Assert.IsTrue(code.Contains("partial class TestController"));
Assert.IsTrue(code.Contains($"Complex([{settings.AspNetNamespace}.FromBody] ComplexType complexType)"));
Assert.IsTrue(code.Contains("Foo(string test, bool test2)"));
Assert.IsTrue(code.Contains("Bar()"));
Assert.Contains("partial class TestController", code);
Assert.Contains($"Complex([{settings.AspNetNamespace}.FromBody] ComplexType complexType)", code);
Assert.Contains("Foo(string test, bool test2)", code);
Assert.Contains("Bar()", code);
}
[TestMethod]
[Fact]
public async Task When_controller_has_operation_with_complextype_then_abstractcontroller_is_generated_with_frombody_attribute()
{
//// Arrange
@@ -140,13 +142,13 @@ public async Task When_controller_has_operation_with_complextype_then_abstractco
var code = codeGen.GenerateFile();
//// Assert
Assert.IsTrue(code.Contains("abstract class TestController"));
Assert.IsTrue(code.Contains($"Complex([{settings.AspNetNamespace}.FromBody] ComplexType complexType)"));
Assert.IsTrue(code.Contains("Foo(string test, bool test2)"));
Assert.IsTrue(code.Contains("Bar()"));
Assert.Contains("abstract class TestController", code);
Assert.Contains($"Complex([{settings.AspNetNamespace}.FromBody] ComplexType complexType)", code);
Assert.Contains("Foo(string test, bool test2)", code);
Assert.Contains("Bar()", code);
}
[TestMethod]
[Fact]
public async Task When_controllerroutenamingstrategy_operationid_then_route_attribute_name_specified()
{
//// Arrange
@@ -162,11 +164,11 @@ public async Task When_controllerroutenamingstrategy_operationid_then_route_attr
var code = codeGen.GenerateFile();
//// Assert
Assert.IsTrue(code.Contains("Route(\"Foo\", Name = \"Test_Foo\")"));
Assert.IsTrue(code.Contains("Route(\"Bar\", Name = \"Test_Bar\")"));
Assert.Contains("Route(\"Foo\", Name = \"Test_Foo\")", code);
Assert.Contains("Route(\"Bar\", Name = \"Test_Bar\")", code);
}
[TestMethod]
[Fact]
public async Task When_controllerroutenamingstrategy_none_then_route_attribute_name_not_specified()
{
//// Arrange
@@ -182,8 +184,8 @@ public async Task When_controllerroutenamingstrategy_none_then_route_attribute_n
var code = codeGen.GenerateFile();
//// Assert
Assert.IsTrue(code.Contains("Route(\"Foo\")"));
Assert.IsTrue(code.Contains("Route(\"Bar\")"));
Assert.Contains("Route(\"Foo\")", code);
Assert.Contains("Route(\"Bar\")", code);
}
}
}
@@ -1,16 +1,12 @@
using System;
using System.CodeDom.Compiler;
using System.Text.RegularExpressions;
using Microsoft.CSharp;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Text.RegularExpressions;
using NJsonSchema;
using Xunit;
namespace NSwag.CodeGeneration.CSharp.Tests.Controllers
{
[TestClass]
public class ControllerGenerationDefaultParameterTests
{
[TestMethod]
[Fact]
public void When_parameter_has_default_then_set_in_partial_controller()
{
//// Arrange
@@ -82,23 +78,23 @@ public void When_parameter_has_default_then_set_in_partial_controller()
var code = generator.GenerateFile();
//// Assert
Assert.IsTrue(code.Contains("_implementation.BarAsync(abc, booldef ?? true, intdef ?? 42, doubledef ?? 0.6822871999174D, decdef ?? 79228162514264337593543950335M, strdef ?? \"default\\\"string\\\"\", bar)"));
Assert.IsTrue(code.Contains("BarAsync(int abc, bool booldef, int intdef, double doubledef, decimal decdef, string strdef, int? bar = null);"));
Assert.Contains("_implementation.BarAsync(abc, booldef ?? true, intdef ?? 42, doubledef ?? 0.6822871999174D, decdef ?? 79228162514264337593543950335M, strdef ?? \"default\\\"string\\\"\", bar)", code);
Assert.Contains("BarAsync(int abc, bool booldef, int intdef, double doubledef, decimal decdef, string strdef, int? bar = null);", code);
var trimmedCode = RemoveExternalReferences(code);
CompilerParameters parameters = new CompilerParameters { GenerateInMemory = true };
//CompilerParameters parameters = new CompilerParameters { GenerateInMemory = true };
var result = new CSharpCodeProvider().CompileAssemblyFromSource(parameters, trimmedCode);
if (result.Errors.Count > 0)
{
foreach (var error in result.Errors)
{
Console.WriteLine(error.ToString());
}
}
//var result = new CSharpCodeProvider().CompileAssemblyFromSource(parameters, trimmedCode);
//if (result.Errors.Count > 0)
//{
// foreach (var error in result.Errors)
// {
// Console.WriteLine(error.ToString());
// }
//}
Assert.IsTrue(result.Errors.Count == 0);
//Assert.True(result.Errors.Count == 0);
}
private static string RemoveExternalReferences(string code)
Oops, something went wrong.

0 comments on commit d7e1d74

Please sign in to comment.