Skip to content

Commit d9e420b

Browse files
Remove functionality that controllers do not serialize data
1 parent 23a25df commit d9e420b

File tree

2 files changed

+20
-53
lines changed

2 files changed

+20
-53
lines changed

Modules/Reflection/ResponseProvider.cs

+20-20
Original file line numberDiff line numberDiff line change
@@ -94,30 +94,30 @@ public ResponseProvider(SerializationRegistry? serialization)
9494
return downloadResponse;
9595
}
9696

97-
if (Serialization is not null)
97+
// basic types should produce a string value
98+
if (type == typeof(DateOnly))
9899
{
99-
// basic types should produce a string value
100-
if (type == typeof(DateOnly))
101-
{
102-
var date = (DateOnly)result;
100+
var date = (DateOnly)result;
103101

104-
return request.Respond()
105-
.Content(date.ToString("yyyy-MM-dd"))
106-
.Type(ContentType.TextPlain)
107-
.Adjust(adjustments)
108-
.Build();
109-
}
102+
return request.Respond()
103+
.Content(date.ToString("yyyy-MM-dd"))
104+
.Type(ContentType.TextPlain)
105+
.Adjust(adjustments)
106+
.Build();
107+
}
110108

111-
if (type.IsPrimitive || type == typeof(string) || type.IsEnum || type == typeof(Guid))
112-
{
113-
return request.Respond()
114-
.Content(result.ToString() ?? string.Empty)
115-
.Type(ContentType.TextPlain)
116-
.Adjust(adjustments)
117-
.Build();
118-
}
109+
if (type.IsPrimitive || type == typeof(string) || type.IsEnum || type == typeof(Guid))
110+
{
111+
return request.Respond()
112+
.Content(result.ToString() ?? string.Empty)
113+
.Type(ContentType.TextPlain)
114+
.Adjust(adjustments)
115+
.Build();
116+
}
119117

120-
// serialize the result
118+
// serialize the result
119+
if (Serialization is not null)
120+
{
121121
var serializer = Serialization.GetSerialization(request);
122122

123123
if (serializer is null)
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
using System;
2-
using System.Net;
3-
using System.Net.Http;
4-
using System.Threading.Tasks;
52

63
using Microsoft.VisualStudio.TestTools.UnitTesting;
74

85
using GenHTTP.Modules.Controllers;
9-
using GenHTTP.Modules.Layouting;
106

117
namespace GenHTTP.Testing.Acceptance.Modules.Controllers
128
{
@@ -17,13 +13,6 @@ public sealed class ErrorHandlingTests
1713

1814
#region Supporting data structures
1915

20-
public sealed class TestController
21-
{
22-
23-
public int SimpleType() => 42;
24-
25-
}
26-
2716
public sealed class ControllerWithNullablePath
2817
{
2918

@@ -44,14 +33,6 @@ public sealed class ControllerWithComplexPath
4433

4534
#region Tests
4635

47-
[TestMethod]
48-
public async Task TestMustNotReturnSimpleType()
49-
{
50-
using var response = await Run("/c/simple-type/");
51-
52-
await response.AssertStatusAsync(HttpStatusCode.InternalServerError);
53-
}
54-
5536
[TestMethod]
5637
public void TestNoNullablePathArguments()
5738
{
@@ -74,20 +55,6 @@ public void TestNoComplexPathArguments()
7455

7556
#endregion
7657

77-
#region Helpers
78-
79-
private async Task<HttpResponseMessage> Run(string uri)
80-
{
81-
var layout = Layout.Create()
82-
.AddController<TestController>("c");
83-
84-
using var runner = TestHost.Run(layout);
85-
86-
return await runner.GetResponseAsync(uri);
87-
}
88-
89-
#endregion
90-
9158
}
9259

9360
}

0 commit comments

Comments
 (0)