From 7edbabd49816f6a2dc8bb6c7911b68d47375d8df Mon Sep 17 00:00:00 2001 From: Chris R Date: Tue, 3 Nov 2015 10:15:23 -0800 Subject: [PATCH] React to Http.Abstractions changes. --- .../DefaultAntiforgeryTokenStoreTest.cs | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/test/Microsoft.AspNet.Antiforgery.Test/DefaultAntiforgeryTokenStoreTest.cs b/test/Microsoft.AspNet.Antiforgery.Test/DefaultAntiforgeryTokenStoreTest.cs index 3b546e99d9..27d36cd2b6 100644 --- a/test/Microsoft.AspNet.Antiforgery.Test/DefaultAntiforgeryTokenStoreTest.cs +++ b/test/Microsoft.AspNet.Antiforgery.Test/DefaultAntiforgeryTokenStoreTest.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Antiforgery public void GetCookieToken_CookieDoesNotExist_ReturnsNull() { // Arrange - var requestCookies = new Mock(); + var requestCookies = new Mock(); requestCookies .Setup(o => o[It.IsAny()]) .Returns(string.Empty); @@ -54,7 +54,7 @@ namespace Microsoft.AspNet.Antiforgery public void GetCookieToken_CookieIsMissingInRequest_LooksUpCookieInAntiforgeryContext() { // Arrange - var requestCookies = new Mock(); + var requestCookies = new Mock(); requestCookies .Setup(o => o[It.IsAny()]) .Returns(string.Empty); @@ -167,7 +167,7 @@ namespace Microsoft.AspNet.Antiforgery // Arrange var httpContext = new DefaultHttpContext(); httpContext.Request.Form = new FormCollection(new Dictionary()); - httpContext.Request.Cookies = new ReadableStringCollection(new Dictionary()); + httpContext.Request.Cookies = new RequestCookieCollection(new Dictionary()); var options = new AntiforgeryOptions() { @@ -196,7 +196,7 @@ namespace Microsoft.AspNet.Antiforgery // Will not be accessed httpContext.Request.Form = null; - httpContext.Request.Cookies = new ReadableStringCollection(new Dictionary() + httpContext.Request.Cookies = new RequestCookieCollection(new Dictionary() { { "cookie-name", "cookie-value" }, }); @@ -226,7 +226,7 @@ namespace Microsoft.AspNet.Antiforgery var httpContext = new DefaultHttpContext(); httpContext.Request.ContentType = "application/x-www-form-urlencoded"; httpContext.Request.Form = new FormCollection(new Dictionary()); - httpContext.Request.Cookies = new ReadableStringCollection(new Dictionary() + httpContext.Request.Cookies = new RequestCookieCollection(new Dictionary() { { "cookie-name", "cookie-value" }, }); @@ -259,7 +259,7 @@ namespace Microsoft.AspNet.Antiforgery { { "form-field-name", "form-value" }, }); - httpContext.Request.Cookies = new ReadableStringCollection(new Dictionary() + httpContext.Request.Cookies = new RequestCookieCollection(new Dictionary() { { "cookie-name", "cookie-value" }, }); @@ -385,7 +385,7 @@ namespace Microsoft.AspNet.Antiforgery } } - private class MockCookieCollection : IReadableStringCollection + private class MockCookieCollection : IRequestCookieCollection { private Dictionary _dictionary; @@ -415,22 +415,26 @@ namespace Microsoft.AspNet.Antiforgery return new MockCookieCollection(new Dictionary() { { key, value } }); } - public string Get(string key) - { - return this[key]; - } - public bool ContainsKey(string key) { return _dictionary.ContainsKey(key); } - public StringValues this[string key] + public string this[string key] { - get { return _dictionary[key]; } + get + { + string value; + return _dictionary.TryGetValue(key, out value) ? value : null; + } } - public IEnumerator> GetEnumerator() + public bool TryGetValue(string key, out string value) + { + return _dictionary.TryGetValue(key, out value); + } + + public IEnumerator> GetEnumerator() { throw new NotImplementedException(); }