Exemple #1
0
        public void Set()
        {
            var key   = Guid.NewGuid().ToString();
            var value = StubRequest.GetRequest();

            _cache.Set(key, value, TimeSpan.FromSeconds(2));

            Assert.IsTrue(_cache.Exists(key));
            Assert.IsTrue(_cacheL1.Exists(key));
            Assert.IsTrue(_cacheL2.Exists(key));
            var retrievedValue1 = _cache.Get <StubRequest>(key);

            Thread.Sleep(_cacheL1ExpirationMsecs);

            Assert.IsTrue(_cache.Exists(key));
            Assert.IsFalse(_cacheL1.Exists(key));
            Assert.IsTrue(_cacheL2.Exists(key));
            var retrievedValue2 = _cache.Get <StubRequest>(key);

            Assert.AreEqual(value.CreatedOn, retrievedValue1.CreatedOn);
            Assert.AreEqual(value.Id, retrievedValue1.Id);
            Assert.AreEqual(value.Name, retrievedValue1.Name);

            Assert.AreEqual(value.CreatedOn, retrievedValue2.CreatedOn);
            Assert.AreEqual(value.Id, retrievedValue2.Id);
            Assert.AreEqual(value.Name, retrievedValue2.Name);
        }
        public virtual void Init()
        {
            mocks = new MockRepository();

            var services = new StubMonoRailServices();

            services.ViewSourceLoader = new FileAssemblyViewSourceLoader("MonoRail.Tests.Views");
            services.AddService(typeof(IViewSourceLoader), services.ViewSourceLoader);

            viewComponentFactory = new DefaultViewComponentFactory();
            viewComponentFactory.Initialize();
            services.AddService(typeof(IViewComponentFactory), viewComponentFactory);
            services.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry);

            var settings = new SparkSettings();

            engine = new SparkViewEngine(settings);
            services.AddService(typeof(ISparkViewEngine), engine);

            factory = new SparkViewFactory();
            factory.Service(services);

            controller        = MockRepository.GenerateMock <IController>();
            controllerContext = new ControllerContext();
            var request = new StubRequest();

            request.FilePath = "";
            var response = new StubResponse();

            engineContext = new StubEngineContext(request, response, new UrlInfo("", "Home", "Index", "/", "castle"));
            engineContext.AddService(typeof(IViewComponentFactory), viewComponentFactory);
            engineContext.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry);
        }
Exemple #3
0
 public void Init()
 {
     request       = new StubRequest();
     response      = new StubResponse();
     services      = new StubMonoRailServices();
     engineContext = new StubEngineContext(request, response, services, null);
 }
		public void Init()
		{
			request = new StubRequest();
			response = new StubResponse();
			services = new StubMonoRailServices();
			engineContext = new StubEngineContext(request, response, services, null);
		}
        public void ToTraceString_NullParameters()
        {
            var req    = StubRequest.GetRequest();
            var count  = _random.Next();
            var actual = MethodInvocationStub.GetNullParametersProxyMock().ToTraceString(_serializer);

            Assert.AreEqual("MethodInvocationStub.NoParmsMethod", actual);
        }
		public void Init()
		{
			var request = new StubRequest();
			response = new StubResponse();
			services = new StubMonoRailServices();
			engStubViewEngineManager = new StubViewEngineManager();
			services.ViewEngineManager = engStubViewEngineManager;
			engineContext = new StubEngineContext(request, response, services, null);
		}
