Esempio n. 1
0
        public NetfluidHost()
        {
            listener = new HttpListener();

            lock (instances)
            {
                instances.Add(this);
            }

            OnException = (c, e) =>
            {
                var ex = e;
                var sb = new StringBuilder();

                while (ex != null)
                {
                    sb.Append(ex.Message + "<br/>" + ex.StackTrace + "<br/>");
                    ex = ex.InnerException;
                }
                return(sb.ToString());
            };

            Logger   = new Logging.NullLogger();
            Filters  = new RouteCollection();
            Triggers = new RouteCollection();
            Routes   = new RouteCollection();

            PublicFolders = new List <IPublicFolder>();
            Sessions      = new DefaultSessionManager();

            StartTime = DateTime.Now;
        }
		public override void OnSetUp()
		{
			sessionStore = new CallContextSessionStore();
			kernel = mockRepository.DynamicMock<IKernel>();
			factoryResolver = mockRepository.DynamicMock<ISessionFactoryResolver>();
			transactionManager = mockRepository.DynamicMock<ITransactionManager>();
			transaction = mockRepository.DynamicMock<ITransaction>();
			sessionFactory = mockRepository.DynamicMock<ISessionFactory>();
			session = mockRepository.DynamicMock<ISession>();
			contextDictionary = new Hashtable();
			sessionManager = new DefaultSessionManager(sessionStore, kernel, factoryResolver);
		}
 public override void OnSetUp()
 {
     sessionStore       = new CallContextSessionStore();
     kernel             = mockRepository.DynamicMock <IKernel>();
     factoryResolver    = mockRepository.DynamicMock <ISessionFactoryResolver>();
     transactionManager = mockRepository.DynamicMock <ITransactionManager>();
     transaction        = mockRepository.DynamicMock <ITransaction>();
     sessionFactory     = mockRepository.DynamicMock <ISessionFactory>();
     session            = mockRepository.DynamicMock <ISession>();
     statelessSession   = mockRepository.DynamicMock <IStatelessSession>();
     contextDictionary  = new Hashtable();
     sessionManager     = new DefaultSessionManager(sessionStore, kernel, factoryResolver);
 }
        /// <summary>
        /// build a restful app
        /// </summary>
        /// <returns></returns>
        public RestfulApplication Build()
        {
            if (RestfulApplicationGlobalConfig.EnableSystemApi)
            {
                RestfulApplicationBaseComponents.RestfulServiceMetaDataManager.AddRestfulService(typeof(RestfulServiceManager));
                RestfulApplicationBaseComponents.ServicePovider.AddSigleton(typeof(RestfulServiceManager), RestfulApplicationBaseComponents.RestfulServiceManager);
            }


            if (RestfulApplicationGlobalConfig.UseDashBorad)
            {
                RestfulApplicationBaseComponents.RestfulServiceMetaDataManager.AddRestfulService(typeof(LoginService));
                RestfulApplicationBaseComponents.RestfulServiceMetaDataManager.AddRestfulService(typeof(XmlStoreUserManager));

                var userManager = new XmlStoreUserManager();



                userManager.CreateGroup("admins", AuthenticateLevel.SupperAdmin);
                userManager.CreateUser("fuanlei", "001", "admins");
                var sessionManager = new DefaultSessionManager();

                RestfulApplicationBaseComponents.ServicePovider.AddSigleton(typeof(XmlStoreUserManager), userManager);


                RestfulApplicationBaseComponents.ServicePovider.AddSigleton(typeof(AfterLoginFilter), new AfterLoginFilter(sessionManager, userManager));

                RestfulApplicationBaseComponents.ServicePovider.AddSigleton(typeof(SessionValidateFilter), new SessionValidateFilter(sessionManager));
                RestfulApplicationBaseComponents.ServicePovider.AddSigleton(typeof(LoginService), new LoginService(userManager));
                RestfulApplicationBaseComponents.ServicePovider.AddSigleton(typeof(AuthenticateFilter), new AuthenticateFilter(AuthenticateLevel.SupperAdmin));
            }


            /* generate all service processor instance */
            foreach (var item in RestfulApplicationBaseComponents.RestfulServiceMetaDataManager)
            {
                foreach (var restful in RestfulApplicationBaseComponents.ProcessorGenerator.Generate(item.Value))
                {
                    RestfulApplicationBaseComponents.RestfulServiceManager.AddProcessor(restful.Path, restful);
                }
            }

            return(new RestfulApplication());
        }
Esempio n. 5
0
        public void Can_Add_And_Remove_Object_From_Session()
        {
            const string keyOne = "TEST_ONE";
            const string keyTwo = "TEST_TWO";

            Song[] songs = new Song[] { new Song()
                                        {
                                            SongId = 1, NameSong = "Test1"
                                        },
                                        new Song()
                                        {
                                            SongId = 2, NameSong = "Test2"
                                        },
                                        new Song()
                                        {
                                            SongId = 3, NameSong = "Test3"
                                        },
                                        new Song()
                                        {
                                            SongId = 4, NameSong = "Test4"
                                        } };

            List <CartItem> cartItems = new List <CartItem>()
            {
                new CartItem()
                {
                    Song = songs[0], Quantity = 1
                },
                new CartItem()
                {
                    Song = songs[1], Quantity = 1
                },
                new CartItem()
                {
                    Song = songs[2], Quantity = 1
                },
                new CartItem()
                {
                    Song = songs[3], Quantity = 1
                },
            };

            List <CartItem> diffrentCartItems = new List <CartItem>()
            {
                new CartItem()
                {
                    Song = songs[2], Quantity = 1
                },
                new CartItem()
                {
                    Song = songs[3], Quantity = 1
                }
            };


            ISessionManager manager = new DefaultSessionManager(FakeHttpContext());

            manager.Set <List <CartItem> >(keyOne, cartItems);
            manager.Set <List <CartItem> >(keyTwo, diffrentCartItems);

            Assert.IsInstanceOfType(manager.Get <List <CartItem> >(keyOne), typeof(List <CartItem>));
            Assert.AreEqual(cartItems, manager.Get <List <CartItem> >(keyOne));
            Assert.AreEqual(manager.Get <List <CartItem> >(keyOne).Count, 4);
            Assert.IsTrue(cartItems.Equals(manager.Get <List <CartItem> >(keyOne)));

            Assert.IsInstanceOfType(manager.TryGet <List <CartItem> >(keyTwo), typeof(List <CartItem>));
            Assert.AreEqual(diffrentCartItems, manager.TryGet <List <CartItem> >(keyTwo));
            Assert.AreEqual(manager.TryGet <List <CartItem> >(keyTwo).Count, 2);
            Assert.IsTrue(diffrentCartItems.Equals(manager.Get <List <CartItem> >(keyTwo)));

            manager.Remove <CartItem>(keyOne);
            manager.Remove <CartItem>(keyTwo);

            Assert.IsNull(manager.TryGet <List <CartItem> >(keyOne));
            Assert.IsNull(manager.Get <List <CartItem> >(keyTwo));
        }