public DecodeCookieToJson ( System.Web.HttpContextBase context ) : string | ||
context | System.Web.HttpContextBase | |
Результат | string |
public void ReturnsNullIfCookieIsInvalid() { // Arrange var context = new Mock<HttpContextBase>(); var tokens = new Mock<TokenService>(); var utils = new Utils.UtilWorker(tokens.Object); context.Setup(c => c.Request.Cookies) .Returns(() => new HttpCookieCollection() { new HttpCookie(ReviewRApiController.CookieName, "COOK%20IE!?") }); tokens.Setup(t => t.UnprotectToken("COOK IE!?", ReviewRApiController.Purpose)) .Throws<InvalidDataException>(); // Act Assert.Null(utils.DecodeCookieToJson(context.Object)); }
public void ReturnsJsonOfTokenIfCookieValid() { // Arrange var context = new Mock<HttpContextBase>(); var tokens = new Mock<TokenService>(); var utils = new Utils.UtilWorker(tokens.Object); context.Setup(c => c.Request.Cookies) .Returns(() => new HttpCookieCollection() { new HttpCookie(ReviewRApiController.CookieName, "COOK%20IE!?") }); tokens.Setup(t => t.UnprotectToken("COOK IE!?", ReviewRApiController.Purpose)) .Returns( new SessionToken( new ReviewRPrincipal( new ReviewRIdentity() { Email = "*****@*****.**", DisplayName = "Swedish Chef" }), DateTime.UtcNow)); // Act Assert.Equal( "{\"userId\":0,\"displayName\":\"Swedish Chef\",\"email\":\"[email protected]\",\"emailHash\":\"67614c787f39a22a54b7dcd169a01477\",\"roles\":null}", utils.DecodeCookieToJson(context.Object)); }