Exemple #7
0
        public void Set_ThenRemove()
        {
            var key   = Guid.NewGuid().ToString();
            var value = StubRequest.GetRequest();

            _cache.Set(key, value);
            Assert.IsTrue(_cache.Exists(key));
            _cache.Remove(key);
            Assert.IsFalse(_cache.Exists(key));
        }
        public void ToTraceString_Xml()
        {
            var req            = StubRequest.GetRequest();
            var count          = _random.Next();
            var actual         = MethodInvocationStub.GetProxyMock(req, count).ToTraceString(Serializer.Default.Xml);
            var expectedFormat = @"MethodInvocationStub.StubMethod <StubRequest xmlns=""http://schemas.datacontract.org/2004/07/Sixeyed.Caching.Tests.Stubs"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance""><CreatedOn>{0}T00:00:00Z</CreatedOn><Id>{1}</Id><Name>{2}</Name></StubRequest>_<int xmlns=""http://schemas.microsoft.com/2003/10/Serialization/"">{3}</int>";
            var expected       = string.Format(expectedFormat, req.CreatedOn.ToString("yyyy-MM-dd"), req.Id, req.Name, count);

            Assert.AreEqual(expected, actual);
        }
        public void ToTraceString()
        {
            var req            = StubRequest.GetRequest();
            var count          = _random.Next();
            var actual         = MethodInvocationStub.GetProxyMock(req, count).ToTraceString(_serializer);
            var expectedFormat = @"MethodInvocationStub.StubMethod request: {0}""Id"":{1},""Name"":""{2}"",""CreatedOn"":""{3}T00:00:00Z""{4}, count: {5}";
            var expected       = string.Format(expectedFormat, "{", req.Id, req.Name, req.CreatedOn.ToString("yyyy-MM-dd"), "}", count);

            Assert.AreEqual(expected, actual);
        }
Exemple #10
0
        public void Init()
        {
            selector = new DefaultActionSelector();

            var request  = new StubRequest();
            var response = new StubResponse();
            var services = new StubMonoRailServices();

            engine = new StubEngineContext(request, response, services, new UrlInfo("area", "controller", "action1"));
        }
Exemple #11
0
        public void Set()
        {
            var cache = Cache.Get(CacheType.Null);
            var key   = Guid.NewGuid().ToString();
            var value = StubRequest.GetRequest();

            cache.Set(key, value);
            Assert.IsFalse(cache.Exists(key));
            var retrievedValue = cache.Get <StubRequest>(key);
        }
        public void Init()
        {
            var request = new StubRequest();

            response = new StubResponse();
            services = new StubMonoRailServices();
            engStubViewEngineManager   = new StubViewEngineManager();
            services.ViewEngineManager = engStubViewEngineManager;
            engineContext = new StubEngineContext(request, response, services, null);
        }
Exemple #13
0
        public void Set_WithSlidingExpiry()
        {
            var cache    = Cache.Get(CacheType.Null);
            var key      = Guid.NewGuid().ToString();
            var value    = StubRequest.GetRequest();
            var lifespan = new TimeSpan(0, 0, 0, 0, 250);

            cache.Set(key, value, lifespan);
            Assert.IsFalse(cache.Exists(key));
            var retrievedValue = cache.Get <StubRequest>(key);
        }
Exemple #14
0
        public void Set_WithAbsoluteExpiry()
        {
            var cache     = Cache.Get(CacheType.Null);
            var key       = Guid.NewGuid().ToString();
            var value     = StubRequest.GetRequest();
            var expiresAt = DateTime.Now.AddMilliseconds(250);

            cache.Set(key, value, expiresAt);
            Assert.IsFalse(cache.Exists(key));
            var retrievedValue = cache.Get <StubRequest>(key);
        }
		public void Init()
		{
			var request = new StubRequest();
			var response = new StubResponse();
			services = new StubMonoRailServices();
			engStubViewEngineManager = new StubViewEngineManager();
			services.ViewEngineManager = engStubViewEngineManager;
			filterFactoryMock = mockRepository.DynamicMock<IFilterFactory>();
			services.FilterFactory = filterFactoryMock;
			engineContext = new StubEngineContext(request, response, services, null);
		}
Exemple #16
0
        public void Set_WithAbsoluteExpiry()
        {
            var key       = Guid.NewGuid().ToString();
            var value     = StubRequest.GetRequest();
            var expiresAt = DateTime.Now.AddMilliseconds(250);

            Cache.NCacheExpress.Set(key, value, expiresAt);
            Assert.IsTrue(Cache.NCacheExpress.Exists(key));
            Thread.Sleep(2000);
            Assert.IsFalse(Cache.NCacheExpress.Exists(key));
        }
Exemple #17
0
        public void Set_ThenRemove()
        {
            var cache = Cache.Get(CacheType.Null);
            var key   = Guid.NewGuid().ToString();
            var value = StubRequest.GetRequest();

            cache.Set(key, value);
            Assert.IsFalse(cache.Exists(key));
            cache.Remove(key);
            Assert.IsFalse(cache.Exists(key));
        }
