示例#1
0
        public void WidgetContent_AppRelativePath_ResolvesAsNormalContent()
        {
            // Arrange
            var dummyHttpContext = new DummyHttpContext();
            var urlHelper = new UrlHelper(dummyHttpContext.Request.RequestContext);

            // Act
            var expected = urlHelper.Content("~/Test");
            var result = urlHelper.WidgetContent("~/Test");

            // Assert
            Assert.AreEqual(expected, result);
        }
示例#2
0
        public void WidgetContent_AbsolutePath_Unchanged()
        {
            // Arrange
            var dummyHttpContext = new DummyHttpContext();
            var urlHelper = new UrlHelper(dummyHttpContext.Request.RequestContext);

            // Act
            var absUrl = "http://www.sitefinity.com/";
            var result = urlHelper.WidgetContent(absUrl);

            // Assert
            Assert.AreEqual(absUrl, result);
        }
        public void RegisterScript_TwoTimes_ExceptionIsThrown()
        {
            var dummyHttpContext = new DummyHttpContext();
            var dummyViewContext = new ViewContext();
            dummyViewContext.HttpContext = dummyHttpContext;
            var dummyViewDataContainer = (IViewDataContainer)new ViewPage();
            var script = "Mvc/Scripts/Designer/modal-dialog.js";

            var htmlHelper = new System.Web.Mvc.HtmlHelper(dummyViewContext, dummyViewDataContainer);

            var result = htmlHelper.Script(script, true);
            Assert.AreEqual(result.ToString(), string.Format(System.Globalization.CultureInfo.InvariantCulture, "<script src=\"{0}\" type=\"text/javascript\"></script>", script));

            result = htmlHelper.Script(script, true);
        }
        public void RegisterStylesheet_TwoTimes_ExceptionIsThrown()
        {
            var dummyHttpContext = new DummyHttpContext();
            var dummyViewContext = new ViewContext();
            dummyViewContext.HttpContext = dummyHttpContext;
            var dummyViewDataContainer = (IViewDataContainer)new ViewPage();
            var htmlHelper = new System.Web.Mvc.HtmlHelper(dummyViewContext, dummyViewDataContainer);

            var stylesheet = "Mvc/Styles/Designer/modal-dialog.css";

            string expected = string.Format(System.Globalization.CultureInfo.InvariantCulture, "<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" />", stylesheet);
            string result = htmlHelper.StyleSheet(stylesheet, null, throwException: true).ToString();
            Assert.AreEqual(expected, result);

            htmlHelper.StyleSheet(stylesheet, null, throwException: true);
        }
        public void RegisterScript_TwoTimes_NoDuplicateRegistrations()
        {
            var dummyHttpContext = new DummyHttpContext();
            var dummyViewContext = new ViewContext();
            dummyViewContext.HttpContext = dummyHttpContext;
            var dummyViewDataContainer = (IViewDataContainer)new ViewPage();
            var script = "Mvc/Scripts/Designer/modal-dialog.js";

            var htmlHelper = new System.Web.Mvc.HtmlHelper(dummyViewContext, dummyViewDataContainer);

            string expected1 = string.Format(System.Globalization.CultureInfo.InvariantCulture, "<script src=\"{0}\" type=\"text/javascript\"></script>", script);
            string result1 = htmlHelper.Script(script).ToString();
            Assert.AreEqual(expected1, result1);

            MvcHtmlString expected2 = MvcHtmlString.Empty;
            MvcHtmlString result2 = htmlHelper.Script(script);
            Assert.AreEqual(expected2, result2);
        }
示例#6
0
        public void WidgetContent_RelativePathAndRouteData_AppendsWidgetVirtualPath()
        {
            // Arrange
            var dummyHttpContext = new DummyHttpContext();
            dummyHttpContext.Request.RequestContext.RouteData.Values.Add("controller", "Dummy");
            var urlHelper = new UrlHelper(dummyHttpContext.Request.RequestContext);

            string result;
            using (var factoryReg = new ControllerFactoryRegion<DummyControllerFactory>())
            {
                factoryReg.Factory.ControllerRegistry["Dummy"] = typeof(DummyController);

                // Act
                result = urlHelper.WidgetContent("Test/MyScript.js");
            }

            // Assert
            Assert.AreEqual("/Frontend-Assembly/Telerik.Sitefinity.Frontend.TestUtilities/Test/MyScript.js", result);
        }
        public void CreateUnsubscribeController_CallIndexAction_EnsuresMessageWithNoLicensed()
        {
            var httpContext = new DummyHttpContext();
            httpContext.Items[SystemManager.PageDesignModeKey] = true;
            SystemManager.RunWithHttpContext(
                          httpContext,
                          () =>
                          {
                              // Arrange
                              using (var controller = new DummyUnsubscribeFormController(isLicensed: false))
                              {
                                  // Act
                                  var view = controller.Index() as ContentResult;

                                  // Assert
                                  Assert.IsTrue(view.Content == "No valid license");
                              }
                          });
        }
        public void CreateSubscribeController_CallTheIndexAction_EnsuresMessageWhenModuleIsDeactivated()
        {
            var httpContext = new DummyHttpContext();

            httpContext.Items[SystemManager.PageDesignModeKey] = true;

            SystemManager.RunWithHttpContext(
                          httpContext,
                          () =>
                          {
                              // Arrange
                              using (var controller = new DummySubscribeFormController(isModuleActivated: false))
                              {
                                  // Act
                                  var view = controller.Index() as ContentResult;

                                  // Assert
                                  Assert.IsNotNull(view);
                                  Assert.IsTrue(view.Content == "NewslettersModuleDeactivatedMessage");
                              }
                          });
        }
        public void OnResultExecuted_VirtualFileDependencies_AddedToResponse()
        {
            // Arrange
            var context = new DummyHttpContext();
            var response = (DummyHttpResponse)context.Response;
            var filterContext = new ResultExecutedContext();
            var actionFilter = new DummyCacheDependentAttribute();
            var viewPath = "~/MyTestView.cshtml";
            var view = new DummyBuildManagerCompiledView(new ControllerContext(), viewPath);

            filterContext.Result = new DummyViewResult { View = view };

            // Act
            SystemManager.RunWithHttpContext(context, () => actionFilter.OnResultExecuted(filterContext));

            // Assert
            Assert.AreEqual(1, response.CacheDependencies.Count, "Unexpected number of cache dependencies were added.");
            Assert.IsInstanceOfType(response.CacheDependencies[0], typeof(DummyCacheDependency), "The cache dependency that was added is of unexpected type.");
            
            var dependency = (DummyCacheDependency)response.CacheDependencies[0];
            Assert.AreEqual(viewPath, dependency.Key, "Cache dependency was not added on the expected path.");
        }
示例#10
0
        public void WidgetContent_RelativePathNoRouteData_ThrowsException()
        {
            // Arrange
            var dummyHttpContext = new DummyHttpContext();
            var urlHelper = new UrlHelper(dummyHttpContext.Request.RequestContext);

            // Act
            urlHelper.WidgetContent("Test/MyScript.js");
        }
        public void CreateUnsubscribeController_CallTheIndexAction_EnsuresViewNameIsChanged()
        {
            var httpContext = new DummyHttpContext();
            httpContext.Items[SystemManager.PageDesignModeKey] = true;
            SystemManager.RunWithHttpContext(
                          httpContext,
                          () =>
                          {
                              // Arrange
                              using (var controller = new DummyUnsubscribeFormController())
                              {
                                  controller.LinkTemplateName = "CustomName";

                                  // Act
                                  var view = controller.Index() as ViewResult;

                                  // Assert
                                  Assert.IsNotNull(view);
                                  Assert.IsTrue(view.ViewName == "UnsubscribeFormByLink.CustomName");
                                  Assert.IsNotNull(view.Model);
                                  Assert.IsTrue(view.Model is UnsubscribeFormViewModel);
                              }
                          });
        }
示例#12
0
        public void RegisterStylesheet_TwoTimes_NoDuplicateRegistrations()
        {
            var dummyHttpContext = new DummyHttpContext();
            var dummyViewContext = new ViewContext();
            dummyViewContext.HttpContext = dummyHttpContext;
            var dummyViewDataContainer = (IViewDataContainer)new ViewPage();
            var htmlHelper = new System.Web.Mvc.HtmlHelper(dummyViewContext, dummyViewDataContainer);

            var stylesheet = "Mvc/Styles/Designer/modal-dialog.css";

            string expected1 = string.Format(System.Globalization.CultureInfo.InvariantCulture, "<link href=\"{0}\" rel=\"stylesheet\" type=\"text/css\" />", stylesheet);
            string result1 = htmlHelper.StyleSheet(stylesheet).ToString();
            Assert.AreEqual(expected1, result1);

            MvcHtmlString expected2 = MvcHtmlString.Empty;
            MvcHtmlString result2 = htmlHelper.StyleSheet(stylesheet);
            Assert.AreEqual(expected2, result2);
        }