示例#1
0
        public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            //var user = _userService.Authenticate(userModel.UserName, userModel.Password);

            var _handler = new ServiceHandlerFactory();

            //var clients = _CacheManager.Get<IEnumerable<ClientRefInfo>>("Client Info", () => getClients());


            var UserInfo = _handler
                           .Using <IUserCredentials>()
                           .GetUserInfo(context.UserName, context.Password);

            if (UserInfo == null)
            {
                context.Rejected();
            }
            else
            {
                context.OwinContext.Set <string>("as:UserId", UserInfo.FindFirst("UserId").Value);
                var ticket = new AuthenticationTicket(UserInfo, new AuthenticationProperties());
                context.Validated(ticket);
            }

            return(Task.FromResult <object>(null));
        }
示例#2
0
        public string ExecuteService(WebContext context)
        {
            ServiceHandlerFactory factory = new ServiceHandlerFactory();
            IHttpHandler          handler = factory.GetHandler(context.HttpContext, null, null, null);

            handler.ProcessRequest(context.HttpContext);

            return(context.Response.GetText());
        }
示例#3
0
        public void Test_Dynamic_Handler()
        {
            Assert.True(true);

            return;

            var _ServiceHandlerFactory = new ServiceHandlerFactory();

            var g = testEngineHandler.Registrations;

            var Mockedit
                = new Moq.Mock <ServiceHandlerFactory>()
                {
                CallBase = true
                };

            var ServiceInterface = new Moq.Mock <IServiceGenericHandler>()
            {
                CallBase = true
            };


            var dataCategories = new List <Category>
            {
                new TestCategory {
                    CategoryName = new DomainEntityTypeString {
                        Value = "AAA"
                    }
                },
                new TestCategory {
                    CategoryName = new DomainEntityTypeString {
                        Value = "BBB"
                    }
                },
                new TestCategory {
                    CategoryName = new DomainEntityTypeString {
                        Value = "ZZZ"
                    }
                }
            }.AsQueryable();

            _ServiceHandlerFactory
            .Using <IServiceGenericHandler>()
            .GetData <ISubCategoryAttribute>();

            //s.Save(It.IsAny<ModelStateDictionary>())).Returns(true);

            //_ServiceHandlerFactory IServiceGenericHandler
            // var subAttributes = Mockedit.Object
            //                    .Using<IServiceGenericHandler>();

            var d = ServiceInterface
                    .Object
                    .GetData <ISubCategoryAttribute>();

            // .GetData<ISubCategoryAttribute>();
        }
        public void Test3()
        {
            string requestText = @"
POST http://www.fish-web-demo.com/DataTypeTest/xxxxxxxxxxx HTTP/1.1
";
            // 上面URL指定了一个ServiceHandlerFactory不能接受的格式,会引发404错误

            IHttpHandler handler = null;

            using (WebContext context = WebContext.FromRawText(requestText)) {
                var factory = new ServiceHandlerFactory();
                handler = factory.GetHandler(context.HttpContext, "POST", null, null);
            }
        }
示例#5
0
        public void Test2()
        {
            string requestText = @"
POST http://www.fish-mvc-demo.com/Ajax/test/DataTypeTest/xxxxxxxxxxx.aspx HTTP/1.1
";
            // 上面URL指定了一个不存在的Action名称,会引发404错误

            IHttpHandler handler = null;

            using (WebContext context = WebContext.FromRawText(requestText)) {
                var factory = new ServiceHandlerFactory();
                handler = factory.GetHandler(context.HttpContext, "POST", null, null);
            }
        }
示例#6
0
        IEnumerable <Repos.Owin.Models.ClientRefInfo> getClients()
        {
            var _handler = new ServiceHandlerFactory();

            return(_handler
                   .Using <IUserCredentials>()
                   .GetClients()
                   .Select(s => new Repos.Owin.Models.ClientRefInfo()
            {
                AssmPrefix = s.AssmPrefix
                , ExtClientId = s.ExtClientId
                , ClientId = s.Id
                , ClientKey = s.ClientKey
            }));
        }
        public void Test1()
        {
            string       requestText = @"
POST http://www.fish-web-demo.com/Ajax/test/DataTypeTest/Input_int_Add.aspx HTTP/1.1
";
            IHttpHandler handler     = null;

            using (WebContext context = WebContext.FromRawText(requestText)) {
                var factory = new ServiceHandlerFactory();
                handler = factory.GetHandler(context.HttpContext, "POST", null, null);

                // 下面这个调用没什么意义,只是为了覆盖代码
                factory.ReleaseHandler(handler);
            }
            Assert.IsNotNull(handler);
        }
示例#8
0
        public async Task <string> AsyncExecuteService(string requestText)
        {
            using (WebContext context = WebContext.FromRawText(requestText)) {
                ServiceHandlerFactory factory = new ServiceHandlerFactory();
                IHttpHandler          handler = factory.GetHandler(context.HttpContext, null, null, null);

                HttpTaskAsyncHandler taskHandler = handler as HttpTaskAsyncHandler;
                if (taskHandler == null)
                {
                    throw new InvalidOperationException();
                }

                await taskHandler.ProcessRequestAsync(context.HttpContext);

                return(context.Response.GetText());
            }
        }
        public void Test2()
        {
            string requestText = @"
POST http://www.fish-mvc-demo.com/Ajax/test/DataTypeTest/xxxxxxxxxxx.aspx HTTP/1.1
";
            // 上面URL指定了一个不存在的Action名称,会引发404错误

            IHttpHandler       handler     = null;
            Http404DebugModule debugModule = new Http404DebugModule();

            using (WebContext context = WebContext.FromRawText(requestText)) {
                debugModule.app_BeginRequest(context.Application.Instance, null);

                var factory = new ServiceHandlerFactory();
                handler = factory.GetHandler(context.HttpContext, "POST", null, null);
            }

            Assert.IsInstanceOfType(handler, typeof(Http404PageHandler));
        }
示例#10
0
        public void Test()
        {
            // 正常场景测试

            string requestText = @"
GET http://www.fish-mvc-demo.com/Ajax/test/DataTypeTest/Input_string_ToUpper.aspx?input=fish HTTP/1.1
";

            using (WebContext context = WebContext.FromRawText(requestText)) {
                TextResult text = new TextResult("abc");

                DateTime        lastModified = new DateTime(2015, 5, 3);
                HttpCacheResult result       = new HttpCacheResult(text, 100, lastModified);
                result.ETag = "123456789";


                ServiceHandlerFactory factory = new ServiceHandlerFactory();
                IHttpHandler          handler = factory.GetHandler(context.HttpContext, null, null, null);

                context.HttpContext.Handler = handler;

                ActionExecutor executor = new ActionExecutor();
                executor.SetValue("HttpContext", context.HttpContext);

                handler.SetValue("ActionExecutor", executor);


                result.Ouput(context.HttpContext);

                Assert.AreEqual("abc", context.Response.GetText());

                var responseCache = context.HttpContext.Response.Cache;
                Assert.AreEqual("Public", responseCache.GetValue("_cacheability").ToString());
                Assert.AreEqual("max-age=100", responseCache.GetValue("_cacheExtension").ToString());
                Assert.AreEqual("123456789", responseCache.GetValue("_etag").ToString());
                Assert.AreEqual(true, (bool)responseCache.GetValue("_isLastModifiedSet"));
                Assert.AreEqual(lastModified.ToUniversalTime(), (DateTime)responseCache.GetValue("_utcLastModified"));
            }
        }