Skip to content

Commit

Permalink
Add HttpSessionState.Mode (#289)
Browse files Browse the repository at this point in the history
This change exposes the API and sets it to `Custom`. Everything else has a meaning and implies certain behavior. This value is the only one that makes sense for us to declare. If needed, we can make it customizable later.

Fixes #281
  • Loading branch information
twsouthwick authored Feb 17, 2023
1 parent f0199bd commit aa73002
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ internal HttpSessionState() { }
public bool IsReadOnly { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public bool IsSynchronized { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public 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 System.Web.SessionState.SessionStateMode Mode { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public string SessionID { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public object SyncRoot { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
public int Timeout { 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");} }
Expand All @@ -580,4 +581,12 @@ internal HttpSessionState() { }
public void Remove(string name) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
public void RemoveAll() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
}
public enum SessionStateMode
{
Custom = 4,
InProc = 1,
Off = 0,
SQLServer = 3,
StateServer = 2,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.Caching.CacheItemUpdateReason))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.Configuration.HttpCapabilitiesBase))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.SessionState.HttpSessionState))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.SessionState.SessionStateMode))]
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public int Timeout

public object SyncRoot => _container.SyncRoot;

[Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = Constants.ApiFromAspNet)]
public SessionStateMode Mode => SessionStateMode.Custom;

public void Abandon() => _container.IsAbandoned = true;

public object? this[string name]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Web.SessionState;

public enum SessionStateMode
{
Off = 0,
InProc = 1,
StateServer = 2,
SQLServer = 3,
Custom = 4
};
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ public void SessionId()
Assert.Equal(id, result);
}

[Fact]
public void Mode()
{
// Arrange
var session = new Mock<ISessionState>();

var state = new HttpSessionState(session.Object);

// Act
var result = state.Mode;

// Assert
Assert.Equal(SessionStateMode.Custom, result);
}

[Fact]
public void Count()
{
Expand Down

0 comments on commit aa73002

Please sign in to comment.