Exemple #18
0
        public void Set_Null()
        {
            var         key   = Guid.NewGuid().ToString();
            StubRequest value = null;

            Assert.IsFalse(Cache.AspNet.Exists(key));
            Cache.AspNet.Set(key, value);
            Assert.IsTrue(Cache.AspNet.Exists(key));
            var retrievedValue = Cache.AspNet.Get <StubRequest>(key);

            Assert.IsNull(retrievedValue);
        }
        public void Init()
        {
            var request  = new StubRequest();
            var response = new StubResponse();

            services = new StubMonoRailServices();
            engStubViewEngineManager   = new StubViewEngineManager();
            services.ViewEngineManager = engStubViewEngineManager;
            filterFactoryMock          = mockRepository.DynamicMock <IFilterFactory>();
            services.FilterFactory     = filterFactoryMock;
            engineContext = new StubEngineContext(request, response, services, null);
        }
		public void Init()
		{
			resourceFactoryMock = mockRepository.DynamicMock<IResourceFactory>();

			StubRequest request = new StubRequest();
			StubResponse response = new StubResponse();
			services = new StubMonoRailServices();
			engStubViewEngineManager = new StubViewEngineManager();
			services.ViewEngineManager = engStubViewEngineManager;
			services.ResourceFactory = resourceFactoryMock;
			engineContext = new StubEngineContext(request, response, services, null);
		}
Exemple #21
0
        public void Set_WithAbsoluteExpiry()
        {
            var key   = Guid.NewGuid().ToString();
            var value = StubRequest.GetRequest();
            //minimum expiry for disk cache is 1 second:
            var expiresAt = DateTime.Now.AddMilliseconds(1250);

            _cache.Set(key, value, expiresAt);
            Assert.IsTrue(_cache.Exists(key));
            Thread.Sleep(1500);
            Assert.IsFalse(_cache.Exists(key));
        }
        public void ThenCheckBlacklistHtmlElements(string text)
        {
            var request = new StubRequest {
                TestString = text
            };
            var sut = new TestMatchesAllowedHtmlFreeTextCharactersValidator();

            var result = sut.Validate(request);

            result.IsValid.Should().BeFalse();
            result.Errors.First().ErrorCode.Should().Be(ErrorCode);
        }
        public void ThenCheckValidCharacters()
        {
            var validChars = GetValidCharacters();
            var request    = new StubRequest {
                TestString = validChars
            };
            var sut = new TestMatchesAllowedHtmlFreeTextCharactersValidator();

            var result = sut.Validate(request);

            result.IsValid.Should().BeTrue();
        }
        public void CanGetItemByIdFromRequest()
        {
            var fetcher   = new ARFetcher(new DefaultConverter());
            var parameter = typeof(MyController).GetMethod("MyAction").GetParameters()[0];
            var attribute = (ARFetchAttribute)parameter.GetCustomAttributes(typeof(ARFetchAttribute), true)[0];
            var request   = new StubRequest();

            request.Params["id"] = account1.Id.ToString();
            var record = (Account)fetcher.FetchActiveRecord(
                parameter, attribute, request, new Dictionary <string, object>());

            Assert.AreEqual(account1.Id, record.Id);
        }
Exemple #25
0
        public void Set()
        {
            var key   = Guid.NewGuid().ToString();
            var value = StubRequest.GetRequest();

            _cache.Set(key, value);
            Assert.IsTrue(_cache.Exists(key));
            var retrievedValue = _cache.Get <StubRequest>(key);

            Assert.AreEqual(value.CreatedOn, retrievedValue.CreatedOn);
            Assert.AreEqual(value.Id, retrievedValue.Id);
            Assert.AreEqual(value.Name, retrievedValue.Name);
        }
