Example #1
0
        public void GetActiveCssClassIfRouteActive_ActiveRouteMatchOnlyByController_ActiveCssClass()
        {
            // Arrange

            var mockedHtmlHelperBuilder = new MockedHtmlHelperBuilder();

            mockedHtmlHelperBuilder.ViewContextMock.Setup(m => m.RouteData)
            .Returns(new RouteData()
            {
                Values =
                {
                    { "controller", "controllerName" },
                    { "action",     "actionName"     },
                    { "id",         "111"            }
                }
            });

            HtmlHelper htmlHelper = mockedHtmlHelperBuilder.GetResult();


            // Act
            var cssActiveClass = htmlHelper.GetCssClassIfCurrentRouteIs("active", "controllerName");

            // Assert
            Assert.AreEqual("active", cssActiveClass);
        }
Example #2
0
        public void GetActiveCssClassIfRouteActive_NotActiveRoute_ActiveCssClass()
        {
            // Arrange
            var mockedHtmlHelperBuilder = new MockedHtmlHelperBuilder();

            mockedHtmlHelperBuilder.ViewContextMock.Setup(m => m.RouteData)
            .Returns(new RouteData()
            {
                Values =
                {
                    { "controller", "controllerName" },
                    { "action",     "actionName"     },
                    { "id",         "111"            }
                }
            });

            HtmlHelper htmlHelper = mockedHtmlHelperBuilder.GetResult();


            // Act
            var cssActiveClass = htmlHelper.GetCssClassIfCurrentRouteIs("active", "controllerNameNotActive", "actionNameNotActive");
            var cssActiveClassWithRouteValues = htmlHelper.GetCssClassIfCurrentRouteIs("active", "controllerName", "actionName", new { id = 333 });

            // Assert
            Assert.IsEmpty(cssActiveClass);
            Assert.IsEmpty(cssActiveClassWithRouteValues);
        }
        public void ValidationErrorCssClassFor_ValidAndInvalidModelProperties_ErrorCssClassNameInCaseOfErrorOtherwiseEmptyString()
        {
            // Arrange
            var mockedHtmlHelperBuilder = new MockedHtmlHelperBuilder();

            mockedHtmlHelperBuilder.ViewData.ModelState.AddModelError("Name", new Exception());
            mockedHtmlHelperBuilder.ViewDataContainerMock.Setup(m => m.ViewData)
            .Returns(mockedHtmlHelperBuilder.ViewData);
            mockedHtmlHelperBuilder.ViewContextMock.Setup(m => m.FormContext)
            .Returns(new FormContext());

            HtmlHelper <TestModel> htmlHelper = mockedHtmlHelperBuilder.GetResult <TestModel>();

            // Act
            var validationErrorResultName        = htmlHelper.ValidationErrorCssClassFor(m => m.Name, "error");
            var validationErrorResultDescription = htmlHelper.ValidationErrorCssClassFor(m => m.Description, "error");

            // Assert
            Assert.AreEqual("error", validationErrorResultName);
            Assert.IsEmpty(validationErrorResultDescription);
        }
        public void HasValidationErrorFor_ValidAndInvalidModelProperties_IndicatorTrueOrFalse()
        {
            // Arrange
            var mockedHtmlHelperBuilder = new MockedHtmlHelperBuilder();

            mockedHtmlHelperBuilder.ViewData.ModelState.AddModelError("Name", new Exception());
            mockedHtmlHelperBuilder.ViewDataContainerMock.Setup(m => m.ViewData)
            .Returns(mockedHtmlHelperBuilder.ViewData);
            mockedHtmlHelperBuilder.ViewContextMock.Setup(m => m.FormContext)
            .Returns(new FormContext());

            HtmlHelper <TestModel> htmlHelper = mockedHtmlHelperBuilder.GetResult <TestModel>();

            // Act
            var validationErrorResultName        = htmlHelper.HasValidationErrorFor(m => m.Name);
            var validationErrorResultDescription = htmlHelper.HasValidationErrorFor(m => m.Description);

            // Assert
            Assert.IsTrue(validationErrorResultName);
            Assert.IsFalse(validationErrorResultDescription);
        }
        public void ValidationCssClassFor_ModelPropertyAndValidationCssClassNames_ValidationCssClassNameDependingOfModelPropertyValidity()
        {
            // Arrange
            var mockedHtmlHelperBuilder = new MockedHtmlHelperBuilder();

            mockedHtmlHelperBuilder.ViewData.ModelState.AddModelError <TestModel>(m => m.Name, new Exception());
            mockedHtmlHelperBuilder.ViewData.ModelState.Add <TestModel>(m => m.Other, new ModelState());
            mockedHtmlHelperBuilder.ViewDataContainerMock.Setup(m => m.ViewData)
            .Returns(mockedHtmlHelperBuilder.ViewData);
            mockedHtmlHelperBuilder.ViewContextMock.Setup(m => m.FormContext)
            .Returns(new FormContext());

            HtmlHelper <TestModel> htmlHelper = mockedHtmlHelperBuilder.GetResult <TestModel>();

            // Act
            var validationErrorResultName        = htmlHelper.ValidationCssClassFor(m => m.Name, "success", "error");
            var validationErrorResultDescription = htmlHelper.ValidationCssClassFor(m => m.Description, "success", "error");
            var validationErrorResultOther       = htmlHelper.ValidationCssClassFor(m => m.Other, "success", "error");

            // Assert
            Assert.AreEqual("error", validationErrorResultName);
            Assert.IsEmpty(validationErrorResultDescription);
            Assert.AreEqual("success", validationErrorResultOther);
        }