From 8259fda829acef9b84f754192b5186035eae8fde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20N=C3=A4geli?= Date: Thu, 17 Oct 2024 15:27:22 +0200 Subject: [PATCH] Additional coverage --- .../Modules/OpenApi/IntegrationTests.cs | 20 +++++++++++++ .../Modules/Reflection/ErrorHandlingTests.cs | 30 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 Testing/Acceptance/Modules/Reflection/ErrorHandlingTests.cs diff --git a/Testing/Acceptance/Modules/OpenApi/IntegrationTests.cs b/Testing/Acceptance/Modules/OpenApi/IntegrationTests.cs index 9aa983ce..82672549 100644 --- a/Testing/Acceptance/Modules/OpenApi/IntegrationTests.cs +++ b/Testing/Acceptance/Modules/OpenApi/IntegrationTests.cs @@ -39,6 +39,14 @@ public class MyController } + public class MultipleMethodsController + { + + [ControllerAction(RequestMethod.Get, RequestMethod.Options)] + public int Method() => 42; + + } + #endregion [TestMethod] @@ -89,4 +97,16 @@ public async Task TestObsoleteOperation() Assert.IsTrue(doc.Paths.First().Value.Operations.First().Value.Deprecated); } + [TestMethod] + public async Task TestControllerWithMultipleMethods() + { + var api = Layout.Create() + .AddController("my") + .Add(ApiDescription.Create()); + + var doc = (await api.GetOpenApiAsync()).OpenApiDocument; + + Assert.AreEqual(2, doc.Paths["/my/method/"].Operations.Count); + } + } diff --git a/Testing/Acceptance/Modules/Reflection/ErrorHandlingTests.cs b/Testing/Acceptance/Modules/Reflection/ErrorHandlingTests.cs new file mode 100644 index 00000000..2484cb78 --- /dev/null +++ b/Testing/Acceptance/Modules/Reflection/ErrorHandlingTests.cs @@ -0,0 +1,30 @@ +using System.Net; +using GenHTTP.Api.Protocol; +using GenHTTP.Modules.Conversion; +using GenHTTP.Modules.Functional; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace GenHTTP.Testing.Acceptance.Modules.Reflection; + +[TestClass] +public class ErrorHandlingTests +{ + + [TestMethod] + public async Task TestSerializationNotPossible() + { + var serialization = Serialization.Empty() + .Default(ContentType.AudioMp4); + + var api = Inline.Create() + .Get(() => new HashSet()) + .Serializers(serialization); + + using var host = TestHost.Run(api); + + using var response = await host.GetResponseAsync(); + + await response.AssertStatusAsync(HttpStatusCode.UnsupportedMediaType); + } + +}