Exemple #1
0
        public void Should_Have_304_Http_Status_Code_If_Response_Has_Modified_Since_Header_Matching_Page_Modified_Date()
        {
            // The file date and the browser date always match for a 304 status, the browser will never send back a more recent date,
            // i.e. "Has the file changed since this date I've stored for the last time it was changed?"
            // and *not* "has the file changed since the time right now?".

            // Arrange
            BrowserCacheAttribute attribute = new BrowserCacheAttribute();

            attribute.SettingsService = GetSettingsService();

            WikiController        controller    = CreateWikiController(attribute);
            ResultExecutedContext filterContext = CreateContext(controller);

            // (page modified date is set in CreateWikiController)
            filterContext.HttpContext.Request.Headers.Add("If-Modified-Since", DateTime.Today.ToString("r"));

            // Act
            attribute.OnResultExecuted(filterContext);

            // Assert
            HttpStatusCodeResult result = filterContext.Result as HttpStatusCodeResult;

            Assert.That(filterContext.HttpContext.Response.StatusCode, Is.EqualTo(304));
            Assert.That(result.StatusCode, Is.EqualTo(304));
            Assert.That(result.StatusDescription, Is.EqualTo("Not Modified"));
        }
        public void Should_Have_200_Http_Status_Code_If_No_Modified_Since_Header()
        {
            // Arrange
            BrowserCacheAttribute attribute = new BrowserCacheAttribute();
            attribute.SettingsService = GetSettingsService();

            WikiController controller = CreateWikiController(attribute);
            ResultExecutedContext filterContext = CreateContext(controller);

            // Act
            attribute.OnResultExecuted(filterContext);

            // Assert
            Assert.That(filterContext.HttpContext.Response.StatusCode, Is.EqualTo(200));
            Assert.That(filterContext.Result, Is.Not.TypeOf<HttpStatusCodeResult>());
        }
		public void should_not_set_viewresult_if_usebrowsercache_is_disabled()
		{
			// Arrange
			BrowserCacheAttribute attribute = new BrowserCacheAttribute();
			attribute.SettingsService = _settingsService;

			WikiController controller = CreateWikiController(attribute);
			ResultExecutedContext filterContext = CreateContext(controller);

			attribute.ApplicationSettings.UseBrowserCache = false;

			// Act
			attribute.OnResultExecuted(filterContext);

			// Assert
			Assert.That(filterContext.Result, Is.Not.TypeOf<HttpStatusCodeResult>());
		}
Exemple #4
0
        public void Should_Have_200_Http_Status_Code_If_No_Modified_Since_Header()
        {
            // Arrange
            BrowserCacheAttribute attribute = new BrowserCacheAttribute();

            attribute.SettingsService = GetSettingsService();

            WikiController        controller    = CreateWikiController(attribute);
            ResultExecutedContext filterContext = CreateContext(controller);

            // Act
            attribute.OnResultExecuted(filterContext);

            // Assert
            Assert.That(filterContext.HttpContext.Response.StatusCode, Is.EqualTo(200));
            Assert.That(filterContext.Result, Is.Not.TypeOf <HttpStatusCodeResult>());
        }
		public void Should_Not_Set_ViewResult_If_UseBrowserCache_Is_Disabled()
		{
			// Arrange
			BrowserCacheAttribute attribute = new BrowserCacheAttribute();
			attribute.SettingsService = GetSettingsService();

			WikiController controller = CreateWikiController(attribute);
			ResultExecutedContext filterContext = CreateContext(controller);

			attribute.ApplicationSettings.UseBrowserCache = false;

			// Act
			attribute.OnResultExecuted(filterContext);

			// Assert
			Assert.That(filterContext.Result, Is.Not.TypeOf<HttpStatusCodeResult>());
		}
		public void Should_Not_Set_ViewResult_If_User_Is_Logged_In()
		{
			// Arrange
			BrowserCacheAttribute attribute = new BrowserCacheAttribute();
			attribute.SettingsService = GetSettingsService();

			WikiController controller = CreateWikiController(attribute);
			ResultExecutedContext filterContext = CreateContext(controller);

			attribute.Context.CurrentUser = Guid.NewGuid().ToString();

			// Act
			attribute.OnResultExecuted(filterContext);

			// Assert
			Assert.That(filterContext.Result, Is.Not.TypeOf<HttpStatusCodeResult>());
		}
        public void should_have_200_http_status_code_if_no_modified_since_header()
        {
            // Arrange
            BrowserCacheAttribute attribute = new BrowserCacheAttribute();

            attribute.SettingsService = _settingsService;

            WikiController        controller    = CreateWikiController(attribute);
            ResultExecutedContext filterContext = CreateContext(controller);

            // Act
            attribute.OnResultExecuted(filterContext);

            // Assert
            Assert.That(filterContext.HttpContext.Response.StatusCode, Is.EqualTo(200));
            Assert.That(filterContext.Result, Is.Not.TypeOf <HttpStatusCodeResult>());
        }
