From 761a182145aa47bda29f731584c69200abc242d3 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Fri, 26 Jun 2015 11:32:41 -0700 Subject: [PATCH] Reacting to Session, Authentication changes --- .../Views/Checkout/AddressAndPayment.cshtml | 2 +- src/MusicStore/project.json | 3 +- .../CartSummaryComponentTest.cs | 2 +- .../MusicStore.Test/CheckoutControllerTest.cs | 2 +- test/MusicStore.Test/ManageControllerTest.cs | 6 +-- .../ShoppingCartControllerTest.cs | 10 ++--- test/MusicStore.Test/TestSession.cs | 45 +++++++++++++++++++ test/MusicStore.Test/TestSessionFeature.cs | 26 ----------- 8 files changed, 58 insertions(+), 38 deletions(-) create mode 100644 test/MusicStore.Test/TestSession.cs delete mode 100644 test/MusicStore.Test/TestSessionFeature.cs diff --git a/src/MusicStore/Views/Checkout/AddressAndPayment.cshtml b/src/MusicStore/Views/Checkout/AddressAndPayment.cshtml index 09969b2a86..08e3404e94 100644 --- a/src/MusicStore/Views/Checkout/AddressAndPayment.cshtml +++ b/src/MusicStore/Views/Checkout/AddressAndPayment.cshtml @@ -8,7 +8,7 @@ @{await Html.RenderPartialAsync("_ValidationScriptsPartial"); } } -
+

Address And Payment


diff --git a/src/MusicStore/project.json b/src/MusicStore/project.json index 8a32ee52e9..8db51d4994 100644 --- a/src/MusicStore/project.json +++ b/src/MusicStore/project.json @@ -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-*", diff --git a/test/MusicStore.Test/CartSummaryComponentTest.cs b/test/MusicStore.Test/CartSummaryComponentTest.cs index f2be34e695..6a465975fb 100644 --- a/test/MusicStore.Test/CartSummaryComponentTest.cs +++ b/test/MusicStore.Test/CartSummaryComponentTest.cs @@ -39,7 +39,7 @@ namespace MusicStore.Components // Session initialization var cartId = "CartId_A"; - viewContext.HttpContext.SetFeature(new TestSessionFeature()); + viewContext.HttpContext.Session = new TestSession(); viewContext.HttpContext.Session.SetString("Session", cartId); // DbContext initialization diff --git a/test/MusicStore.Test/CheckoutControllerTest.cs b/test/MusicStore.Test/CheckoutControllerTest.cs index a0af8edb6c..562210d182 100644 --- a/test/MusicStore.Test/CheckoutControllerTest.cs +++ b/test/MusicStore.Test/CheckoutControllerTest.cs @@ -58,7 +58,7 @@ namespace MusicStore.Controllers // Session initialization var cartId = "CartId_A"; - httpContext.SetFeature(new TestSessionFeature()); + httpContext.Session = new TestSession(); httpContext.Session.SetString("Session", cartId); // FormCollection initialization diff --git a/test/MusicStore.Test/ManageControllerTest.cs b/test/MusicStore.Test/ManageControllerTest.cs index ad6fa6b6d9..077c820fcc 100644 --- a/test/MusicStore.Test/ManageControllerTest.cs +++ b/test/MusicStore.Test/ManageControllerTest.cs @@ -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(); } diff --git a/test/MusicStore.Test/ShoppingCartControllerTest.cs b/test/MusicStore.Test/ShoppingCartControllerTest.cs index bbaebe6152..72a1335b0c 100644 --- a/test/MusicStore.Test/ShoppingCartControllerTest.cs +++ b/test/MusicStore.Test/ShoppingCartControllerTest.cs @@ -42,7 +42,7 @@ namespace MusicStore.Controllers { // Arrange var httpContext = new DefaultHttpContext(); - httpContext.SetFeature(new TestSessionFeature()); + httpContext.Session = new TestSession(); var controller = new ShoppingCartController() { @@ -68,7 +68,7 @@ namespace MusicStore.Controllers { // Arrange var httpContext = new DefaultHttpContext(); - httpContext.SetFeature(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(new TestSessionFeature()); + httpContext.Session = new TestSession(); httpContext.Session.SetString("Session", cartId); var dbContext = _serviceProvider.GetRequiredService(); @@ -133,7 +133,7 @@ namespace MusicStore.Controllers // Arrange var albumId = 3; var httpContext = new DefaultHttpContext(); - httpContext.SetFeature(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(new TestSessionFeature()); + httpContext.Session = new TestSession(); httpContext.Session.SetString("Session", cartId); // DbContext initialization diff --git a/test/MusicStore.Test/TestSession.cs b/test/MusicStore.Test/TestSession.cs new file mode 100644 index 0000000000..8a69105651 --- /dev/null +++ b/test/MusicStore.Test/TestSession.cs @@ -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 _store + = new Dictionary(StringComparer.OrdinalIgnoreCase); + + public IEnumerable 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); + } + } +} diff --git a/test/MusicStore.Test/TestSessionFeature.cs b/test/MusicStore.Test/TestSessionFeature.cs deleted file mode 100644 index 74e0b0d7da..0000000000 --- a/test/MusicStore.Test/TestSessionFeature.cs +++ /dev/null @@ -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); - } - } - } -}