-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure *Base types have the same members as the main types (#498)
System.Web had *Base types that were meant for abstraction. This adds a test to ensure we have the same members on both versions and adds a few that were missing.
- Loading branch information
1 parent
aac9078
commit 58bc014
Showing
10 changed files
with
137 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/VerifyHttpBaseTypes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Web; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.AspNetCore.SystemWebAdapters; | ||
|
||
/// <summary> | ||
/// This test validates that the *Base type (the abstraction in System.Web) has the same members as on the non-base type. For example, <see cref="HttpContext"/> and <see cref="HttpContextBase"/>. | ||
/// This test is a best effort to ensure when an API is added to the main type, the base type gets it as well | ||
/// </summary> | ||
public class VerifyHttpBaseTypes | ||
{ | ||
private static readonly HashSet<string> _skipped = new HashSet<string>() | ||
{ | ||
"op_Implicit", // This is only defined on the non-base types as there is a well defined conversion | ||
}; | ||
|
||
private readonly ITestOutputHelper _output; | ||
|
||
public VerifyHttpBaseTypes(ITestOutputHelper output) | ||
{ | ||
_output = output; | ||
} | ||
|
||
[InlineData(typeof(HttpContext), typeof(HttpContextBase))] | ||
[InlineData(typeof(HttpRequest), typeof(HttpRequestBase))] | ||
[InlineData(typeof(HttpResponse), typeof(HttpResponseBase))] | ||
[Theory] | ||
public void ValidateMemberExistsOnBaseType(Type type, Type baseType) | ||
{ | ||
ArgumentNullException.ThrowIfNull(type); | ||
ArgumentNullException.ThrowIfNull(baseType); | ||
|
||
const BindingFlags Flags = BindingFlags.Public | BindingFlags.Instance; | ||
|
||
var isMissing = false; | ||
|
||
foreach (var method in type.GetMethods(Flags)) | ||
{ | ||
if (_skipped.Contains(method.Name)) | ||
{ | ||
continue; | ||
} | ||
|
||
var found = baseType.GetMethod(method.Name, Flags, method.GetParameters().Select(p => p.ParameterType).ToArray()); | ||
|
||
if (found is null) | ||
{ | ||
_output.WriteLine(method.Name); | ||
isMissing = true; | ||
} | ||
} | ||
|
||
Assert.False(isMissing); | ||
} | ||
} |