public void GetActionPath_Action_Row() { MetaModel m = Utils.CommonInitialize(true); var route = RouteTable.Routes[0] as MyDynamicDataRoute; MetaTable t = m.Tables[TestDataContext.TableFooWithDefaults]; var foo = new FooWithDefaults(); Assert.AreEqual(String.Empty, t.GetActionPath(null, (object)null), "#A1"); AssertExtensions.Throws <HttpException> (() => t.GetActionPath(PageAction.Details, (object)"test"), "#A2"); Assert.AreEqual(Utils.BuildActionName(t, PageAction.Details, "PrimaryKeyColumn1=primary%20key%20value&PrimaryKeyColumn2=456&PrimaryKeyColumn3=True"), t.GetActionPath(PageAction.Details, foo), "#A3"); t = m.Tables[TestDataContext.TableFooNoDefaultsWithPrimaryKey]; var foo2 = new FooNoDefaultsWithPrimaryKey(); route.GetVirtualPathCalled = false; Assert.AreEqual(Utils.BuildActionName(t, PageAction.Details), t.GetActionPath(PageAction.Details, foo2), "#B1"); Assert.AreEqual(true, route.GetVirtualPathCalled, "#B1-1"); Assert.AreEqual(3, route.GetVirtualPathValues.Count, "#B1-2"); route.GetVirtualPathCalled = false; foo2.PrimaryKeyColumn1 = String.Empty; Assert.AreEqual(Utils.BuildActionName(t, PageAction.Details), t.GetActionPath(PageAction.Details, foo2), "#C1"); Assert.AreEqual(true, route.GetVirtualPathCalled, "#C1-1"); Assert.AreEqual(3, route.GetVirtualPathValues.Count, "#C1-2"); route.GetVirtualPathCalled = false; foo2.PrimaryKeyColumn1 = "SomeValue"; Assert.AreEqual(Utils.BuildActionName(t, PageAction.Details, "PrimaryKeyColumn1=SomeValue"), t.GetActionPath(PageAction.Details, foo2), "#D1"); Assert.AreEqual(true, route.GetVirtualPathCalled, "#D1-1"); Assert.AreEqual(3, route.GetVirtualPathValues.Count, "#D1-2"); }
public void GetActionPath_Action_RouteValues() { MetaModel m = Utils.CommonInitialize(true); var route = RouteTable.Routes[0] as MyDynamicDataRoute; MetaTable t = m.Tables[TestDataContext.TableFooWithDefaults]; var values = new RouteValueDictionary(); // NO null check for the routeValues parameter _again_! AssertExtensions.Throws <NullReferenceException> (() => t.GetActionPath(PageAction.Details, (RouteValueDictionary)null), "#A1"); Assert.AreEqual(Utils.BuildActionName(t, PageAction.Details), t.GetActionPath(PageAction.Details, values), "#A2"); Assert.AreEqual(2, values.Count, "#A3"); // GetActionPath does not check if the Action and Table keys are present in the dictionary... values.Clear(); values.Add("Action", "something"); AssertExtensions.Throws <ArgumentException> (() => { t.GetActionPath(PageAction.Details, values); }, "#B1"); values.Clear(); values.Add("Table", "else"); AssertExtensions.Throws <ArgumentException> (() => { t.GetActionPath(PageAction.Details, values); }, "#B2"); }
public void GetActionPath_Action_PrimaryKeyValues() { MetaModel m = Utils.CommonInitialize(); MetaTable t = m.Tables[TestDataContext.TableFooWithDefaults]; Assert.AreEqual(String.Empty, t.GetActionPath(null, (IList <object>)null), "#A1"); Assert.AreEqual(String.Empty, t.GetActionPath(String.Empty, (IList <object>)null), "#A2"); Assert.AreEqual(String.Empty, t.GetActionPath("BogusValue", (IList <object>)null), "#A3"); }
public void GetActionPath_Action() { MetaModel m = Utils.CommonInitialize(); MetaTable t = m.Tables[TestDataContext.TableFooWithDefaults]; Assert.AreEqual(String.Empty, t.GetActionPath(null), "#A1"); Assert.AreEqual(String.Empty, t.GetActionPath(String.Empty), "#A2"); Assert.AreEqual(String.Empty, t.GetActionPath("SomeInvalidValue"), "#A3"); }
public void GetActionPath_Action_2() { MetaModel m = Utils.CommonInitialize(); MetaTable t = m.Tables[TestDataContext.TableFooWithDefaults]; Assert.AreEqual(Utils.BuildActionName(t, PageAction.Details), t.GetActionPath(PageAction.Details), "#A1"); Assert.AreEqual(Utils.BuildActionName(t, PageAction.Edit), t.GetActionPath(PageAction.Edit), "#A2"); Assert.AreEqual(Utils.BuildActionName(t, PageAction.Insert), t.GetActionPath(PageAction.Insert), "#A3"); Assert.AreEqual(Utils.BuildActionName(t, PageAction.List), t.GetActionPath(PageAction.List), "#A4"); }
private void BindToDataItem(object dataItem) { dataItem = Misc.GetRealDataItem(dataItem); Debug.Assert(dataItem != null, "DataItem is null"); // Try to get the MetaTable from the type and if we can't find it then ---- up. MetaTable table = Misc.GetTableFromTypeHierarchy(dataItem.GetType()); if (table == null) { throw new InvalidOperationException(String.Format( CultureInfo.CurrentCulture, DynamicDataResources.MetaModel_EntityTypeDoesNotBelongToModel, dataItem.GetType().FullName)); } string action = GetActionOrDefaultTo(PageAction.Details); NavigateUrl = table.GetActionPath(action, GetRouteValues(table, dataItem)); if (String.IsNullOrEmpty(Text)) { if (!String.IsNullOrEmpty(DataField)) { Text = DataBinder.GetPropertyValue(dataItem, DataField).ToString(); } else { Text = table.GetDisplayString(dataItem); } } }
private void BindToMetaTable(MetaTable table) { string action = GetActionOrDefaultTo(PageAction.List); NavigateUrl = table.GetActionPath(action, GetRouteValues()); if (String.IsNullOrEmpty(Text)) { Text = table.DisplayName; } }
public void GetActionPath_Action_PrimaryKeyValues_Path() { MetaModel m = Utils.CommonInitialize(true); var route = RouteTable.Routes[0] as MyDynamicDataRoute; MetaTable t = m.Tables[TestDataContext.TableFooWithDefaults]; Assert.AreEqual(String.Empty, t.GetActionPath(null, (IList <object>)null, null), "#A1"); Assert.AreEqual(String.Empty, t.GetActionPath(null, (IList <object>)null, String.Empty), "#A2"); var dataList = new List <object> (); dataList.Add("first item"); // Yet another lack of parameter checking - the number of items passed in the dataList must be at least equal // to the number of columns in the PrimaryKeyColumns collection AssertExtensions.Throws <ArgumentOutOfRangeException> (() => t.GetActionPath(PageAction.Details, dataList), "#A3"); dataList.Add(2); dataList.Add(false); route.GetVirtualPathCalled = false; Assert.AreEqual(Utils.BuildActionName(t, PageAction.Details, "PrimaryKeyColumn1=first%20item&PrimaryKeyColumn2=2&PrimaryKeyColumn3=False"), t.GetActionPath(PageAction.Details, dataList, null), "#A4"); Assert.AreEqual(true, route.GetVirtualPathCalled, "#A4-1"); route.GetVirtualPathCalled = false; Assert.AreEqual("~/SomePath.aspx", t.GetActionPath(null, (IList <object>)null, "~/SomePath.aspx"), "#A5"); Assert.AreEqual(false, route.GetVirtualPathCalled, "#A5-1"); route.GetVirtualPathCalled = false; Assert.AreEqual("~/SomePath.aspx?PrimaryKeyColumn1=first%20item&PrimaryKeyColumn2=2&PrimaryKeyColumn3=False", t.GetActionPath(null, dataList, "~/SomePath.aspx"), "#A6"); Assert.AreEqual(false, route.GetVirtualPathCalled, "#A6-1"); route.GetVirtualPathCalled = false; Assert.AreEqual("~/SomePath.aspx", t.GetActionPath(PageAction.Details, (IList <object>)null, "~/SomePath.aspx"), "#A7"); Assert.AreEqual(false, route.GetVirtualPathCalled, "#A7-1"); route.GetVirtualPathCalled = false; Assert.AreEqual("~/SomePath.aspx?PrimaryKeyColumn1=first%20item&PrimaryKeyColumn2=2&PrimaryKeyColumn3=False", t.GetActionPath(PageAction.Details, dataList, "~/SomePath.aspx"), "#A8"); Assert.AreEqual(false, route.GetVirtualPathCalled, "#A8-1"); route.GetVirtualPathCalled = false; Assert.AreEqual(Utils.BuildActionName(t, PageAction.Details), t.GetActionPath(PageAction.Details, (IList <object>)null, null), "#A9"); Assert.AreEqual(true, route.GetVirtualPathCalled, "#A9-1"); route.GetVirtualPathCalled = false; Assert.AreEqual(Utils.BuildActionName(t, PageAction.Details, "PrimaryKeyColumn1=first%20item&PrimaryKeyColumn2=2&PrimaryKeyColumn3=False"), t.GetActionPath(PageAction.Details, dataList, null), "#A10"); Assert.AreEqual(true, route.GetVirtualPathCalled, "#A10-1"); route.GetVirtualPathCalled = false; Assert.AreEqual(Utils.BuildActionName(t, PageAction.Details), t.GetActionPath(PageAction.Details, (IList <object>)null, String.Empty), "#A11"); Assert.AreEqual(true, route.GetVirtualPathCalled, "#A11-1"); route.GetVirtualPathCalled = false; Assert.AreEqual(Utils.BuildActionName(t, PageAction.Details, "PrimaryKeyColumn1=first%20item&PrimaryKeyColumn2=2&PrimaryKeyColumn3=False"), t.GetActionPath(PageAction.Details, dataList, String.Empty), "#A12"); Assert.AreEqual(true, route.GetVirtualPathCalled, "#A12-1"); }
protected void Page_Load(object sender, EventArgs e) { table = GridDataSource.GetTable(); Title = table.DisplayName; InsertHyperLink.NavigateUrl = table.GetActionPath(PageAction.Insert); // Disable various options if the table is readonly if (table.IsReadOnly) { GridView1.Columns.RemoveAt(0); InsertHyperLink.Visible = false; } }
public void GetActionPath_Action_PrimaryKeyValues_3() { MetaModel m = Utils.CommonInitialize(true); var route = RouteTable.Routes[0] as MyDynamicDataRoute; MetaTable t = m.Tables[TestDataContext.TableFooWithDefaults]; Assert.AreEqual(Utils.BuildActionName(t, PageAction.Details), t.GetActionPath(PageAction.Details, (IList <object>)null), "#A1"); var dataList = new List <object> (); dataList.Add("first item"); // Yet another lack of parameter checking - the number of items passed in the dataList must be at least equal // to the number of columns in the PrimaryKeyColumns collection AssertExtensions.Throws <ArgumentOutOfRangeException> (() => t.GetActionPath(PageAction.Details, dataList), "#A2"); dataList.Add(2); dataList.Add(false); Assert.AreEqual(Utils.BuildActionName(t, PageAction.Details, "PrimaryKeyColumn1=first%20item&PrimaryKeyColumn2=2&PrimaryKeyColumn3=False"), t.GetActionPath(PageAction.Details, dataList), "#A3"); dataList.Clear(); dataList.Add(false); dataList.Add("item"); dataList.Add(5432); // Not even close to correct behavior, but that's how it behaves... Assert.AreEqual(Utils.BuildActionName(t, PageAction.Details, "PrimaryKeyColumn1=False&PrimaryKeyColumn2=item&PrimaryKeyColumn3=5432"), t.GetActionPath(PageAction.Details, dataList), "#A4"); // check the contents of the passed values dictionary // Assert.AreEqual(5, route.GetVirtualPathValues.Count, "#B1"); Assert.IsTrue(route.GetVirtualPathValues.ContainsKey("Action"), "#B1-1"); Assert.AreEqual(PageAction.Details, route.GetVirtualPathValues["Action"], "#B1-2"); Assert.IsTrue(route.GetVirtualPathValues.ContainsKey("Table"), "#B1-3"); Assert.AreEqual(t.Name, route.GetVirtualPathValues["Table"], "#B1-4"); }
public void GetActionPath_Action_PrimaryKeyValues_2() { MetaModel m = Utils.CommonInitialize(true); var route = RouteTable.Routes[0] as MyDynamicDataRoute; MetaTable t = m.Tables[TestDataContext.TableFooWithDefaults]; Assert.AreEqual(Utils.BuildActionName(t, PageAction.Details), t.GetActionPath(PageAction.Details, (IList <object>)null), "#A1"); // check the contents of the passed values dictionary // Assert.AreEqual(2, route.GetVirtualPathValues.Count, "#B1"); Assert.IsTrue(route.GetVirtualPathValues.ContainsKey("Action"), "#B1-1"); Assert.AreEqual(PageAction.Details, route.GetVirtualPathValues["Action"], "#B1-2"); Assert.IsTrue(route.GetVirtualPathValues.ContainsKey("Table"), "#B1-3"); Assert.AreEqual(t.Name, route.GetVirtualPathValues["Table"], "#B1-4"); }
protected void Page_Load(object sender, EventArgs e) { table = GridDataSource.GetTable(); Title = table.DisplayName; InsertHyperLink.NavigateUrl = table.GetActionPath(PageAction.Insert); // Disable various options if the table is readonly if (table.IsReadOnly) { GridView1.Columns[0].Visible = false; InsertHyperLink.Visible = false; } if (!Page.IsPostBack) { ApplyStaticFilters(); ApplySort(); } }
public void GetActionPath_Action_Row_Path() { MetaModel m = Utils.CommonInitialize(true); var route = RouteTable.Routes[0] as MyDynamicDataRoute; MetaTable t = m.Tables[TestDataContext.TableFooWithDefaults]; var foo = new FooWithDefaults(); Assert.AreEqual(String.Empty, t.GetActionPath(null, (object)null, null), "#A1"); Assert.AreEqual(String.Empty, t.GetActionPath(null, (object)null, String.Empty), "#A2"); Assert.AreEqual(Utils.BuildActionName(t, PageAction.Details, "PrimaryKeyColumn1=primary%20key%20value&PrimaryKeyColumn2=456&PrimaryKeyColumn3=True"), t.GetActionPath(PageAction.Details, foo, null), "#A3"); Assert.AreEqual("~/SomePath.aspx", t.GetActionPath(null, (object)null, "~/SomePath.aspx"), "#A4"); Assert.AreEqual("~/SomePath.aspx?PrimaryKeyColumn1=primary%20key%20value&PrimaryKeyColumn2=456&PrimaryKeyColumn3=True", t.GetActionPath(null, foo, "~/SomePath.aspx"), "#A5"); Assert.AreEqual("~/SomePath.aspx", t.GetActionPath(PageAction.Details, (object)null, "~/SomePath.aspx"), "#A6"); Assert.AreEqual("~/SomePath.aspx?PrimaryKeyColumn1=primary%20key%20value&PrimaryKeyColumn2=456&PrimaryKeyColumn3=True", t.GetActionPath(PageAction.Details, foo, "~/SomePath.aspx"), "#A7"); Assert.AreEqual(Utils.BuildActionName(t, PageAction.Details), t.GetActionPath(PageAction.Details, (object)null, null), "#A8"); Assert.AreEqual(Utils.BuildActionName(t, PageAction.Details, "PrimaryKeyColumn1=primary%20key%20value&PrimaryKeyColumn2=456&PrimaryKeyColumn3=True"), t.GetActionPath(PageAction.Details, foo, null), "#A9"); Assert.AreEqual(Utils.BuildActionName(t, PageAction.Details), t.GetActionPath(PageAction.Details, (object)null, String.Empty), "#A10"); Assert.AreEqual(Utils.BuildActionName(t, PageAction.Details, "PrimaryKeyColumn1=primary%20key%20value&PrimaryKeyColumn2=456&PrimaryKeyColumn3=True"), t.GetActionPath(PageAction.Details, foo, String.Empty), "#A11"); }
public void GetActionPath_Action_3() { MetaModel m = MetaModel.Default; var req = new FakeHttpWorkerRequest(); var ctx = new HttpContext(req); HttpContext.Current = ctx; RouteCollection routes = RouteTable.Routes; routes.Clear(); routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx") { Action = PageAction.List, ViewName = "ListDetails", Model = m, RouteHandler = new MyDynamicDataRouteHandler() }); routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx") { Action = PageAction.Details, ViewName = "ListDetails", Model = m, RouteHandler = new MyDynamicDataRouteHandler() }); MetaTable t = m.Tables[TestDataContext.TableFooWithDefaults]; Assert.AreEqual(t.Model, m, "#A0"); Assert.AreEqual(Utils.BuildActionName(t, "ListDetails"), t.GetActionPath(PageAction.Details), "#A1"); Assert.AreEqual(Utils.BuildActionName(t, "ListDetails"), t.GetActionPath(PageAction.List), "#A2"); // Missing routes Assert.AreEqual(String.Empty, t.GetActionPath(PageAction.Edit), "#A3"); Assert.AreEqual(String.Empty, t.GetActionPath(PageAction.Insert), "#A4"); // Add routes for the two above tests routes.Add(new DynamicDataRoute("{table}/EditInsert.aspx") { Action = PageAction.Edit, ViewName = "MyEditInsert", Model = m, RouteHandler = new MyDynamicDataRouteHandler() }); routes.Add(new DynamicDataRoute("{table}/InsertEdit.aspx") { Action = PageAction.Insert, ViewName = "MyEditInsert", Model = m, RouteHandler = new MyDynamicDataRouteHandler() }); Assert.AreEqual(Utils.BuildActionName(t, "ListDetails"), t.GetActionPath(PageAction.Details), "#B1"); Assert.AreEqual(Utils.BuildActionName(t, "ListDetails"), t.GetActionPath(PageAction.List), "#B2"); Assert.AreEqual(Utils.BuildActionName(t, "EditInsert"), t.GetActionPath(PageAction.Edit), "#B3"); Assert.AreEqual(Utils.BuildActionName(t, "InsertEdit"), t.GetActionPath(PageAction.Insert), "#B4"); }
protected void Page_Load( object sender, EventArgs e ) { table = GridDataSource.GetTable(); Title = table.DisplayName; InsertHyperLink.NavigateUrl = table.GetActionPath( PageAction.Insert ) +"?ParentID="+ParentID; // Disable various options if the table is readonly if( table.IsReadOnly ) { GridView1.Columns[ 0 ].Visible = false; InsertHyperLink.Visible = false; } GridDataSource.AutoGenerateWhereClause = false; if( ParentID==null ) { GridDataSource.Where = "ParentID==null"; InsertHyperLink.Visible = false; } else { GridDataSource.Where = "ParentID==" + ParentID; InsertHyperLink.Visible = true; } if( !IsPostBack ) { //using (var dc = new DCFactory<CmsDataContext>()) //{ var catalogItems = SeoPartsCatalogDac.GetVirtualPathItemsById( ParentID ); var crumbItems = new List<object>(); crumbItems.Add( new { Name = "Главная", Url = table.ListActionPath } ); foreach( var c in catalogItems ) crumbItems.Add( new { Name = c.Name, Url = GetListUrl( c.ID ) } ); _breadCrumbsRepeater.DataSource = crumbItems; _breadCrumbsRepeater.DataBind(); var currentItem = catalogItems.LastOrDefault(); if( currentItem != null && catalogItems.All( c => c.Visible ) ) { _previewLink.Visible = true; StringBuilder sb = new StringBuilder(); sb.Append( ConfigurationManager.AppSettings[ "WebSiteUrl" ] ); sb.Append( "/Parts" ); foreach( var urlCode in SeoPartsCatalogBO.GetVirtualPathByItems( catalogItems ) ) { sb.Append( "/" ); sb.Append( urlCode ); } sb.Append( ".aspx" ); _previewLink.NavigateUrl = sb.ToString(); } else { _previewLink.Visible = false; } //} } if (string.IsNullOrEmpty(GridView1.SortExpression)) { GridView1.Sort("Priority", SortDirection.Ascending); } }
private void BindToMetaTable(MetaTable table) { string action = GetActionOrDefaultTo(PageAction.List); NavigateUrl = table.GetActionPath(action, GetRouteValues()); if (String.IsNullOrEmpty(Text)) { Text = table.DisplayName; } }