Exemple #8
0
        public void Should_Not_Set_ViewResult_If_User_Is_Logged_In()
        {
            // Arrange
            BrowserCacheAttribute attribute = new BrowserCacheAttribute();

            attribute.SettingsService = GetSettingsService();

            WikiController        controller    = CreateWikiController(attribute);
            ResultExecutedContext filterContext = CreateContext(controller);

            attribute.Context.CurrentUser = Guid.NewGuid().ToString();

            // Act
            attribute.OnResultExecuted(filterContext);

            // Assert
            Assert.That(filterContext.Result, Is.Not.TypeOf <HttpStatusCodeResult>());
        }
Exemple #9
0
        public void Should_Not_Set_ViewResult_If_UseBrowserCache_Is_Disabled()
        {
            // Arrange
            BrowserCacheAttribute attribute = new BrowserCacheAttribute();

            attribute.SettingsService = GetSettingsService();

            WikiController        controller    = CreateWikiController(attribute);
            ResultExecutedContext filterContext = CreateContext(controller);

            attribute.ApplicationSettings.UseBrowserCache = false;

            // Act
            attribute.OnResultExecuted(filterContext);

            // Assert
            Assert.That(filterContext.Result, Is.Not.TypeOf <HttpStatusCodeResult>());
        }
        public void Should_Have_200_Http_Status_Code_If_PluginsSaved_After_Header_Last_Modified_Date()
        {
            // Arrange
            BrowserCacheAttribute attribute = new BrowserCacheAttribute();
            attribute.SettingsService = GetSettingsService();
            _repositoryMock.SiteSettings.PluginLastSaveDate = DateTime.UtcNow;

            WikiController controller = CreateWikiController(attribute);
            ResultExecutedContext filterContext = CreateContext(controller);
            filterContext.HttpContext.Request.Headers.Add("If-Modified-Since", DateTime.Today.ToString("r"));

            // Act
            attribute.OnResultExecuted(filterContext);

            // Assert
            Assert.That(filterContext.HttpContext.Response.StatusCode, Is.EqualTo(200));
            Assert.That(filterContext.Result, Is.Not.TypeOf<HttpStatusCodeResult>());
        }
        public void should_not_set_viewresult_if_user_is_logged_in()
        {
            // Arrange
            BrowserCacheAttribute attribute = new BrowserCacheAttribute();

            attribute.SettingsService = _settingsService;

            WikiController        controller    = CreateWikiController(attribute);
            ResultExecutedContext filterContext = CreateContext(controller);

            attribute.Context.CurrentUser = Guid.NewGuid().ToString();

            // Act
            attribute.OnResultExecuted(filterContext);

            // Assert
            Assert.That(filterContext.Result, Is.Not.TypeOf <HttpStatusCodeResult>());
        }
        public void should_not_set_viewresult_if_usebrowsercache_is_disabled()
        {
            // Arrange
            BrowserCacheAttribute attribute = new BrowserCacheAttribute();

            attribute.SettingsService = _settingsService;

            WikiController        controller    = CreateWikiController(attribute);
            ResultExecutedContext filterContext = CreateContext(controller);

            attribute.ApplicationSettings.UseBrowserCache = false;

            // Act
            attribute.OnResultExecuted(filterContext);

            // Assert
            Assert.That(filterContext.Result, Is.Not.TypeOf <HttpStatusCodeResult>());
        }
