Ejemplo n.º 1
0
        public static T CreateApi <T>(string dataseed, string usercode) where T : BaseApiController, new()
        {
            var _controller = new T();

            _controller.DC = new DataContext(dataseed, DBTypeEnum.Memory);
            Mock <HttpContext> mockHttpContext = new Mock <HttpContext>();
            MockHttpSession    mockSession     = new MockHttpSession();

            mockHttpContext.Setup(s => s.Session).Returns(mockSession);
            Mock <IServiceProvider> mockService = new Mock <IServiceProvider>();

            mockService.Setup(x => x.GetService(typeof(GlobalData))).Returns(new GlobalData());
            mockService.Setup(x => x.GetService(typeof(Configs))).Returns(new Configs());
            mockService.Setup(x => x.GetService(typeof(IDistributedCache))).Returns(new MemoryDistributedCache(Options.Create <MemoryDistributedCacheOptions>(new MemoryDistributedCacheOptions())));
            GlobalServices.SetServiceProvider(mockService.Object);
            _controller.ControllerContext.HttpContext = mockHttpContext.Object;
            _controller.Cache         = new MemoryDistributedCache(Options.Create <MemoryDistributedCacheOptions>(new MemoryDistributedCacheOptions()));
            _controller.LoginUserInfo = new LoginUserInfo {
                ITCode = usercode ?? "user"
            };
            _controller.ConfigInfo = new Configs();
            _controller.GlobaInfo  = new GlobalData();
            _controller.GlobaInfo.AllAccessUrls = new List <string>();
            _controller.GlobaInfo.AllAssembly   = new List <System.Reflection.Assembly>();
            _controller.GlobaInfo.AllModels     = new List <Type>();
            _controller.GlobaInfo.SetModuleGetFunc(() => new List <FrameworkModule>());
            return(_controller);
        }
Ejemplo n.º 2
0
        public static T CreateApi <T>(IDataContext dataContext, string usercode) where T : BaseApiController, new()
        {
            var _controller = new T();

            _controller.Wtm = MockWtmContext.CreateWtmContext(dataContext, usercode);
            Mock <HttpContext> mockHttpContext = new Mock <HttpContext>();
            MockHttpSession    mockSession     = new MockHttpSession();

            mockHttpContext.Setup(s => s.Session).Returns(mockSession);
            mockHttpContext.Setup(x => x.Request).Returns(new DefaultHttpContext().Request);
            _controller.ControllerContext.HttpContext = mockHttpContext.Object;
            _controller.Wtm.MSD = new ModelStateServiceProvider(_controller.ModelState);
            return(_controller);
        }
Ejemplo n.º 3
0
        public static WTMContext CreateWtmContext(IDataContext dataContext = null, string usercode = null)
        {
            GlobalData gd = new GlobalData();

            gd.AllAccessUrls = new List <string>();
            gd.AllAssembly   = new List <System.Reflection.Assembly>();
            gd.AllModule     = new List <WalkingTec.Mvvm.Core.Support.Json.SimpleModule>();

            Mock <HttpContext>      mockHttpContext = new Mock <HttpContext>();
            Mock <HttpRequest>      mockHttpRequest = new Mock <HttpRequest>();
            Mock <IServiceProvider> mockService     = new Mock <IServiceProvider>();
            MockHttpSession         mockSession     = new MockHttpSession();

            mockHttpRequest.Setup(x => x.Cookies).Returns(new MockCookie());
            mockService.Setup(x => x.GetService(typeof(IDistributedCache))).Returns(new MemoryDistributedCache(Options.Create <MemoryDistributedCacheOptions>(new MemoryDistributedCacheOptions())));
            mockHttpContext.Setup(x => x.Request).Returns(mockHttpRequest.Object);
            mockHttpContext.Setup(x => x.RequestServices).Returns(mockService.Object);
            var httpa = new HttpContextAccessor();

            httpa.HttpContext = mockHttpContext.Object;
            var wtmcontext = new WTMContext(null, new GlobalData(), httpa, new DefaultUIService(), null, dataContext, new ResourceManagerStringLocalizerFactory(Options.Create <LocalizationOptions>(new LocalizationOptions {
                ResourcesPath = "Resources"
            }), new Microsoft.Extensions.Logging.LoggerFactory()));

            wtmcontext.MSD     = new BasicMSD();
            wtmcontext.Session = new SessionServiceProvider(mockSession);
            if (dataContext == null)
            {
                wtmcontext.DC = new EmptyContext(Guid.NewGuid().ToString(), DBTypeEnum.Memory);
            }
            else
            {
                wtmcontext.DC = dataContext;
            }
            wtmcontext.LoginUserInfo = new LoginUserInfo {
                ITCode = usercode ?? "user"
            };
            wtmcontext.GlobaInfo.AllAccessUrls = new List <string>();
            wtmcontext.GlobaInfo.AllAssembly   = new List <System.Reflection.Assembly>();
            wtmcontext.GlobaInfo.AllModule     = new List <WalkingTec.Mvvm.Core.Support.Json.SimpleModule>();
            mockService.Setup(x => x.GetService(typeof(WtmFileProvider))).Returns(new WtmFileProvider(wtmcontext));
            return(wtmcontext);
        }