Exemple #26
0
		public void CanBindPrimaryKeyToEmptyGuid()
		{
			Tag tag = new Tag() { Id = Guid.Empty, Name = "TopMovie" };
			tag.Create();

			var request = new StubRequest();
			request.Params["tag.id"] = Guid.Empty.ToString();

			var binder = new ARDataBinder { AutoLoad = AutoLoadBehavior.Always, TreatEmptyGuidAsNull = false};
			
			var record = (Tag)binder.BindObject(typeof(Tag), "tag", request.ParamsNode);
	
			Assert.AreEqual(tag.Id, record.Id);
		}
		public void Init()
		{
			StubRequest request = new StubRequest();
			response = new StubResponse();
			StubMonoRailServices services = new StubMonoRailServices();
			engStubViewEngineManager = new StubViewEngineManager();
			services.ViewEngineManager = engStubViewEngineManager;
			engineContext = new StubEngineContext(request, response, services, new UrlInfo("area", "controller", "action"));

			generator = new JQueryAjaxProxyGenerator();
			generator.ControllerTree = services.ControllerTree;
			generator.ControllerDescriptorBuilder = services.ControllerDescriptorProvider;

			services.ControllerTree.AddController("area", "controller1", typeof(NoAjaxController));
			services.ControllerTree.AddController("", "controller2", typeof(AjaxController));
		}
Exemple #28
0
        public void ExecutesActionAndReturnValue()
        {
            var controller = new BaseController();
            var actionMeta = new ActionMetaDescriptor();

            var executor = new ActionMethodExecutor(GetActionMethod(controller), actionMeta);

            var            req           = new StubRequest();
            var            res           = new StubResponse();
            var            services      = new StubMonoRailServices();
            IEngineContext engineContext = new StubEngineContext(req, res, services, new UrlInfo("area", "controller", "action"));
            var            retVal        = executor.Execute(engineContext, controller, new ControllerContext());

            Assert.IsTrue(controller.WasExecuted);
            Assert.AreEqual(1, retVal);
        }
Exemple #29
0
        public void DelegatesToDynamicAction()
        {
            var dynAction = new ActionStub();

            var executor = new DynamicActionExecutor(dynAction);

            var            req           = new StubRequest();
            var            res           = new StubResponse();
            var            services      = new StubMonoRailServices();
            IEngineContext engineContext = new StubEngineContext(req, res, services, new UrlInfo("area", "controller", "action"));

            var retVal = executor.Execute(engineContext, new DummyController(), new ControllerContext());

            Assert.IsTrue(dynAction.WasExecuted);
            Assert.AreEqual(3, retVal);
        }
Exemple #30
0
        public void Set_WithSlidingExpiry()
        {
            var key      = Guid.NewGuid().ToString();
            var value    = StubRequest.GetRequest();
            var lifespan = new TimeSpan(0, 0, 0, 0, 250);

            Cache.AspNet.Set(key, value, lifespan);
            Assert.IsTrue(Cache.AspNet.Exists(key));
            Thread.Sleep(200);
            var retrieved = Cache.AspNet.Get <StubRequest>(key);

            Assert.IsNotNull(retrieved);

            Thread.Sleep(50);
            Assert.IsFalse(Cache.AspNet.Exists(key));
        }
Exemple #31
0
        public void Set()
        {
            var key   = Guid.NewGuid().ToString();
            var value = StubRequest.GetRequest();

            _cache.Set(key, value);
            Assert.IsTrue(_cache.Exists(key));
            var retrievedValue = _cache.Get <StubRequest>(key);

            Assert.AreEqual(value.CreatedOn, retrievedValue.CreatedOn);
            Assert.AreEqual(value.Id, retrievedValue.Id);
            Assert.AreEqual(value.Name, retrievedValue.Name);
            //verify the item is encrypted:
            var cachedItem = File.ReadAllText(Path.Combine(CacheConfiguration.Current.DiskCache.Path, key + ".cache"));

            Assert.IsFalse(cachedItem.Contains(value.Name));
        }
