Reacting to Session, Authentication changes
This commit is contained in:
parent
f5a880ba32
commit
761a182145
|
|
@ -8,7 +8,7 @@
|
|||
@{await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
||||
|
||||
<form asp-anti-forgery="true">
|
||||
<form asp-antiforgery="true">
|
||||
<h2>Address And Payment</h2>
|
||||
<hr />
|
||||
<div asp-validation-summary="ValidationSummary.All" class="text-danger"></div>
|
||||
|
|
|
|||
|
|
@ -11,9 +11,10 @@
|
|||
"publishExclude": "*.cmd",
|
||||
"webroot": "wwwroot",
|
||||
"dependencies": {
|
||||
"EntityFramework.SqlServer": "7.0.0-*",
|
||||
"EntityFramework.InMemory": "7.0.0-*",
|
||||
"EntityFramework.SqlServer": "7.0.0-*",
|
||||
"Kestrel": "1.0.0-*",
|
||||
"Microsoft.AspNet.Antiforgery": "1.0.0-*",
|
||||
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
|
||||
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-*",
|
||||
"Microsoft.AspNet.Authentication.Google": "1.0.0-*",
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ namespace MusicStore.Components
|
|||
|
||||
// Session initialization
|
||||
var cartId = "CartId_A";
|
||||
viewContext.HttpContext.SetFeature<ISessionFeature>(new TestSessionFeature());
|
||||
viewContext.HttpContext.Session = new TestSession();
|
||||
viewContext.HttpContext.Session.SetString("Session", cartId);
|
||||
|
||||
// DbContext initialization
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ namespace MusicStore.Controllers
|
|||
|
||||
// Session initialization
|
||||
var cartId = "CartId_A";
|
||||
httpContext.SetFeature<ISessionFeature>(new TestSessionFeature());
|
||||
httpContext.Session = new TestSession();
|
||||
httpContext.Session.SetString("Session", cartId);
|
||||
|
||||
// FormCollection initialization
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ namespace MusicStore.Controllers
|
|||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public void Challenge(ChallengeContext context)
|
||||
public Task ChallengeAsync(ChallengeContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
@ -109,12 +109,12 @@ namespace MusicStore.Controllers
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SignIn(SignInContext context)
|
||||
public Task SignInAsync(SignInContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SignOut(SignOutContext context)
|
||||
public Task SignOutAsync(SignOutContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ namespace MusicStore.Controllers
|
|||
{
|
||||
// Arrange
|
||||
var httpContext = new DefaultHttpContext();
|
||||
httpContext.SetFeature<ISessionFeature>(new TestSessionFeature());
|
||||
httpContext.Session = new TestSession();
|
||||
|
||||
var controller = new ShoppingCartController()
|
||||
{
|
||||
|
|
@ -68,7 +68,7 @@ namespace MusicStore.Controllers
|
|||
{
|
||||
// Arrange
|
||||
var httpContext = new DefaultHttpContext();
|
||||
httpContext.SetFeature<ISessionFeature>(new TestSessionFeature());
|
||||
httpContext.Session = new TestSession();
|
||||
httpContext.Session.SetString("Session", "CartId_A");
|
||||
|
||||
var controller = new ShoppingCartController()
|
||||
|
|
@ -96,7 +96,7 @@ namespace MusicStore.Controllers
|
|||
// Arrange
|
||||
var cartId = "CartId_A";
|
||||
var httpContext = new DefaultHttpContext();
|
||||
httpContext.SetFeature<ISessionFeature>(new TestSessionFeature());
|
||||
httpContext.Session = new TestSession();
|
||||
httpContext.Session.SetString("Session", cartId);
|
||||
|
||||
var dbContext = _serviceProvider.GetRequiredService<MusicStoreContext>();
|
||||
|
|
@ -133,7 +133,7 @@ namespace MusicStore.Controllers
|
|||
// Arrange
|
||||
var albumId = 3;
|
||||
var httpContext = new DefaultHttpContext();
|
||||
httpContext.SetFeature<ISessionFeature>(new TestSessionFeature());
|
||||
httpContext.Session = new TestSession();
|
||||
httpContext.Session.SetString("Session", "CartId_A");
|
||||
|
||||
// Creates the albums of AlbumId = 1 ~ 10.
|
||||
|
|
@ -172,7 +172,7 @@ namespace MusicStore.Controllers
|
|||
var httpContext = new DefaultHttpContext();
|
||||
|
||||
// Session and cart initialization
|
||||
httpContext.SetFeature<ISessionFeature>(new TestSessionFeature());
|
||||
httpContext.Session = new TestSession();
|
||||
httpContext.Session.SetString("Session", cartId);
|
||||
|
||||
// DbContext initialization
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
|
||||
namespace MusicStore.Controllers
|
||||
{
|
||||
internal class TestSession : ISession
|
||||
{
|
||||
private Dictionary<string, byte[]> _store
|
||||
= new Dictionary<string, byte[]>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public IEnumerable<string> Keys { get { return _store.Keys; } }
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_store.Clear();
|
||||
}
|
||||
|
||||
public Task CommitAsync()
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public Task LoadAsync()
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public void Remove(string key)
|
||||
{
|
||||
_store.Remove(key);
|
||||
}
|
||||
|
||||
public void Set(string key, byte[] value)
|
||||
{
|
||||
_store[key] = value;
|
||||
}
|
||||
|
||||
public bool TryGetValue(string key, out byte[] value)
|
||||
{
|
||||
return _store.TryGetValue(key, out value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
using System;
|
||||
using Microsoft.AspNet.Http.Features;
|
||||
using Microsoft.AspNet.Session;
|
||||
using Microsoft.Framework.Caching.Distributed;
|
||||
using Microsoft.Framework.Caching.Memory;
|
||||
using Microsoft.Framework.Logging.Testing;
|
||||
|
||||
namespace MusicStore.Controllers
|
||||
{
|
||||
public class TestSessionFeature : ISessionFeature
|
||||
{
|
||||
public ISession Session
|
||||
{
|
||||
get
|
||||
{
|
||||
return new DistributedSession(
|
||||
new LocalCache(new MemoryCache(new MemoryCacheOptions())),
|
||||
"sessionId_A",
|
||||
idleTimeout: TimeSpan.MaxValue,
|
||||
tryEstablishSession: () => true,
|
||||
loggerFactory: new NullLoggerFactory(),
|
||||
isNewSessionKey: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue