From 2f7e64cfd1d92f0114c85f52aa3b79e4eecba8bb Mon Sep 17 00:00:00 2001 From: Taylor Southwick Date: Thu, 11 Jul 2024 11:15:33 -0700 Subject: [PATCH 1/3] Remove or fix APIs that were ported with different signatures This is to fix a few APIs where the APIs ported did not match .NET Framework, so using those methods would throw at runtime. The only API removed in this is HttpRequest.LogonUserIdentity - we can investigate adding it back if needed. The rest of the APIs now match framework and tests are in place to ensure going forward no regressions or repeats of this issue occur. Fixes #486 --- .../Caching/Cache.cs | 2 +- .../Caching/CacheDependency.cs | 3 +- .../Generated/Ref.Standard.cs | 65 ++++++++--- .../Generated/TypeForwards.Framework.cs | 2 + .../HttpApplicationStateBase.cs | 109 ++++++++++++++++++ .../HttpApplicationStateWrapper.cs | 108 +++++++++++++++++ .../HttpCachePolicyBase.cs | 11 +- .../HttpCachePolicyWrapper.cs | 2 +- .../HttpContextBase.cs | 2 +- .../HttpContextWrapper.cs | 2 +- .../HttpException.cs | 43 +++---- .../HttpRequest.cs | 4 +- .../HttpRequestBase.cs | 2 - .../HttpRequestWrapper.cs | 3 - .../BaselineMethodIssues.txt | 22 ---- ...etCore.SystemWebAdapters.Apis.Tests.csproj | 3 - .../VerifyHttpBaseTypes.cs | 14 ++- .../VerifyMembersHaveSameSignature.cs | 5 - .../HttpExceptionTests.cs | 49 +++----- 19 files changed, 322 insertions(+), 129 deletions(-) create mode 100644 src/Microsoft.AspNetCore.SystemWebAdapters/HttpApplicationStateBase.cs create mode 100644 src/Microsoft.AspNetCore.SystemWebAdapters/HttpApplicationStateWrapper.cs delete mode 100644 test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/BaselineMethodIssues.txt diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/Caching/Cache.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/Caching/Cache.cs index 6a00f3174e..4d098ecceb 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/Caching/Cache.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/Caching/Cache.cs @@ -159,5 +159,5 @@ public void Insert(string key, object value, CacheDependency? dependencies, Date internal ObjectCache ObjectCache => _cache; - public IEnumerator GetEnumerator() => ((IEnumerable)_cache).GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)_cache).GetEnumerator(); } diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/Caching/CacheDependency.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/Caching/CacheDependency.cs index e7043e0ba9..d1f60c7ce1 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/Caching/CacheDependency.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/Caching/CacheDependency.cs @@ -131,7 +131,8 @@ public void SetCacheDependencyChanged(Action dependencyChange #region "IDisposable" protected virtual void DependencyDispose() { } - protected virtual void Dispose(bool disposing) + [Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1063:Implement IDisposable Correctly", Justification = Constants.ApiFromAspNet)] + internal void Dispose(bool disposing) { if (disposing) { diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs index c66b22aace..925014f52a 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs @@ -80,6 +80,55 @@ internal HttpApplicationState() { } public void Set(string name, object value) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public void UnLock() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public abstract partial class HttpApplicationStateBase : System.Collections.Specialized.NameObjectCollectionBase, System.Collections.ICollection, System.Collections.IEnumerable + { + protected HttpApplicationStateBase() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public virtual string[] AllKeys { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public virtual System.Web.HttpApplicationStateBase Contents { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public override int Count { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public virtual bool IsSynchronized { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public virtual object this[int index] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public virtual object this[string name] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} set { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public virtual object SyncRoot { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public virtual void Add(string name, object value) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public virtual void Clear() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public virtual void CopyTo(System.Array array, int index) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public virtual object Get(int index) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public virtual object Get(string name) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public override System.Collections.IEnumerator GetEnumerator() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public virtual string GetKey(int index) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public virtual void Lock() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public virtual void Remove(string name) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public virtual void RemoveAll() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public virtual void RemoveAt(int index) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public virtual void Set(string name, object value) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public virtual void UnLock() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + } + public partial class HttpApplicationStateWrapper : System.Web.HttpApplicationStateBase + { + public HttpApplicationStateWrapper(System.Web.HttpApplicationState httpApplicationState) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public override string[] AllKeys { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public override System.Web.HttpApplicationStateBase Contents { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public override int Count { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public override bool IsSynchronized { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public override object this[int index] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public override object this[string name] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} set { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public override System.Collections.Specialized.NameObjectCollectionBase.KeysCollection Keys { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public override object SyncRoot { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public override void Add(string name, object value) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public override void Clear() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public override void CopyTo(System.Array array, int index) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public override object Get(int index) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public override object Get(string name) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public override System.Collections.IEnumerator GetEnumerator() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public override string GetKey(int index) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public override void Lock() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public override void Remove(string name) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public override void RemoveAll() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public override void RemoveAt(int index) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public override void Set(string name, object value) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + public override void UnLock() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + } public partial class HttpBrowserCapabilities : System.Web.Configuration.HttpCapabilitiesBase { internal HttpBrowserCapabilities() { } @@ -131,7 +180,6 @@ public partial class HttpCachePolicyBase public HttpCachePolicyBase() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public virtual System.Web.HttpCacheVaryByHeaders VaryByHeaders { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual void SetCacheability(System.Web.HttpCacheability cacheability) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} - public virtual void SetCacheability(System.Web.HttpCacheability cacheability, string field) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public virtual void SetExpires(System.DateTime date) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public virtual void SetLastModified(System.DateTime date) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public virtual void SetMaxAge(System.TimeSpan delta) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} @@ -192,7 +240,7 @@ public partial class HttpContextBase : System.IServiceProvider { protected HttpContextBase() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public virtual System.Exception[] AllErrors { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } - public virtual System.Web.HttpApplicationState Application { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public virtual System.Web.HttpApplicationStateBase Application { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual System.Web.HttpApplication ApplicationInstance { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual System.Web.Caching.Cache Cache { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual System.Web.IHttpHandler CurrentHandler { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } @@ -225,7 +273,7 @@ public partial class HttpContextWrapper : System.Web.HttpContextBase { public HttpContextWrapper(System.Web.HttpContext httpContext) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public override System.Exception[] AllErrors { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } - public override System.Web.HttpApplicationState Application { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } + public override System.Web.HttpApplicationStateBase Application { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override System.Web.HttpApplication ApplicationInstance { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override System.Web.Caching.Cache Cache { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override System.Web.IHttpHandler CurrentHandler { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } @@ -288,15 +336,10 @@ public sealed partial class HttpCookieCollection : System.Collections.Specialize public partial class HttpException : System.SystemException { public HttpException() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} - public HttpException(int httpStatusCode) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public HttpException(int httpStatusCode, string message) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public HttpException(int httpStatusCode, string message, System.Exception innerException) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} - public HttpException(System.Net.HttpStatusCode httpStatusCode) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} - public HttpException(System.Net.HttpStatusCode httpStatusCode, string message) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} - public HttpException(System.Net.HttpStatusCode httpStatusCode, string message, System.Exception innerException) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public HttpException(string message) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public HttpException(string message, System.Exception innerException) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} - public int StatusCode { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public int GetHttpCode() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public sealed partial class HttpFileCollection : System.Collections.Specialized.NameObjectCollectionBase @@ -395,7 +438,6 @@ internal HttpRequest() { } public bool IsLocal { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public bool IsSecureConnection { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public string this[string key] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } - public System.Security.Principal.IIdentity LogonUserIdentity { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public System.Collections.Specialized.NameValueCollection Params { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public string Path { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public string PathInfo { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } @@ -440,7 +482,6 @@ public abstract partial class HttpRequestBase public virtual bool IsLocal { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual bool IsSecureConnection { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual string this[string key] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } - public virtual System.Security.Principal.IIdentity LogonUserIdentity { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual System.Collections.Specialized.NameValueCollection Params { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual string Path { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public virtual string PathInfo { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } @@ -485,7 +526,6 @@ public partial class HttpRequestWrapper : System.Web.HttpRequestBase public override bool IsLocal { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override bool IsSecureConnection { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override string this[string key] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } - public override System.Security.Principal.IIdentity LogonUserIdentity { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override System.Collections.Specialized.NameValueCollection Params { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override string Path { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public override string PathInfo { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } @@ -836,13 +876,13 @@ public sealed partial class Cache : System.Collections.IEnumerable public object this[string key] { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} set { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public object Add(string key, object value, System.Web.Caching.CacheDependency dependencies, System.DateTime absoluteExpiration, System.TimeSpan slidingExpiration, System.Web.Caching.CacheItemPriority priority, System.Web.Caching.CacheItemRemovedCallback onRemoveCallback) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public object Get(string key) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} - public System.Collections.IEnumerator GetEnumerator() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public void Insert(string key, object value) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public void Insert(string key, object value, System.Web.Caching.CacheDependency dependencies) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public void Insert(string key, object value, System.Web.Caching.CacheDependency dependencies, System.DateTime absoluteExpiration, System.TimeSpan slidingExpiration) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public void Insert(string key, object value, System.Web.Caching.CacheDependency dependencies, System.DateTime absoluteExpiration, System.TimeSpan slidingExpiration, System.Web.Caching.CacheItemPriority priority, System.Web.Caching.CacheItemRemovedCallback onRemoveCallback) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public void Insert(string key, object value, System.Web.Caching.CacheDependency dependencies, System.DateTime absoluteExpiration, System.TimeSpan slidingExpiration, System.Web.Caching.CacheItemUpdateCallback onUpdateCallback) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public object Remove(string key) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } public partial class CacheDependency : System.IDisposable { @@ -859,7 +899,6 @@ public partial class CacheDependency : System.IDisposable public System.DateTime UtcLastModified { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} } protected virtual void DependencyDispose() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public void Dispose() { } - protected virtual void Dispose(bool disposing) { } protected internal void FinishInit() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public virtual string[] GetFileDependencies() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} public virtual string GetUniqueID() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/TypeForwards.Framework.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/TypeForwards.Framework.cs index fd18a3aeca..00841306b2 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/TypeForwards.Framework.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/Generated/TypeForwards.Framework.cs @@ -22,6 +22,8 @@ [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpApplication))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpApplicationState))] +[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpApplicationStateBase))] +[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpApplicationStateWrapper))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpBrowserCapabilities))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpBrowserCapabilitiesBase))] [assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpBrowserCapabilitiesWrapper))] diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpApplicationStateBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpApplicationStateBase.cs new file mode 100644 index 0000000000..4f9478223a --- /dev/null +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpApplicationStateBase.cs @@ -0,0 +1,109 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; +using System.Collections.Specialized; +using System.Diagnostics.CodeAnalysis; + +namespace System.Web; + +[SuppressMessage("Design", "CA1010:Generic interface should also be implemented", Justification = Constants.ApiFromAspNet)] +[SuppressMessage("Naming", "CA1710:Identifiers should have correct suffix", Justification = Constants.ApiFromAspNet)] +public abstract class HttpApplicationStateBase : NameObjectCollectionBase, ICollection +{ + [SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = Constants.ApiFromAspNet)] + [SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = Constants.ApiFromAspNet)] + public virtual string?[]? AllKeys => throw new NotImplementedException(); + + [SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = Constants.ApiFromAspNet)] + public virtual HttpApplicationStateBase Contents => throw new NotImplementedException(); + + [SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = Constants.ApiFromAspNet)] + public override int Count => throw new NotImplementedException(); + + [SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = Constants.ApiFromAspNet)] + public virtual bool IsSynchronized => throw new NotImplementedException(); + + [SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = Constants.ApiFromAspNet)] + public virtual object SyncRoot => throw new NotImplementedException(); + + [SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = Constants.ApiFromAspNet)] + [DisallowNull] + public virtual object? this[int index] => throw new NotImplementedException(); + + [SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = Constants.ApiFromAspNet)] + [DisallowNull] + public virtual object? this[string name] + { + get => throw new NotImplementedException(); + set => throw new NotImplementedException(); + } + + public virtual void Add(string name, object value) + { + throw new NotImplementedException(); + } + + public virtual void Clear() + { + throw new NotImplementedException(); + } + + public virtual void CopyTo(Array array, int index) + { + throw new NotImplementedException(); + } + + [SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = Constants.ApiFromAspNet)] + public virtual object? Get(int index) + { + throw new NotImplementedException(); + } + + [SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = Constants.ApiFromAspNet)] + public virtual object? Get(string name) + { + throw new NotImplementedException(); + } + + public override IEnumerator GetEnumerator() + { + throw new NotImplementedException(); + } + + public virtual string? GetKey(int index) + { + throw new NotImplementedException(); + } + + public virtual void Lock() + { + throw new NotImplementedException(); + } + + public virtual void Remove(string name) + { + throw new NotImplementedException(); + } + + public virtual void RemoveAll() + { + throw new NotImplementedException(); + } + + public virtual void RemoveAt(int index) + { + throw new NotImplementedException(); + } + + [SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = Constants.ApiFromAspNet)] + public virtual void Set(string name, object value) + { + throw new NotImplementedException(); + } + + public virtual void UnLock() + { + throw new NotImplementedException(); + } +} diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpApplicationStateWrapper.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpApplicationStateWrapper.cs new file mode 100644 index 0000000000..39c172613a --- /dev/null +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpApplicationStateWrapper.cs @@ -0,0 +1,108 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; +using System.Collections.Specialized; +using System.Diagnostics.CodeAnalysis; + +namespace System.Web; + +[SuppressMessage("Design", "CA1010:Generic interface should also be implemented", Justification = Constants.ApiFromAspNet)] +public class HttpApplicationStateWrapper : HttpApplicationStateBase +{ + private readonly HttpApplicationState _application; + + public HttpApplicationStateWrapper(HttpApplicationState httpApplicationState) + { + ArgumentNullException.ThrowIfNull(httpApplicationState); + + _application = httpApplicationState; + } + + public override string?[]? AllKeys => _application.AllKeys; + + public override HttpApplicationStateBase Contents => this; + + public override int Count => _application.Count; + + public override bool IsSynchronized => ((ICollection)_application).IsSynchronized; + + public override NameObjectCollectionBase.KeysCollection Keys => _application.Keys; + + public override object SyncRoot => ((ICollection)_application).SyncRoot; + + [DisallowNull] + public override object? this[int index] => _application[index]!; + + [DisallowNull] + public override object? this[string name] + { + get => _application[name]; + set => _application[name] = value; + } + + public override void Add(string name, object value) + { + _application.Add(name, value); + } + + public override void Clear() + { + _application.Clear(); + } + + public override void CopyTo(Array array, int index) + { + ((ICollection)_application).CopyTo(array, index); + } + + public override object? Get(int index) + { + return _application.Get(index); + } + + public override object? Get(string name) + { + return _application.Get(name); + } + + public override IEnumerator GetEnumerator() + { + return _application.GetEnumerator(); + } + + public override string? GetKey(int index) + { + return _application.GetKey(index); + } + + public override void Lock() + { + _application.Lock(); + } + + public override void Remove(string name) + { + _application.Remove(name); + } + + public override void RemoveAll() + { + _application.RemoveAll(); + } + + public override void RemoveAt(int index) + { + _application.RemoveAt(index); + } + + public override void Set(string name, object value) + { + _application.Set(name, value); + } + + public override void UnLock() + { + _application.UnLock(); + } +} diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpCachePolicyBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpCachePolicyBase.cs index 6dffda6ab9..0dfd2acf86 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpCachePolicyBase.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpCachePolicyBase.cs @@ -12,17 +12,14 @@ public class HttpCachePolicyBase public virtual void SetCacheability(HttpCacheability cacheability) => throw new NotImplementedException(); - public virtual void SetCacheability(HttpCacheability cacheability, string field) => throw new NotImplementedException(); - - [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Date", - Justification = "Matches HttpCachePolicy class")] + [SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = Constants.ApiFromAspNet)] public virtual void SetLastModified(DateTime date) => throw new NotImplementedException(); public virtual void SetMaxAge(TimeSpan delta) => throw new NotImplementedException(); - - [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Date", - Justification = "Matches HttpCachePolicy class")] + + [SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = Constants.ApiFromAspNet)] public virtual void SetExpires(DateTime date) => throw new NotImplementedException(); + [SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = Constants.ApiFromAspNet)] public virtual void SetOmitVaryStar(bool omit) => throw new NotImplementedException(); } diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpCachePolicyWrapper.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpCachePolicyWrapper.cs index b87156f202..05a8f6b05a 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpCachePolicyWrapper.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpCachePolicyWrapper.cs @@ -11,7 +11,7 @@ public HttpCachePolicyWrapper(HttpCachePolicy httpCachePolicy) { if (httpCachePolicy == null) { - ArgumentNullException.ThrowIfNull(httpCachePolicy); + ArgumentNullException.ThrowIfNull(httpCachePolicy); } _httpCachePolicy = httpCachePolicy; } diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpContextBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpContextBase.cs index 928737d30a..ba30f5dd4e 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpContextBase.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpContextBase.cs @@ -36,7 +36,7 @@ protected HttpContextBase() public virtual HttpApplication ApplicationInstance => throw new NotImplementedException(); - public virtual HttpApplicationState Application => throw new NotImplementedException(); + public virtual HttpApplicationStateBase Application => throw new NotImplementedException(); public virtual bool IsPostNotification => throw new NotImplementedException(); diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpContextWrapper.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpContextWrapper.cs index f989a515f1..26a73b8503 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpContextWrapper.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpContextWrapper.cs @@ -43,7 +43,7 @@ public HttpContextWrapper(HttpContext httpContext) public override HttpApplication ApplicationInstance => _context.ApplicationInstance; - public override HttpApplicationState Application => _context.Application; + public override HttpApplicationStateBase Application => new HttpApplicationStateWrapper(_context.Application); public override RequestNotification CurrentNotification => _context.CurrentNotification; diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpException.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpException.cs index 132865f991..d2aafaf0be 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpException.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpException.cs @@ -1,13 +1,14 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Net; +using System.IO; +using Microsoft.AspNetCore.Http; namespace System.Web; public class HttpException : SystemException { - private readonly int _httpStatusCode = 500; + private readonly int _httpStatusCode; public HttpException() { @@ -17,50 +18,32 @@ public HttpException(string message) : base(message) { } - public HttpException(string message, Exception innerException) + public HttpException(String message, Exception innerException) : base(message, innerException) { } - public HttpException(int httpStatusCode) - { - _httpStatusCode = httpStatusCode; - } - - public HttpException(HttpStatusCode httpStatusCode) - { - _httpStatusCode = (int)httpStatusCode; - } - public HttpException(int httpStatusCode, string message) : base(message) { _httpStatusCode = httpStatusCode; } - public HttpException(HttpStatusCode httpStatusCode, string message) - : base(message) - { - _httpStatusCode = (int)httpStatusCode; - } - public HttpException(int httpStatusCode, string message, Exception innerException) : base(message, innerException) { _httpStatusCode = httpStatusCode; } - public HttpException(HttpStatusCode httpStatusCode, string message, Exception innerException) - : base(message, innerException) - { - _httpStatusCode = (int)httpStatusCode; - } - [Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1024:Use properties where appropriate", Justification = Constants.ApiFromAspNet)] - public int GetHttpCode() - { - return StatusCode; - } + public int GetHttpCode() => GetHttpCodeForException(this); - public int StatusCode => _httpStatusCode; + internal static int GetHttpCodeForException(Exception e) => e switch + { + HttpException { _httpStatusCode: { } code } when code > 0 => code, + UnauthorizedAccessException => StatusCodes.Status401Unauthorized, + PathTooLongException => StatusCodes.Status414UriTooLong, + { InnerException: { } inner } => GetHttpCodeForException(inner), + _ => 500 + }; } diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequest.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequest.cs index a2931aaca1..1c8d1b95d1 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequest.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequest.cs @@ -198,9 +198,7 @@ public bool IsLocal public int TotalBytes => (int)InputStream.Length; - public bool IsAuthenticated => LogonUserIdentity?.IsAuthenticated ?? false; - - public IIdentity? LogonUserIdentity => Request.HttpContext.User.Identity; + public bool IsAuthenticated => Request.HttpContext.User is { Identity.IsAuthenticated: true }; public Encoding? ContentEncoding => TypedHeaders.ContentType?.Encoding; diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestBase.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestBase.cs index a8f789e6a9..a1b124bc5d 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestBase.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestBase.cs @@ -90,8 +90,6 @@ public virtual string? ContentType public virtual bool IsAuthenticated => throw new NotImplementedException(); - public virtual IIdentity? LogonUserIdentity => throw new NotImplementedException(); - public virtual Encoding? ContentEncoding => throw new NotImplementedException(); public virtual string? UserHostName => throw new NotImplementedException(); diff --git a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestWrapper.cs b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestWrapper.cs index df9b478c12..17cced4ff6 100644 --- a/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestWrapper.cs +++ b/src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestWrapper.cs @@ -3,7 +3,6 @@ using System.Collections.Specialized; using System.IO; -using System.Security.Principal; using System.Text; namespace System.Web @@ -55,8 +54,6 @@ public override string? ContentType public override bool IsLocal => _request.IsLocal; - public override IIdentity? LogonUserIdentity => _request.LogonUserIdentity; - public override string Path => _request.Path; public override string CurrentExecutionFilePath => _request.CurrentExecutionFilePath; diff --git a/test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/BaselineMethodIssues.txt b/test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/BaselineMethodIssues.txt deleted file mode 100644 index 9e8592e124..0000000000 --- a/test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/BaselineMethodIssues.txt +++ /dev/null @@ -1,22 +0,0 @@ -T:System.Web.HttpApplicationState M:System.Web.HttpContextBase.get_Application -T:System.Web.HttpApplicationState P:System.Web.HttpContextBase.Application -T:System.Web.HttpApplicationState M:System.Web.HttpContextWrapper.get_Application -T:System.Web.HttpApplicationState P:System.Web.HttpContextWrapper.Application -T:System.Void M:System.Web.HttpException.#ctor(System.Int32) -T:System.Void M:System.Web.HttpException.#ctor(System.Net.HttpStatusCode) -T:System.Void M:System.Web.HttpException.#ctor(System.Net.HttpStatusCode,System.String) -T:System.Void M:System.Web.HttpException.#ctor(System.Net.HttpStatusCode,System.String,System.Exception) -T:System.Int32 M:System.Web.HttpException.get_StatusCode -T:System.Int32 P:System.Web.HttpException.StatusCode -T:System.Security.Principal.IIdentity M:System.Web.HttpRequest.get_LogonUserIdentity -T:System.Security.Principal.IIdentity P:System.Web.HttpRequest.LogonUserIdentity -T:System.Security.Principal.IIdentity M:System.Web.HttpRequestBase.get_LogonUserIdentity -T:System.Security.Principal.IIdentity P:System.Web.HttpRequestBase.LogonUserIdentity -T:System.Security.Principal.IIdentity M:System.Web.HttpRequestWrapper.get_LogonUserIdentity -T:System.Security.Principal.IIdentity P:System.Web.HttpRequestWrapper.LogonUserIdentity -T:System.Web.HttpCachePolicy M:System.Web.HttpResponseBase.get_Cache -T:System.Web.HttpCachePolicy P:System.Web.HttpResponseBase.Cache -T:System.Web.HttpCachePolicy M:System.Web.HttpResponseWrapper.get_Cache -T:System.Web.HttpCachePolicy P:System.Web.HttpResponseWrapper.Cache -T:System.Collections.IEnumerator M:System.Web.Caching.Cache.GetEnumerator -T:System.Void M:System.Web.Caching.CacheDependency.Dispose(System.Boolean) diff --git a/test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests.csproj b/test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests.csproj index 5e4e61b9d4..d1d7eb29e4 100644 --- a/test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests.csproj +++ b/test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests.csproj @@ -30,9 +30,6 @@ PreserveNewest - - PreserveNewest - diff --git a/test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/VerifyHttpBaseTypes.cs b/test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/VerifyHttpBaseTypes.cs index a8aafadf92..ee14404ae9 100644 --- a/test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/VerifyHttpBaseTypes.cs +++ b/test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/VerifyHttpBaseTypes.cs @@ -17,9 +17,12 @@ namespace Microsoft.AspNetCore.SystemWebAdapters; /// public class VerifyHttpBaseTypes { - private static readonly HashSet _skipped = new HashSet() + private static readonly Dictionary _skipped = new() { - "op_Implicit", // This is only defined on the non-base types as there is a well defined conversion + // This is only defined on the non-base types as there is a well defined conversion + [typeof(HttpContext)] = "op_Implicit", + [typeof(HttpRequest)] = "op_Implicit", + [typeof(HttpResponse)] = "op_Implicit", }; private readonly ITestOutputHelper _output; @@ -32,6 +35,11 @@ public VerifyHttpBaseTypes(ITestOutputHelper output) [InlineData(typeof(HttpContext), typeof(HttpContextBase))] [InlineData(typeof(HttpRequest), typeof(HttpRequestBase))] [InlineData(typeof(HttpResponse), typeof(HttpResponseBase))] + [InlineData(typeof(HttpCachePolicy), typeof(HttpCachePolicyBase))] + [InlineData(typeof(HttpPostedFile), typeof(HttpPostedFileBase))] + [InlineData(typeof(HttpFileCollectionBase), typeof(HttpFileCollectionBase))] + [InlineData(typeof(HttpServerUtilityBase), typeof(HttpServerUtilityBase))] + [InlineData(typeof(HttpSessionStateBase), typeof(HttpSessionStateBase))] [Theory] public void ValidateMemberExistsOnBaseType(Type type, Type baseType) { @@ -44,7 +52,7 @@ public void ValidateMemberExistsOnBaseType(Type type, Type baseType) foreach (var method in type.GetMethods(Flags)) { - if (_skipped.Contains(method.Name)) + if (_skipped.Contains(new(type, method.Name))) { continue; } diff --git a/test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/VerifyMembersHaveSameSignature.cs b/test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/VerifyMembersHaveSameSignature.cs index 24ff9b82b4..e9fd92cedc 100644 --- a/test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/VerifyMembersHaveSameSignature.cs +++ b/test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/VerifyMembersHaveSameSignature.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.IO; -using System.Linq; using Basic.Reference.Assemblies; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -36,10 +35,6 @@ public void VerifyMembersOnTypesAreConsistent() _output.WriteLine(adaptedType); } - // Remove baseline - var knownIssues = File.ReadAllLines("BaselineMethodIssues.txt"); - netstandard.ExceptWith(knownIssues); - Assert.Empty(netstandard); } diff --git a/test/Microsoft.AspNetCore.SystemWebAdapters.Tests/HttpExceptionTests.cs b/test/Microsoft.AspNetCore.SystemWebAdapters.Tests/HttpExceptionTests.cs index 423ce1ac10..0698c0a961 100644 --- a/test/Microsoft.AspNetCore.SystemWebAdapters.Tests/HttpExceptionTests.cs +++ b/test/Microsoft.AspNetCore.SystemWebAdapters.Tests/HttpExceptionTests.cs @@ -2,8 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using System.Net; +using System.IO; using System.Web; +using Microsoft.AspNetCore.Http; using Xunit; namespace Microsoft.AspNetCore.SystemWebAdapters; @@ -58,25 +59,12 @@ public void CreateWithHttpStatusCode() var httpStatusCode = 404; // Act - var exception = new HttpException(httpStatusCode); + var exception = new HttpException(httpStatusCode, "message"); // Assert Assert.Equal(httpStatusCode, exception.GetHttpCode()); } - [Fact] - public void CreateWithHttpStatusCodeEnum() - { - // Arrange - var httpStatusCode = HttpStatusCode.NotFound; - - // Act - var exception = new HttpException(httpStatusCode); - - // Assert - Assert.Equal((int)httpStatusCode, exception.GetHttpCode()); - } - [Fact] public void CreateWithHttpStatusCodeAndMessage() { @@ -93,49 +81,44 @@ public void CreateWithHttpStatusCodeAndMessage() } [Fact] - public void CreateWithHttpStatusCodeEnumAndMessage() + public void CreateWithIntCodeAndMessageAndInnerException() { // Arrange - var httpStatusCode = HttpStatusCode.NotFound; + var httpStatusCode = 404; var message = "message"; + var innerException = new Exception(); // Act - var exception = new HttpException(httpStatusCode, message); + var exception = new HttpException(httpStatusCode, message, innerException); // Assert Assert.Equal(message, exception.Message); - Assert.Equal((int)httpStatusCode, exception.GetHttpCode()); + Assert.Equal(httpStatusCode, exception.GetHttpCode()); } [Fact] - public void CreateWithIntCodeAndMessageAndInnerException() + public void PathTooLongCode() { // Arrange - var httpStatusCode = 404; - var message = "message"; - var innerException = new Exception(); + var exception = new HttpException(string.Empty, new PathTooLongException()); // Act - var exception = new HttpException(httpStatusCode, message, innerException); + var httpStatusCode = exception.GetHttpCode(); // Assert - Assert.Equal(message, exception.Message); - Assert.Equal(httpStatusCode, exception.GetHttpCode()); + Assert.Equal(StatusCodes.Status414UriTooLong, httpStatusCode); } [Fact] - public void CreateWithEnumHttpStatusCodeAndMessageAndInnerException() + public void UnauthorizedCode() { // Arrange - var httpStatusCode = HttpStatusCode.NotFound; - var message = "message"; - var innerException = new Exception(); + var exception = new HttpException(string.Empty, new UnauthorizedAccessException()); // Act - var exception = new HttpException(httpStatusCode, message, innerException); + var httpStatusCode = exception.GetHttpCode(); // Assert - Assert.Equal(message, exception.Message); - Assert.Equal((int)httpStatusCode, exception.GetHttpCode()); + Assert.Equal(StatusCodes.Status401Unauthorized, httpStatusCode); } } From b71fe3cd6c70d3b6d9b68614f5b43685f2cf0fbc Mon Sep 17 00:00:00 2001 From: Taylor Southwick Date: Thu, 11 Jul 2024 12:26:36 -0700 Subject: [PATCH 2/3] fix broken --- .../Caching/CacheTests.cs | 3 +-- .../HttpRequestTests.cs | 24 ------------------- 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/test/Microsoft.AspNetCore.SystemWebAdapters.Tests/Caching/CacheTests.cs b/test/Microsoft.AspNetCore.SystemWebAdapters.Tests/Caching/CacheTests.cs index d395d68781..48edd4af7b 100644 --- a/test/Microsoft.AspNetCore.SystemWebAdapters.Tests/Caching/CacheTests.cs +++ b/test/Microsoft.AspNetCore.SystemWebAdapters.Tests/Caching/CacheTests.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections; -using System.IO; using System.Runtime.Caching; using System.Threading.Tasks; using AutoFixture; @@ -70,7 +69,7 @@ public void Enumerator() var cache = new Cache(memCache); // Act - var result = cache.GetEnumerator(); + var result = ((IEnumerable)cache).GetEnumerator(); // Assert var enumerator = (IDictionaryEnumerator)result; diff --git a/test/Microsoft.AspNetCore.SystemWebAdapters.Tests/HttpRequestTests.cs b/test/Microsoft.AspNetCore.SystemWebAdapters.Tests/HttpRequestTests.cs index 8b23da3206..41e7c83d9e 100644 --- a/test/Microsoft.AspNetCore.SystemWebAdapters.Tests/HttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.SystemWebAdapters.Tests/HttpRequestTests.cs @@ -597,30 +597,6 @@ public void IsAuthenticated(bool isAuthenticated) Assert.Equal(isAuthenticated, result); } - [Fact] - public void Identity() - { - // Arrange - var identity = new Mock(); - - var user = new Mock(); - user.Setup(u => u.Identity).Returns(identity.Object); - - var coreContext = new Mock(); - coreContext.Setup(c => c.User).Returns(user.Object); - - var coreRequest = new Mock(); - coreRequest.Setup(c => c.HttpContext).Returns(coreContext.Object); - - var request = new HttpRequest(coreRequest.Object); - - // Act - var result = request.LogonUserIdentity; - - // Assert - Assert.Same(identity.Object, result); - } - public enum ContentEncodingType { None, From 8bcebe81483629cf9dc847acddc6a56efd144ef2 Mon Sep 17 00:00:00 2001 From: Taylor Southwick Date: Thu, 11 Jul 2024 13:23:00 -0700 Subject: [PATCH 3/3] fix cacheability test --- .../VerifyHttpBaseTypes.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/VerifyHttpBaseTypes.cs b/test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/VerifyHttpBaseTypes.cs index ee14404ae9..2b17ed6bf0 100644 --- a/test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/VerifyHttpBaseTypes.cs +++ b/test/Microsoft.AspNetCore.SystemWebAdapters.Apis.Tests/VerifyHttpBaseTypes.cs @@ -19,10 +19,10 @@ public class VerifyHttpBaseTypes { private static readonly Dictionary _skipped = new() { - // This is only defined on the non-base types as there is a well defined conversion [typeof(HttpContext)] = "op_Implicit", [typeof(HttpRequest)] = "op_Implicit", [typeof(HttpResponse)] = "op_Implicit", + [typeof(HttpCachePolicy)] = nameof(HttpCachePolicy.GetCacheability), }; private readonly ITestOutputHelper _output;