Exemple #13
0
        public void Should_Have_304_Http_Status_Code_If_PluginsSaved_Is_Equal_To_Header_Last_Modified_Date()
        {
            // Arrange
            BrowserCacheAttribute attribute = new BrowserCacheAttribute();

            attribute.SettingsService = GetSettingsService();
            _repositoryMock.SiteSettings.PluginLastSaveDate = DateTime.Today.ToUniversalTime().AddHours(1);

            WikiController        controller    = CreateWikiController(attribute);
            ResultExecutedContext filterContext = CreateContext(controller);

            filterContext.HttpContext.Request.Headers.Add("If-Modified-Since", DateTime.Today.AddHours(1).ToUniversalTime().ToString("r"));

            // Act
            attribute.OnResultExecuted(filterContext);

            // Assert
            Assert.That(filterContext.HttpContext.Response.StatusCode, Is.EqualTo(304));
            Assert.That(filterContext.Result, Is.TypeOf <HttpStatusCodeResult>());
        }
        public void should_have_304_http_status_code_if_pluginssaved_is_equal_to_header_last_modified_date()
        {
            // Arrange
            BrowserCacheAttribute attribute = new BrowserCacheAttribute();

            attribute.SettingsService = _settingsService;
            _settingsRepository.SiteSettings.PluginLastSaveDate = DateTime.Today.ToUniversalTime().AddHours(1);

            WikiController        controller    = CreateWikiController(attribute);
            ResultExecutedContext filterContext = CreateContext(controller);

            filterContext.HttpContext.Request.Headers.Add("If-Modified-Since", DateTime.Today.AddHours(1).ToUniversalTime().ToString("r"));

            // Act
            attribute.OnResultExecuted(filterContext);

            // Assert
            Assert.That(filterContext.HttpContext.Response.StatusCode, Is.EqualTo(304));
            Assert.That(filterContext.Result, Is.TypeOf <HttpStatusCodeResult>());
        }
