public void ComplexUrlGeneration() { RouteTable.Routes.Clear(); ActionFactory.Actions[typeof(NestedQueryModel)] = new ActionInfo(); RouteTable.Routes.Add(typeof(NestedQueryModel).FullName, new Route("fakeUrl", null)); ModelBinders.Binders.Remove(typeof(DateTime?)); ModelBinders.Binders.Add(typeof(DateTime?), new DateTimeBinder()); ActionFactory.TypeFormatters[typeof(DateTime?)] = (o, context) => ((DateTime?)o).Value.ToString("dd/MM/yyyy HH:mm:ss"); var urlHelper = MvcMockHelpers.GetUrlHelper("~/fakeUrl"); var httpContext = Mock.Get(urlHelper.RequestContext.HttpContext.Request); httpContext.Setup(x => x.QueryString).Returns(new NameValueCollection() { { "Age", "1" }, { "NestedList[0].Name", "MyName" }, { "NestedObj.Name", "MyName2" }, { "Today", "17/10/2010 12:00:00" } }); var url = urlHelper.For <NestedQueryModel>(x => x.Age = 2, x => x.NestedObj.Name = "Wow"); Assert.AreEqual("/fakeUrl?Age=2&Today=17%2F10%2F2010%2012%3A00%3A00&NestedList%5B0%5D.Name=MyName&NestedObj.Name=Wow", url); }
public void UrlForInterfaceShouldReturnCorrectUrl1() { ActionFactory.Actions.Add(typeof(TestUrl), new ActionInfo() { }); RouteTable.Routes.Add(typeof(TestUrl).FullName, new Route("fakeUrl/{Age}/edit", null)); var url = MvcMockHelpers.GetUrlHelper("~/fakeUrl"); url.For(new TestUrl()).ShouldBe("/fakeUrl/0/edit"); }
public void ComplexUrlGenerationWithEnum() { RouteTable.Routes.Clear(); ActionFactory.Actions[typeof(NestedQueryModel)] = new ActionInfo(); RouteTable.Routes.Add(typeof(NestedQueryModel).FullName, new Route("fakeUrl", null)); var urlHelper = MvcMockHelpers.GetUrlHelper("~/fakeUrl"); var httpContext = Mock.Get(urlHelper.RequestContext.HttpContext.Request); httpContext.Setup(x => x.QueryString).Returns(new NameValueCollection()); var url = urlHelper.For <NestedQueryModel>(x => x.MyEnum = MyEnum.Two, x => x.NestedObj.MyEnum = MyEnum.Two); Assert.AreEqual("/fakeUrl?MyEnum=Two&NestedObj.MyEnum=Two", url); }
public void UrlForInterfaceShouldReturnCorrectUrl() { ActionFactory.Actions.Add(typeof(TestUrl), new ActionInfo() { }); RouteTable.Routes.Add(typeof(TestUrl).FullName, new Route("fakeUrl/{Id}", null)); var url = MvcMockHelpers.GetUrlHelper("~/fakeUrl"); var newGuid = Guid.NewGuid(); url.For(new TestUrl() { Id = newGuid }).ShouldBe("/fakeUrl/" + newGuid); }
public void SimpleUrlGeneration() { RouteTable.Routes.Clear(); ActionFactory.Actions[typeof(NestedQueryModel)] = new ActionInfo(); RouteTable.Routes.Add(typeof(NestedQueryModel).FullName, new Route("fakeUrl", null)); var urlHelper = MvcMockHelpers.GetUrlHelper("~/fakeUrl"); var httpContext = Mock.Get(urlHelper.RequestContext.HttpContext.Request); httpContext.Setup(x => x.QueryString).Returns(new NameValueCollection() { { "Age", "1" } }); var url = urlHelper.For <NestedQueryModel>(x => x.Age = 2); Assert.AreEqual(url, "/fakeUrl?Age=2"); }
public void AliasBinding() { RouteTable.Routes.Clear(); ModelBinders.Binders.DefaultBinder = new AliasModelBinder(); ActionFactory.Actions[typeof(AliasQueryModel)] = new ActionInfo(); RouteTable.Routes.Add(typeof(AliasQueryModel).FullName, new Route("fakeUrl", null)); var urlHelper = MvcMockHelpers.GetUrlHelper("~/fakeUrl"); var httpContext = Mock.Get(urlHelper.RequestContext.HttpContext.Request); httpContext.Setup(x => x.QueryString).Returns(new NameValueCollection()); var url = urlHelper.For(new AliasQueryModel { MyBigLongNameHere = "MyName" }); Assert.AreEqual("/fakeUrl?N=MyName", url); ModelBinders.Binders.DefaultBinder = new DefaultModelBinder(); }
public void NestedAliases() { RouteTable.Routes.Clear(); ModelBinders.Binders.DefaultBinder = new AliasModelBinder(); ActionFactory.Actions[typeof(AliasQueryModel)] = new ActionInfo(); RouteTable.Routes.Add(typeof(AliasQueryModel).FullName, new Route("fakeUrl", null)); var urlHelper = MvcMockHelpers.GetUrlHelper("~/fakeUrl"); var httpContext = Mock.Get(urlHelper.RequestContext.HttpContext.Request); httpContext.Setup(x => x.QueryString).Returns(new NameValueCollection() { { "NAQ.LNP2", "Binding" } }); var url = urlHelper.For <AliasQueryModel>(x => x.NestedAliasQuery.LongerNestedProp = "WowWee"); Assert.AreEqual("/fakeUrl?NAQ.LNP=WowWee&NAQ.LNP2=Binding", url); ModelBinders.Binders.DefaultBinder = new DefaultModelBinder(); }