Example #1
0
        public void GetUrl_WithBadRouteName_Throws()
        {
            // Arrange
            var testableAttribute = new TestableRemoteAttribute("nonexistentRoute");
            var context           = GetValidationContextWithArea(currentArea: null);

            // Act & Assert
            var exception = Assert.Throws <InvalidOperationException>(() => testableAttribute.InvokeGetUrl(context));

            Assert.Equal("No URL for remote validation could be found.", exception.Message);
        }
Example #2
0
        public void GetUrl_WithActionControllerAreaInArea_FindsControllerInDifferentArea()
        {
            // Arrange
            var testableAttribute = new TestableRemoteAttribute("Action", "Controller", "AnotherArea");
            var context           = GetValidationContextWithArea(currentArea: "Test");

            // Act
            var actualUrl = testableAttribute.InvokeGetUrl(context);

            // Assert
            Assert.Equal("/AnotherArea/Controller/Action", actualUrl);
        }
Example #3
0
        public void GetUrl_WithActionControllerArea_FindsControllerInRootArea(string areaName)
        {
            // Arrange
            var testableAttribute = new TestableRemoteAttribute("Action", "Controller", areaName);
            var context           = GetValidationContextWithArea(currentArea: null);

            // Act
            var actualUrl = testableAttribute.InvokeGetUrl(context);

            // Assert
            Assert.Equal("/Controller/Action", actualUrl);
        }
Example #4
0
        public void GetUrl_WithRoute_CallsUrlHelperWithExpectedValues()
        {
            // Arrange
            var routeName = "RouteName";
            var testableRemoteAttribute = new TestableRemoteAttribute(routeName);
            var url       = "/my/URL";
            var urlHelper = new MockUrlHelper(url, routeName);
            var context   = GetValidationContext(urlHelper);

            // Act
            var actualUrl = testableRemoteAttribute.InvokeGetUrl(context);

            // Assert
            Assert.Equal(url, actualUrl);

            var routeDictionary = Assert.IsType <RouteValueDictionary>(urlHelper.RouteValues);

            Assert.Empty(routeDictionary);
        }
Example #5
0
        public void GetUrl_WithActionController_CallsUrlHelperWithExpectedValues()
        {
            // Arrange
            var testableRemoteAttribute = new TestableRemoteAttribute("Action", "Controller");
            var url       = "/Controller/Action";
            var urlHelper = new MockUrlHelper(url, routeName: null);
            var context   = GetValidationContext(urlHelper);

            // Act
            var actualUrl = testableRemoteAttribute.InvokeGetUrl(context);

            // Assert
            Assert.Equal(url, actualUrl);

            var routeDictionary = Assert.IsType <RouteValueDictionary>(urlHelper.RouteValues);

            Assert.Equal(2, routeDictionary.Count);
            Assert.Equal("Action", routeDictionary["action"] as string);
            Assert.Equal("Controller", routeDictionary["controller"] as string);
        }