Skip to content

Commit 543a30c

Browse files
committed
Improved ApplicationBuilderMock
1 parent 1d3ec72 commit 543a30c

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

src/MyTested.AspNetCore.Mvc.Abstractions/Internal/Application/ApplicationBuilderMock.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,12 @@ private void CheckForEndpointRouting(IServiceProvider serviceProvider)
128128

129129
private void ExtractEndpointRoutes(Func<RequestDelegate, RequestDelegate> middleware)
130130
{
131-
var middlewareTypeField = middleware.GetTargetField("middleware");
131+
var stateTypeField = middleware.GetTargetField("state");
132+
var stateType = stateTypeField?.GetValue(middleware.Target);
132133

133-
if (!(middlewareTypeField?.GetValue(middleware.Target) is Type middlewareType)
134-
|| middlewareType.Name != "EndpointMiddleware")
134+
var middlewareTypeProperty = stateType?.GetType().GetProperty("Middleware");
135+
136+
if (middlewareTypeProperty?.GetValue(stateType) is not Type { Name: "EndpointMiddleware" })
135137
{
136138
return;
137139
}
@@ -157,7 +159,7 @@ private void ExtractEndpointRoutes(Func<RequestDelegate, RequestDelegate> middle
157159
endpointDataSource
158160
.Endpoints
159161
.OfType<RouteEndpoint>()
160-
.Where(route => route.Metadata.All(m =>
162+
.Where(route => route.Metadata.All(m =>
161163
Reflection.AreNotAssignable(typeof(IRouteTemplateProvider), m.GetType())))
162164
.OrderBy(route => route.Order)
163165
.ForEach(route =>

src/MyTested.AspNetCore.Mvc.Abstractions/Utilities/Extensions/FuncExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static FieldInfo GetTargetField<T, TResult>(
1111
string fieldName)
1212
=> func
1313
.Target
14-
.GetType()
14+
?.GetType()
1515
.GetTypeInfo()
1616
.DeclaredFields
1717
.FirstOrDefault(m => m.Name == fieldName);

test/MyTested.AspNetCore.Mvc.Http.Test/BuildersTests/HttpTests/HttpRequestBuilderTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void WithHttpRequestShouldWorkCorrectlyWithDefaultValues()
4747
.WithCookies(new
4848
{
4949
ObjectCookie = "ObjectCookieValue",
50-
AnotherObjectCookie = "AnotherObjectCookieValue"
50+
AnotherObjectCookie = "AnotherObjectCookieValue"
5151
})
5252
.AndAlso()
5353
.WithFormField("Field", "FieldValue")
@@ -181,7 +181,7 @@ public void WithFormAsObjectShouldWorkCorrectly()
181181
Assert.Equal("AnotherFieldValue", builtRequest.Form["AnotherField"]);
182182
});
183183
}
184-
184+
185185
[Fact]
186186
public void WithFormAsStringDictionaryShouldWorkCorrectly()
187187
{
@@ -269,7 +269,7 @@ public void WithHeadersAsDictionaryShouldWorkCorrectly()
269269
Assert.Equal("AnotherHeaderValue,SecondHeaderValue", builtRequest.Headers["AnotherHeader"]);
270270
});
271271
}
272-
272+
273273
[Fact]
274274
public void WithHeadersAsObjectDictionaryShouldWorkCorrectly()
275275
{
@@ -560,7 +560,7 @@ public void WithStringBodyShouldWorkCorrectly()
560560
Assert.Equal(ContentType.TextPlain, builtRequest.ContentType);
561561
Assert.Equal(reader.BaseStream.Length, builtRequest.ContentLength);
562562
}
563-
});
563+
});
564564
}
565565

566566
[Fact]
@@ -708,7 +708,7 @@ public void WithLocationShouldWorkWithRelativeUri()
708708
.WithHttpRequest(request => request.WithLocation("/Home/Index"))
709709
.ShouldPassForThe<HttpRequest>(builtRequest =>
710710
{
711-
Assert.Null(builtRequest.Host.Value);
711+
Assert.Equal(string.Empty, builtRequest.Host.Value);
712712
Assert.Equal("/Home/Index", builtRequest.PathBase);
713713
Assert.Equal("http", builtRequest.Scheme);
714714
Assert.Equal("/Home/Index", builtRequest.Path);
@@ -724,7 +724,7 @@ public void WithLocationShouldWorkWithRelativeUriAndQueryString()
724724
.WithHttpRequest(request => request.WithLocation("/Home/Index?test=text"))
725725
.ShouldPassForThe<HttpRequest>(builtRequest =>
726726
{
727-
Assert.Null(builtRequest.Host.Value);
727+
Assert.Equal(string.Empty, builtRequest.Host.Value);
728728
Assert.Equal("/Home/Index", builtRequest.PathBase);
729729
Assert.Equal("http", builtRequest.Scheme);
730730
Assert.Equal("/Home/Index", builtRequest.Path);

test/MyTested.AspNetCore.Mvc.ViewData.Test/PluginsTests/ViewDataTestPluginTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void ShouldInvokeMethodOfTypeVoidWithValidServiceCollection()
3333

3434
testPlugin.DefaultServiceRegistrationDelegate(serviceCollection);
3535

36-
Assert.True(serviceCollection.Count == 165);
36+
Assert.True(serviceCollection.Count == 166);
3737
}
3838
}
3939
}

0 commit comments

Comments
 (0)