public void Model () { MetaModel m = Utils.CommonInitialize (); var route = RouteTable.Routes[0] as DynamicDataRoute; Assert.IsNotNull (route, "#A1"); Assert.IsNotNull (route.Model, "#A1-1"); var handler = route.RouteHandler; Assert.IsNotNull (handler, "#A2"); Assert.IsTrue (handler.GetType () == typeof (MyDynamicDataRouteHandler), "#A2-1"); Assert.IsNull (handler.Model, "#A2-2"); var req = new FakeHttpWorkerRequest (); var ctx = new HttpContext (req); RequestContext rc = DynamicDataRouteHandler.GetRequestContext (ctx); Assert.IsNotNull (rc, "#B1"); Assert.IsNull (handler.Model, "#B1-2"); var wrapper = new MyHttpContextWrapper (); var request = wrapper.Request as MyHttpRequestWrapper; // It appears .NET checks whether the indicated table exists - if not, GetRouteData will return // null (even though the Route class will find a match) request.SetProperty ("AppRelativeCurrentExecutionFilePath", "~/NoSuchTable/List.aspx"); request.SetProperty ("PathInfo", String.Empty); // This must be non-null because DynamicData doesn't care to check whether the returned // value is null or not... request.SetProperty ("QueryString", new NameValueCollection ()); // No table FooTable in the context - returns null RouteData rd = route.GetRouteData (wrapper); Assert.IsNull (rd, "#C1"); // Apparently Model is set in the above call even though it returns null Assert.IsNotNull (handler.Model, "#C1-1"); Assert.AreEqual (route.Model, handler.Model, "#C1-2"); request.SetProperty ("AppRelativeCurrentExecutionFilePath", "~/BarTable/List.aspx"); rd = route.GetRouteData (wrapper); Assert.IsNotNull (rd, "#D1"); Assert.IsNotNull (handler.Model, "#D1-1"); Assert.AreEqual (route.Model, handler.Model, "#D1-2"); }
// Probably need to simulate a full reqest using similar environment as System.Web tests public void CreateHandler () { MetaModel m = Utils.CommonInitialize (); var route = RouteTable.Routes[0] as DynamicDataRoute; MetaTable t = m.Tables[TestDataContext.TableFooEmpty]; Assert.IsNotNull (t, "#A1"); var handler = route.RouteHandler = new DynamicDataRouteHandler (); var wrapper = new MyHttpContextWrapper (); var request = wrapper.Request as MyHttpRequestWrapper; request.SetProperty ("AppRelativeCurrentExecutionFilePath", "~/FooEmptyTable/List.aspx"); request.SetProperty ("PathInfo", String.Empty); // This must be non-null because DynamicData doesn't care to check whether the returned // value is null or not... request.SetProperty ("QueryString", new NameValueCollection ()); // This will assign the route handler's Model property RouteData rd = route.GetRouteData (wrapper); Assert.IsNotNull (handler.Model, "#A2"); // Throws a NREX from some internal method - no slightest idea why, as none of the parameters // passed are null IHttpHandler h = handler.CreateHandler (route, t, PageAction.Details); Assert.IsNotNull (h, "#A3"); Assert.AreEqual (typeof (Page), h.GetType (), "#A3-1"); var page = h as Page; Assert.AreEqual (String.Empty, page.AppRelativeVirtualPath, "#A3-2"); }
public void GetScaffoldPageVirtualPath () { MetaModel m = Utils.CommonInitialize (); var route = RouteTable.Routes[0] as DynamicDataRoute; MetaTable t = m.Tables[TestDataContext.TableFooDisplayName]; Assert.IsNotNull (t, "#A1"); // We neeed the handler to have its Model property set route.RouteHandler = new MyDynamicDataRouteHandler (); var handler = route.RouteHandler as MyDynamicDataRouteHandler; Assert.IsNotNull (handler, "#A2"); // Lack of null check (for table) AssertExtensions.Throws<NullReferenceException> (() => { handler.DoGetScaffoldPageVirtualPath (null, null); }, "#A2-1"); // Another missing null check (this time for Model)... Are null checks // out of fashion? AssertExtensions.Throws<NullReferenceException> (() => { handler.DoGetScaffoldPageVirtualPath (t, String.Empty); }, "#A2-2"); var wrapper = new MyHttpContextWrapper (); var request = wrapper.Request as MyHttpRequestWrapper; request.SetProperty ("AppRelativeCurrentExecutionFilePath", "~/FooDisplayNameTable/List.aspx"); request.SetProperty ("PathInfo", String.Empty); // This must be non-null because DynamicData doesn't care to check whether the returned // value is null or not... request.SetProperty ("QueryString", new NameValueCollection ()); // This will assign the route handler's Model property RouteData rd = route.GetRouteData (wrapper); Assert.IsNotNull (handler.Model, "#A3"); Assert.AreEqual (handler.Model.DynamicDataFolderVirtualPath + "PageTemplates/" + "MyCustomPage.aspx", handler.DoGetScaffoldPageVirtualPath (t, "MyCustomPage"), "#A4"); handler.Model.DynamicDataFolderVirtualPath = "~/MyFolder"; Assert.AreEqual (handler.Model.DynamicDataFolderVirtualPath + "PageTemplates/" + "MyCustomPage.aspx", handler.DoGetScaffoldPageVirtualPath (t, "MyCustomPage"), "#A5"); // doh! Assert.AreEqual (handler.Model.DynamicDataFolderVirtualPath + "PageTemplates/" + ".aspx", handler.DoGetScaffoldPageVirtualPath (t, null), "#A6"); Assert.AreEqual (handler.Model.DynamicDataFolderVirtualPath + "PageTemplates/" + ".aspx", handler.DoGetScaffoldPageVirtualPath (t, String.Empty), "#A7"); }
public void GetRouteData () { var r = new DynamicDataRoute ("{table}/{action}.aspx"); // We need one which overloads CreateHandler r.RouteHandler = new MyDynamicDataRouteHandler (); var wrapper = new MyHttpContextWrapper (); var request = wrapper.Request as MyHttpRequestWrapper; request.SetProperty ("AppRelativeCurrentExecutionFilePath", "~/NoSuchTable/List.aspx"); request.SetProperty ("PathInfo", String.Empty); // This must be non-null because DynamicData doesn't care to check whether the returned // value is null or not... request.SetProperty ("QueryString", new NameValueCollection ()); // It appears .NET checks whether the indicated table exists - if not, GetRouteData will return // null (even though the Route class will find a match) RouteData rd = r.GetRouteData (wrapper); Assert.IsNull (rd, "#A1"); request.SetProperty ("AppRelativeCurrentExecutionFilePath", "~/BazTable/List.aspx"); rd = r.GetRouteData (wrapper); Assert.IsNotNull (rd, "#B1"); }