예제 #1
0
        public void CanInvokeMethodWithParamsArray()
        {
            var viewContext = _mocks.DynamicViewContext("someView");
            var viewDataContainer = _mocks.DynamicMock<IViewDataContainer>();

            HtmlExtensionDuck.AddExtension(typeof(HtmlExtensionForTesting));
            var htmlExtensionDuck = new HtmlExtensionDuck(viewContext, viewDataContainer);
            Object[] args = {"foo", "bar"};
            object result = htmlExtensionDuck.Invoke("Bar", args);

            Assert.That(result, Is.EqualTo("Bar3"));
        }
예제 #2
0
        public void CanFindMethodWithAmbiguousOverloads()
        {
            var viewContext = _mocks.DynamicViewContext("someView");
            var viewDataContainer = _mocks.DynamicMock<IViewDataContainer>();

            HtmlExtensionDuck.AddExtension(typeof(HtmlExtensionForTesting));
            var htmlExtensionDuck = new HtmlExtensionDuck(viewContext, viewDataContainer);

            object result = htmlExtensionDuck.Invoke("Bar", "x");

            Assert.That(result, Is.EqualTo("Bar"));
        }
예제 #3
0
        public void CanAddExtensionsToHtmlExtensionDuck()
        {
            var viewContext = _mocks.DynamicViewContext("someView");
            var viewDataContainer = _mocks.DynamicMock<IViewDataContainer>();

            HtmlExtensionDuck.AddExtension(typeof(HtmlExtensionForTesting));
            var htmlExtensionDuck = new HtmlExtensionDuck(viewContext, viewDataContainer);

            object result = htmlExtensionDuck.Invoke("Foo");

            Assert.That(result, Is.EqualTo("Bar"));
        }
        private static void AddHtmlExtensionsFromConfig()
        {
            var section = ConfigurationManager.GetSection("nvelocity");

            if (section == null)
            {
                return;
            }

            var config = (NVelocityConfiguration)section;

            foreach (var t in  config.HtmlExtensionTypes)
            {
                HtmlExtensionDuck.AddExtension(t);
            }
        }
예제 #5
0
        public void SetUp()
        {
            _mocks = new MockRepository();
            var httpContext = _mocks.DynamicMock<HttpContextBase>();
            var httpResponse = _mocks.DynamicMock<HttpResponseBase>();
            var httpSessionState = _mocks.DynamicMock<HttpSessionStateBase>();
            SetupResult.For(httpContext.Session).Return(httpSessionState);
            SetupResult.For(httpContext.Response).Return(httpResponse);
            var routeData = new RouteData();
            routeData.Values["controller"] = "testcontroller";
            var requestContext = new RequestContext(httpContext,
                                                               routeData
                                                                  );
            var controller = _mocks.DynamicMock<ControllerBase>();
            var controllerContext = new ControllerContext(requestContext, controller);
            var view = _mocks.DynamicMock<IView>();
            _mocks.ReplayAll();
            var viewPage = new ViewPage();
            var viewContext = new ViewContext(controllerContext, view,new ViewDataDictionary(), new TempDataDictionary(), new StringWriter());

            _htmlHelper = new HtmlHelper(viewContext, viewPage);
            _htmlHelperDuck = new HtmlExtensionDuck(_htmlHelper) {Introspector = new Introspector(new Logger())};
        }
예제 #6
0
 private void CreateAndAddHelpers(Hashtable entries)
 {
     entries["html"] = entries["htmlhelper"] = new HtmlExtensionDuck(_viewContext, this);
     entries["url"] = entries["urlhelper"] = new UrlHelper(_viewContext.RequestContext);
 }
 private void CreateAndAddHelpers(Hashtable entries)
 {
     entries["html"] = entries["htmlhelper"] = new HtmlExtensionDuck(_viewContext, this);
     entries["url"]  = entries["urlhelper"] = new UrlHelper(_viewContext.RequestContext);
 }