Exemple #32
0
        public void Set_WithTimeoutExpiry()
        {
            var key      = Guid.NewGuid().ToString();
            var value    = StubRequest.GetRequest();
            var lifespan = new TimeSpan(0, 0, 0, 1, 250);

            _cache.Set(key, value, lifespan);
            Assert.IsTrue(_cache.Exists(key));
            Thread.Sleep(200);
            var retrieved = _cache.Get <StubRequest>(key);

            Assert.IsNotNull(retrieved);

            Thread.Sleep(2000);
            Assert.IsFalse(_cache.Exists(key));
            retrieved = _cache.Get <StubRequest>(key);
        }
        public void CompatibleExecutorDelegatesInvocationToControllerUsingDelegate()
        {
            var controller = new BaseController();
            var actionMeta = new ActionMetaDescriptor();

            ActionMethodExecutorCompatible.InvokeOnController delegateToController = controller.InvokeMethodStub;

            var executor =
                new ActionMethodExecutorCompatible(GetActionMethod(controller), actionMeta, delegateToController);

            var            req           = new StubRequest();
            var            res           = new StubResponse();
            var            services      = new StubMonoRailServices();
            IEngineContext engineContext = new StubEngineContext(req, res, services, new UrlInfo("area", "controller", "action"));
            var            retVal        = executor.Execute(engineContext, controller, new ControllerContext());

            Assert.IsTrue(controller.WasExecuted);
            Assert.AreEqual(2, retVal);
        }
        private static RequestContext CreateRequestContext(String adapterName, String method)
        {
            var stubHttpContext = new StubContext();
            var routeData = new RouteData();
            routeData.Values.Add("adapter", adapterName);

            var requestContext = new RequestContext(stubHttpContext, routeData);
                        
            var request = new StubRequest();

            request.SetRawUrl(adapterName);
            request.SetPath(adapterName);
            request.SetHttpMethod(method);

            stubHttpContext.SetRequest(request);
            stubHttpContext.SetResponse(new StubResponse());

            return requestContext;
        }
Exemple #35
0
        public void Init()
        {
            var request = new StubRequest();

            response = new StubResponse();
            var services = new StubMonoRailServices();

            engStubViewEngineManager   = new StubViewEngineManager();
            services.ViewEngineManager = engStubViewEngineManager;
            engineContext = new StubEngineContext(request, response, services, new UrlInfo("area", "controller", "action"));

            generator = new PrototypeAjaxProxyGenerator
            {
                ControllerTree = services.ControllerTree,
                ControllerDescriptorBuilder = services.ControllerDescriptorProvider
            };

            services.ControllerTree.AddController("area", "controller1", typeof(NoAjaxController));
            services.ControllerTree.AddController("", "controller2", typeof(AjaxController));
        }
Exemple #36
0
        public void Set_ThenRemoveAll()
        {
            var key1   = Guid.NewGuid().ToString();
            var value1 = StubRequest.GetRequest();

            Cache.AspNet.Set(key1, value1);

            var key2   = Guid.NewGuid().ToString();
            var value2 = StubRequest.GetRequest();

            Cache.AspNet.Set(key2, value2);

            Assert.IsTrue(Cache.AspNet.Exists(key1));
            Assert.IsTrue(Cache.AspNet.Exists(key2));

            Cache.AspNet.RemoveAll();

            Assert.IsFalse(Cache.AspNet.Exists(key1));
            Assert.IsFalse(Cache.AspNet.Exists(key2));
        }
Exemple #37
0
        public void Set_ThenGetAll()
        {
            var key1   = Guid.NewGuid().ToString();
            var value1 = StubRequest.GetRequest();

            Cache.AspNet.Set(key1, value1);

            var key2   = Guid.NewGuid().ToString();
            var value2 = StubRequest.GetRequest();

            Cache.AspNet.Set(key2, value2);

            var all = Cache.AspNet.GetAll <StubRequest>();

            Assert.IsNotNull(all);
            Assert.AreEqual(2, all.Count());
            Assert.IsTrue(all.ContainsKey(key1));
            Assert.AreEqual(value1.Id, all[key1].Id);
            Assert.IsTrue(all.ContainsKey(key2));
            Assert.AreEqual(value2.Id, all[key2].Id);
        }
Exemple #38
0
 public StubContext(string relativeUrl)
 {
     request = new StubRequest(relativeUrl);
 }
        private static RequestContext CreateRequestContext(String adapterName, String method, String httpVerb = "GET", String query = null, String id = null)
        {
            var stubHttpContext = new StubContext();
            var routeData = new RouteData();
            routeData.Values.Add("adapter", adapterName);
            routeData.Values.Add("method", method);

            if (id != null)
            {
                routeData.Values.Add("id", id);
            }

            var requestContext = new RequestContext(stubHttpContext, routeData);

            var request = new StubRequest();

            request.SetRawUrl(adapterName);
            request.SetPath(adapterName);
            request.SetHttpMethod(httpVerb);
            request.SetQueryString(query);

            stubHttpContext.SetRequest(request);
            stubHttpContext.SetResponse(new StubResponse());

            return requestContext;
        }