Exemple #15
0
        private WikiController CreateWikiController(BrowserCacheAttribute attribute)
        {
            // Settings
            ApplicationSettings appSettings = new ApplicationSettings()
            {
                Installed = true, UseBrowserCache = true
            };
            UserContextStub userContext = new UserContextStub()
            {
                IsLoggedIn = false
            };

            // PageService
            PageViewModelCache pageViewModelCache = new PageViewModelCache(appSettings, CacheMock.RoadkillCache);
            ListCache          listCache          = new ListCache(appSettings, CacheMock.RoadkillCache);
            SiteCache          siteCache          = new SiteCache(appSettings, CacheMock.RoadkillCache);
            SearchServiceMock  searchService      = new SearchServiceMock(appSettings, _repositoryMock, _pluginFactory);
            PageHistoryService historyService     = new PageHistoryService(appSettings, _repositoryMock, userContext, pageViewModelCache, _pluginFactory);
            PageService        pageService        = new PageService(appSettings, _repositoryMock, searchService, historyService, userContext, listCache, pageViewModelCache, siteCache, _pluginFactory);

            // WikiController
            SettingsService settingsService = new SettingsService(appSettings, _repositoryMock);
            UserServiceStub userManager     = new UserServiceStub();
            WikiController  wikiController  = new WikiController(appSettings, userManager, pageService, userContext, settingsService);

            // Create a page that the request is for
            Page page = new Page()
            {
                Title = "title", ModifiedOn = _pageModifiedDate
            };

            _repositoryMock.AddNewPage(page, "text", "user", _pageCreatedDate);

            // Update the BrowserCacheAttribute
            attribute.ApplicationSettings = appSettings;
            attribute.Context             = userContext;
            attribute.PageService         = pageService;

            return(wikiController);
        }
        public void Should_Have_304_Http_Status_Code_If_Response_Has_Modified_Since_Header_Matching_Page_Modified_Date()
        {
            // The file date and the browser date always match for a 304 status, the browser will never send back a more recent date,
            // i.e. "Has the file changed since this date I've stored for the last time it was changed?"
            // and *not* "has the file changed since the time right now?".

            // Arrange
            BrowserCacheAttribute attribute = new BrowserCacheAttribute();
            attribute.SettingsService = GetSettingsService();

            WikiController controller = CreateWikiController(attribute);
            ResultExecutedContext filterContext = CreateContext(controller);

            // (page modified date is set in CreateWikiController)
            filterContext.HttpContext.Request.Headers.Add("If-Modified-Since", DateTime.Today.ToString("r"));

            // Act
            attribute.OnResultExecuted(filterContext);

            // Assert
            HttpStatusCodeResult result = filterContext.Result as HttpStatusCodeResult;
            Assert.That(filterContext.HttpContext.Response.StatusCode, Is.EqualTo(304));
            Assert.That(result.StatusCode, Is.EqualTo(304));
            Assert.That(result.StatusDescription, Is.EqualTo("Not Modified"));
        }
		public void should_have_200_http_status_code_if_no_modified_since_header()
		{
			// Arrange
			BrowserCacheAttribute attribute = new BrowserCacheAttribute();
			attribute.SettingsService = _settingsService;

			WikiController controller = CreateWikiController(attribute);
			ResultExecutedContext filterContext = CreateContext(controller);

			// Act
			attribute.OnResultExecuted(filterContext);

			// Assert
			Assert.That(filterContext.HttpContext.Response.StatusCode, Is.EqualTo(200));
			Assert.That(filterContext.Result, Is.Not.TypeOf<HttpStatusCodeResult>());
		}
		public void should_have_304_http_status_code_if_pluginssaved_is_equal_to_header_last_modified_date()
		{
			// Arrange
			BrowserCacheAttribute attribute = new BrowserCacheAttribute();
			attribute.SettingsService = _settingsService;
			_settingsRepository.SiteSettings.PluginLastSaveDate = DateTime.Today.ToUniversalTime().AddHours(1);

			WikiController controller = CreateWikiController(attribute);
			ResultExecutedContext filterContext = CreateContext(controller);
			filterContext.HttpContext.Request.Headers.Add("If-Modified-Since", DateTime.Today.AddHours(1).ToUniversalTime().ToString("r"));

			// Act
			attribute.OnResultExecuted(filterContext);

			// Assert
			Assert.That(filterContext.HttpContext.Response.StatusCode, Is.EqualTo(304));
			Assert.That(filterContext.Result, Is.TypeOf<HttpStatusCodeResult>());
		}
        private WikiController CreateWikiController(BrowserCacheAttribute attribute)
        {
            // Settings
            ApplicationSettings appSettings = new ApplicationSettings() { Installed = true, UseBrowserCache = true };
            UserContextStub userContext = new UserContextStub() { IsLoggedIn = false };

            // PageService
            PageViewModelCache pageViewModelCache = new PageViewModelCache(appSettings, CacheMock.RoadkillCache);
            ListCache listCache = new ListCache(appSettings, CacheMock.RoadkillCache);
            SiteCache siteCache = new SiteCache(appSettings, CacheMock.RoadkillCache);
            SearchServiceMock searchService = new SearchServiceMock(appSettings, _repositoryMock, _pluginFactory);
            PageHistoryService historyService = new PageHistoryService(appSettings, _repositoryMock, userContext, pageViewModelCache, _pluginFactory);
            PageService pageService = new PageService(appSettings, _repositoryMock, searchService, historyService, userContext, listCache, pageViewModelCache, siteCache, _pluginFactory);

            // WikiController
            SettingsService settingsService = new SettingsService(appSettings, _repositoryMock);
            UserServiceStub userManager = new UserServiceStub();
            WikiController wikiController = new WikiController(appSettings, userManager, pageService, userContext, settingsService);

            // Create a page that the request is for
            Page page = new Page() { Title = "title", ModifiedOn = _pageModifiedDate };
            _repositoryMock.AddNewPage(page, "text", "user", _pageCreatedDate);

            // Update the BrowserCacheAttribute
            attribute.ApplicationSettings = appSettings;
            attribute.Context = userContext;
            attribute.PageService = pageService;

            return wikiController;
        }
		public void should_not_set_viewresult_if_user_is_logged_in()
		{
			// Arrange
			BrowserCacheAttribute attribute = new BrowserCacheAttribute();
			attribute.SettingsService = _settingsService;

			WikiController controller = CreateWikiController(attribute);
			ResultExecutedContext filterContext = CreateContext(controller);

			attribute.Context.CurrentUser = Guid.NewGuid().ToString();

			// Act
			attribute.OnResultExecuted(filterContext);

			// Assert
			Assert.That(filterContext.Result, Is.Not.TypeOf<HttpStatusCodeResult>());
		}