Ejemplo n.º 1
0
        public void GetFormInfo()
        {
            var protector = new Mock<IDataProtector>();
            var protectorProvider = new Mock<IDataProtectionProvider>();
            protectorProvider.Setup(x => x.CreateProtector(It.IsAny<string>())).Returns(protector.Object);
            var surfaceRouteParams = $"{SurfaceFormHelper.ReservedAdditionalKeys.Controller}=mycontroller&{SurfaceFormHelper.ReservedAdditionalKeys.Action}=myaction&{SurfaceFormHelper.ReservedAdditionalKeys.Area}=myarea";
            protector.Setup(dataProtector => dataProtector.Protect(It.IsAny<byte[]>())).Returns(Encoding.UTF8.GetBytes(surfaceRouteParams));
            protector.Setup(dataProtector => dataProtector.Unprotect(It.IsAny<byte[]>())).Returns(Encoding.UTF8.GetBytes(surfaceRouteParams));
            var helper = new SurfaceFormHelper(Mock.Of<ILoggerFactory>(), protectorProvider.Object);
            var request = new Mock<HttpRequest>();
            request.Setup(httpRequest => httpRequest.Method).Returns("GET");
            request.Setup(httpRequest => httpRequest.Query).Returns(
                new FormCollection(new Dictionary<string, StringValues>
                {
                    {"ufprt", Convert.ToBase64String(Encoding.UTF8.GetBytes(surfaceRouteParams))}
                }));

            var httpCtxAccessor = new Mock<IHttpContextAccessor>();
            var httpContext = new Mock<HttpContext>();
            httpContext.Setup(context => context.Request).Returns(request.Object);
            httpCtxAccessor.Setup(accessor => accessor.HttpContext).Returns(httpContext.Object);
            var routeCtx = new RouteContext(httpContext.Object);

            var result = helper.GetFormInfo(routeCtx);

            Assert.Equal("mycontroller", result.ControllerName);
            Assert.Equal("myaction", result.ActionName);
            Assert.Equal("myarea", result.Area);
        }
Ejemplo n.º 2
0
 public void GetRequestSurfaceToken_Get()
 {
     var helper = new SurfaceFormHelper(Mock.Of<ILoggerFactory>(), Mock.Of<IDataProtectionProvider>());
     var request = new Mock<HttpRequest>();
     request.Setup(httpRequest => httpRequest.Method).Returns("GET");
     request.Setup(httpRequest => httpRequest.Query).Returns(
         new FormCollection(new Dictionary<string, StringValues>
         {
             {"ufprt", "test"}
         }));
     var result = helper.GetRequestSurfaceToken(request.Object);
     Assert.Equal("test", result);
 }
Ejemplo n.º 3
0
        public void ValidateRequiredTokenParams()
        {
            var helper = new SurfaceFormHelper(Mock.Of<ILoggerFactory>(), Mock.Of<IDataProtectionProvider>());
            var result = helper.ValidateRequiredTokenParams(new Dictionary<string, string>
            {
                {SurfaceFormHelper.ReservedAdditionalKeys.Controller, "foo"},
                {SurfaceFormHelper.ReservedAdditionalKeys.Action, "bar"},
                {SurfaceFormHelper.ReservedAdditionalKeys.Area, "a"}
            });

            Assert.Equal(true, result);

            result = helper.ValidateRequiredTokenParams(new Dictionary<string, string>
            {
                {SurfaceFormHelper.ReservedAdditionalKeys.Controller, "foo"},
                {SurfaceFormHelper.ReservedAdditionalKeys.Action, "bar"}
            });

            Assert.Equal(false, result);
        }