public void RequiredErrorMessage()
        {
            MetaModel m = Utils.CommonInitialize();

            MetaTable  t  = m.Tables[TestDataContext.TableBaz];
            MetaColumn mc = t.GetColumn("Column1");

            Assert.IsNotNull(mc, "#A1");
//			Assert.IsFalse (String.IsNullOrEmpty (mc.RequiredErrorMessage), "#A2");

            mc = t.GetColumn("ErrorMessageColumn1");
            Assert.IsNotNull(mc, "#B1");
            Assert.IsFalse(String.IsNullOrEmpty(mc.RequiredErrorMessage), "#B2");
            Assert.AreEqual("Custom error message", mc.RequiredErrorMessage, "#B3");

            mc = t.GetColumn("ErrorMessageColumn2");
            Assert.IsNotNull(mc, "#C1");
            Assert.IsFalse(String.IsNullOrEmpty(mc.RequiredErrorMessage), "#C2");

            t  = m.Tables[TestDataContext.TableFooWithMetadataType];
            mc = t.GetColumn("Column6");
            Assert.IsNotNull(mc, "#D1");
            Assert.IsFalse(mc.IsRequired, "#D1-1");
            Assert.AreEqual(0, mc.Attributes.OfType <RequiredAttribute> ().Count(), "#D1-2");
            Assert.AreEqual(String.Empty, mc.RequiredErrorMessage, "#D1-3");
        }
        public void IsRequired()
        {
            MetaModel m = Utils.CommonInitialize();

            MetaTable  t  = m.Tables[TestDataContext.TableFooWithMetadataType];
            MetaColumn mc = t.GetColumn("Column1");

            Assert.IsNotNull(mc, "#A1");
            Assert.IsTrue(mc.IsRequired, "#A1-1");
            Assert.AreEqual(1, mc.Attributes.OfType <RequiredAttribute> ().Count(), "#A1-2");

            mc = t.GetColumn("Column5");
            Assert.IsNotNull(mc, "#B1");
            Assert.IsTrue(mc.IsRequired, "#B1-1");
            Assert.AreEqual(1, mc.Attributes.OfType <RequiredAttribute> ().Count(), "#B1-2");

            // This one is made nullable by the test column provider
            mc = t.GetColumn("Column6");
            Assert.IsNotNull(mc, "#C1");
            Assert.IsFalse(mc.IsRequired, "#C1-1");
            Assert.AreEqual(0, mc.Attributes.OfType <RequiredAttribute> ().Count(), "#C1-2");

            mc = t.GetColumn("Column7");
            Assert.IsNotNull(mc, "#D1");
            Assert.IsTrue(mc.IsRequired, "#D1-1");
            Assert.AreEqual(1, mc.Attributes.OfType <RequiredAttribute> ().Count(), "#D1-2");

            mc = t.GetColumn("Column2");
            Assert.IsNotNull(mc, "#E1");
            Assert.IsTrue(mc.IsRequired, "#F1-1");
            Assert.AreEqual(1, mc.Attributes.OfType <RequiredAttribute> ().Count(), "#E1-2");
        }
Beispiel #3
0
        static void Column_OnLoad(Page p)
        {
            var lc = p.FindControl("ListView1") as ListView;

            Assert.IsNotNull(lc, "#A1");

            var dc = lc.FindChild <DynamicControl> ("FirstName");

            Assert.IsNotNull(dc, "#A1-1");
            Assert.IsNotNull(dc.Column, "#B1");

            // Safe not to check for GetModel's return value - it throws if model isn't found, same
            // goes for GetTable and GetColumn
            MetaTable  table  = MetaModel.GetModel(typeof(EmployeesDataContext)).GetTable("EmployeeTable");
            MetaColumn column = table.GetColumn("FirstName");

            Assert.AreEqual(column, dc.Column, "#B1-1");
            Assert.AreEqual(dc.Column.Table, dc.Table, "#B1-2");

            dc.Column = column;
            Assert.AreEqual(column, dc.Column, "#C1-3");

            column    = table.GetColumn("Active");
            dc.Column = column;
            Assert.AreEqual(column, dc.Column, "#C1-4");

            // Talk about consistency...
            table     = MetaModel.GetModel(typeof(EmployeesDataContext)).GetTable("SeasonalEmployeeTable");
            column    = table.GetColumn("FirstName");
            dc.Column = column;

            Assert.AreNotEqual(dc.Column.Table, dc.Table, "#C1-5");
        }
        public void IsFloatingPoint()
        {
            MetaModel m = Utils.CommonInitialize();

            MetaTable  t  = m.Tables[TestDataContext.TableBazDataTypeDefaultTypes];
            MetaColumn mc = t.GetColumn("Int_Column");

            Assert.IsNotNull(mc, "#A1");
            Assert.AreEqual(false, mc.IsFloatingPoint, "#A1-1");

            mc = t.GetColumn("Long_Column");
            Assert.IsNotNull(mc, "#A2");
            Assert.AreEqual(false, mc.IsFloatingPoint, "#A2-1");

            mc = t.GetColumn("Bool_Column");
            Assert.IsNotNull(mc, "#A3");
            Assert.AreEqual(false, mc.IsFloatingPoint, "#A3-1");

            mc = t.GetColumn("Single_Column");
            Assert.IsNotNull(mc, "#A4");
            Assert.AreEqual(true, mc.IsFloatingPoint, "#A4-1");

            mc = t.GetColumn("Float_Column");
            Assert.IsNotNull(mc, "#A5");
            Assert.AreEqual(true, mc.IsFloatingPoint, "#A5-1");

            mc = t.GetColumn("Double_Column");
            Assert.IsNotNull(mc, "#A6");
            Assert.AreEqual(true, mc.IsFloatingPoint, "#A6-1");

            mc = t.GetColumn("Decimal_Column");
            Assert.IsNotNull(mc, "#A7");
            Assert.AreEqual(true, mc.IsFloatingPoint, "#A7-1");
        }
        public void CreateHandlerParams()
        {
            MetaModel m = Utils.CommonInitialize();

            var       route   = RouteTable.Routes[0] as DynamicDataRoute;
            MetaTable t       = m.Tables[TestDataContext.TableFooEmpty];
            var       handler = route.RouteHandler = new DynamicDataRouteHandler();

            // No null check is made, of course - throws from some internal method
            AssertExtensions.Throws <NullReferenceException> (() =>
            {
                handler.CreateHandler(null, t, PageAction.Details);
            }, "#A1");

            // No null check again - this time throws from GetCustomPageVirtualPath
            AssertExtensions.Throws <NullReferenceException> (() =>
            {
                handler.CreateHandler(route, null, PageAction.Details);
            }, "#A2");

            // And once again, no null check and thrown from GetCustomPageVirtualPath as well
            AssertExtensions.Throws <NullReferenceException> (() =>
            {
                handler.CreateHandler(route, t, null);
            }, "#A3");
        }
Beispiel #6
0
        public void GetPrimaryKeyValues()
        {
            MetaModel m     = Utils.CommonInitialize(true);
            var       route = RouteTable.Routes[0] as MyDynamicDataRoute;

            MetaTable t   = m.Tables[TestDataContext.TableFooWithDefaults];
            var       foo = new FooWithDefaults();

            Assert.IsNull(t.GetPrimaryKeyValues(null), "#A1");
            AssertExtensions.Throws <HttpException> (() => t.GetPrimaryKeyValues("test"), "#A2");

            IList <object> ret = t.GetPrimaryKeyValues(foo);

            Assert.IsNotNull(ret, "#B1");
            Assert.AreEqual(3, ret.Count, "#B2");
            Assert.IsNotNull(ret[0], "#B2-1");
            Assert.IsTrue(ret[0] is string, "#B2-2");
            Assert.AreEqual("primary key value", ret[0], "#B2-3");
            Assert.IsNotNull(ret[1], "#B2-4");
            Assert.IsTrue(ret[1] is int, "#B2-5");
            Assert.AreEqual(456, ret[1], "#B2-6");
            Assert.IsNotNull(ret[2], "#B2-7");
            Assert.IsTrue(ret[2] is bool, "#B2-8");
            Assert.AreEqual(true, ret[2], "#B2-9");

            t = m.Tables[TestDataContext.TableFooNoPrimaryColumns];
            var foo2 = new FooNoPrimaryColumns();

            ret = t.GetPrimaryKeyValues(foo2);
            Assert.IsNotNull(ret, "#C1");
            Assert.AreEqual(0, ret.Count, "#C2");
        }
Beispiel #7
0
        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");
        }
Beispiel #8
0
        public void GetActionPath2()
        {
            var foo = new Foo(true);
            var req = new FakeHttpWorkerRequest();
            var ctx = new HttpContext(req);

            HttpContext.Current = ctx;
            MetaModel m = Utils.GetModel <MyDataContext2> ();

            RouteTable.Routes.Add(
                new DynamicDataRoute("{table}/{action}.aspx")
            {
                Constraints  = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
                Model        = m,
                RouteHandler = new MyDynamicDataRouteHandler()
            });

            // .NET stacktrace:
            //
            // at System.Web.DynamicData.MetaModel.TryGetTable(String uniqueTableName, MetaTable& table)
            // at System.Web.DynamicData.MetaModel.GetTable(String uniqueTableName)
            AssertExtensions.Throws <ArgumentNullException> (() => m.GetActionPath(null, PageAction.List, foo), "#A1");
            Assert.AreEqual(String.Empty, m.GetActionPath("FooTable", null, foo), "#A2");
            Assert.AreEqual("/FooTable/List.aspx", m.GetActionPath("FooTable", PageAction.List, null), "#A3");
            AssertExtensions.Throws <ArgumentException> (() => m.GetActionPath("NoSuchTable", PageAction.List, foo), "#A4");

            Assert.AreEqual("/FooTable/List.aspx", m.GetActionPath("FooTable", "List", foo), "#B1");
        }
Beispiel #9
0
        public void GetPrimaryKeyString_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.GetPrimaryKeyString((object)null), "#A1");
            Assert.AreEqual("primary key value,456,True", t.GetPrimaryKeyString(foo), "#A2");

            var foo2 = new FooNoDefaultsWithPrimaryKey();

            AssertExtensions.Throws <HttpException> (() => t.GetPrimaryKeyString(foo2), "#B1");

            t = m.Tables[TestDataContext.TableFooSettableDefaults];
            var foo3 = new FooSettableDefaults(null, null, null);

            Assert.AreEqual(String.Empty, t.GetPrimaryKeyString(foo3), "#C1");

            foo3 = new FooSettableDefaults(null, String.Empty, null);
            Assert.AreEqual(",,", t.GetPrimaryKeyString(foo3), "#C2");

            foo3 = new FooSettableDefaults(String.Empty, null, null);
            Assert.AreEqual(",,", t.GetPrimaryKeyString(foo3), "#C2");
        }
        public void IsPrimaryKey()
        {
            MetaModel m = Utils.CommonInitialize();

            MetaTable  t  = m.Tables[TestDataContext.TableBaz];
            MetaColumn mc = t.GetColumn("Column1");

            Assert.IsNotNull(mc, "#A1");
            Assert.AreEqual(false, mc.IsPrimaryKey, "#A1-1");
            Assert.AreEqual(mc.Provider.IsPrimaryKey, mc.IsPrimaryKey, "#A1-2");

            mc = t.GetColumn("PrimaryKeyColumn1");
            Assert.IsNotNull(mc, "#A2");
            Assert.AreEqual(true, mc.IsPrimaryKey, "#A2-1");
            Assert.AreEqual(mc.Provider.IsPrimaryKey, mc.IsPrimaryKey, "#A2-2");

            t  = m.Tables[TestDataContext.TableAssociatedFoo];
            mc = t.GetColumn("ForeignKeyColumn1");
            Assert.IsNotNull(mc, "#B1");
            Assert.AreEqual(false, mc.IsPrimaryKey, "#B1-1");
            Assert.AreEqual(mc.Provider.IsPrimaryKey, mc.IsPrimaryKey, "#B1-2");

            mc = t.GetColumn("PrimaryKeyColumn1");
            Assert.IsNotNull(mc, "#B2");
            Assert.AreEqual(true, mc.IsPrimaryKey, "#B2-1");
            Assert.AreEqual(mc.Provider.IsPrimaryKey, mc.IsPrimaryKey, "#B2-2");
        }
Beispiel #11
0
 public void GetModel()
 {
     Utils.GetModel <UseOnlyInGetModelTestDataContext> ();
     AssertExtensions.Throws <ArgumentNullException> (() => MetaModel.GetModel(null), "#A1");
     AssertExtensions.Throws <InvalidOperationException> (() => MetaModel.GetModel(typeof(object)), "#A2");
     Assert.IsNotNull(MetaModel.GetModel(typeof(UseOnlyInGetModelTestDataContext)));
 }
Beispiel #12
0
        public void GetTable()
        {
            MetaModel m = Utils.GetModel <MyDataContext2> ();
            MetaTable t;
            string    str  = null;
            Type      type = null;

            AssertExtensions.Throws <ArgumentNullException> (() => t = m.GetTable(str), "#A1");
            AssertExtensions.Throws <ArgumentNullException> (() => t = m.GetTable(type), "#A2");
            AssertExtensions.Throws <ArgumentNullException> (() => t = m.GetTable(null, null), "#A3");
            AssertExtensions.Throws <ArgumentNullException> (() => t = m.GetTable(null, typeof(Foo)), "#A4");
            AssertExtensions.Throws <ArgumentNullException> (() => t = m.GetTable("FooTable", null), "#A5");

            AssertExtensions.Throws <ArgumentException> (() => t = m.GetTable(String.Empty), "#B1");
            AssertExtensions.Throws <ArgumentException> (() => t = m.GetTable("NoSuchName"), "#B2");
            AssertExtensions.Throws <ArgumentException> (() => t = m.GetTable(typeof(object)), "#B3");
            AssertExtensions.Throws <ArgumentException> (() => t = m.GetTable("FooTable", typeof(object)), "#B4");
            AssertExtensions.Throws <ArgumentException> (() => t = m.GetTable("NoSuchTable", typeof(object)), "#B5");

            Assert.IsNotNull(t = m.GetTable("FooTable"), "#C1");
            Assert.AreEqual(typeof(Foo), t.EntityType, "#C2");
            Assert.IsNotNull(t = m.GetTable(typeof(Foo)), "#C3");
            Assert.AreEqual(typeof(Foo), t.EntityType, "#C4");
            Assert.IsNotNull(t = m.GetTable("FooTable", typeof(MyDataContext2)), "#C5");
            Assert.AreEqual(typeof(Foo), t.EntityType, "#C6");
        }
Beispiel #13
0
        public void BaseDefaultsModification_8()
        {
            MetaModel m   = MetaModel.Default;
            var       req = new FakeHttpWorkerRequest();
            var       ctx = new HttpContext(req);

            HttpContext.Current = ctx;

            RouteCollection routes = RouteTable.Routes;

            routes.Clear();

            var ddr = new DynamicDataRoute("{table}/{action}.aspx")
            {
                Table        = String.Empty,
                Model        = m,
                RouteHandler = new MyDynamicDataRouteHandler()
            };

            routes.Add(ddr);
            var rd = new RouteData();
            var hc = new HttpContextWrapper(HttpContext.Current);

            AssertExtensions.Throws <ArgumentException> (() => {
                ddr.GetVirtualPath(new RequestContext(hc, rd), null);
            }, "#A1");
        }
Beispiel #14
0
        public void GetDisplayString()
        {
            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.GetDisplayString(null), "#A1");
            AssertExtensions.Throws <HttpException> (() => t.GetDisplayString(String.Empty), "#A2");
            Assert.AreEqual("hello", t.GetDisplayString(foo), "#A3");
            AssertExtensions.Throws <HttpException> (() => t.GetDisplayString("TestString"), "#A4");

            // The method looks at the entity type to see if it has an overriden ToString method,
            // it ignores such methods on the passed "row"
            var foo2 = new FooWithToString();

            Assert.AreEqual("hello", t.GetDisplayString(foo2), "#B1");

            t = m.Tables[TestDataContext.TableFooWithToString];
            Assert.AreEqual("ValueFrom_ToString", t.GetDisplayString(foo2), "#C1");

            // If we pass an object which is not of EntityType,
            // the method returns the result of row.ToString ()
            Assert.AreEqual(foo.GetType().ToString(), t.GetDisplayString(foo), "#C2");

            var foo3 = new FooNoDefaultsWithPrimaryKey();

            t = m.Tables[TestDataContext.TableFooNoDefaultsWithPrimaryKey];
            Assert.AreEqual(String.Empty, t.GetDisplayString(foo3), "#D1");
        }
Beispiel #15
0
        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");
        }
Beispiel #16
0
        public void BaseDefaultsModification_7()
        {
            MetaModel m   = MetaModel.Default;
            var       req = new FakeHttpWorkerRequest();
            var       ctx = new HttpContext(req);

            HttpContext.Current = ctx;

            RouteCollection routes = RouteTable.Routes;

            routes.Clear();

            var ddr = new DynamicDataRoute("{table}/{action}.aspx")
            {
                Table        = null,
                Model        = m,
                RouteHandler = new MyDynamicDataRouteHandler()
            };

            routes.Add(ddr);

            Assert.IsNotNull(ddr, "#A1");
            Assert.IsNull(ddr.Defaults, "#A1-1");
            var rd = new RouteData();
            var hc = new HttpContextWrapper(HttpContext.Current);

            ddr.GetVirtualPath(new RequestContext(hc, rd), null);
            Assert.IsNull(ddr.Defaults, "#B1");
        }
Beispiel #17
0
        public void GetQuery_Context()
        {
            MetaModel m = Utils.GetModel <MyDataContext2> ();

            var req = new FakeHttpWorkerRequest();
            var ctx = new HttpContext(req);

            HttpContext.Current = ctx;

            RouteCollection routes = RouteTable.Routes;

            routes.Clear();
            var route = new MyDynamicDataRoute("{table}/{action}.aspx")
            {
                Constraints  = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
                Model        = m,
                RouteHandler = new MyDynamicDataRouteHandler()
            };

            routes.Add(route);

            MetaTable  t     = m.GetTable("FooTable");;
            IQueryable query = t.GetQuery(null);

            Assert.IsNotNull(query, "#A1");
            Assert.IsTrue(query.GetType() == typeof(Table <Foo>), "#A2");

            var foo = new Foo(true);

            AssertExtensions.Throws(() => t.GetQuery(foo), "#B1");
        }
Beispiel #18
0
        public void RegisterContext4()
        {
            MetaModel m = Utils.GetModel <MyDataContext1> ();

            Assert.AreEqual(0, m.Tables.Count, "#1-1");
            Assert.AreEqual(0, m.VisibleTables.Count, "#1-2");
            Assert.IsNotNull(MetaModel.GetModel(typeof(MyDataContext1)), "#2");
        }
Beispiel #19
0
        public void DataContextType()
        {
            MetaModel m = Utils.CommonInitialize();

            MetaTable t = m.Tables[TestDataContext.TableFooEmpty];

            Assert.IsTrue(t.DataContextType == typeof(TestDataContext), "#A1");
        }
Beispiel #20
0
        public void Model()
        {
            MetaModel m = Utils.CommonInitialize();

            MetaTable t = m.Tables[TestDataContext.TableFooWithDefaults];

            Assert.IsTrue(t.Model == m, "#A1");
        }
Beispiel #21
0
 public void RegisterContext2()
 {
     try {
         var m = new MetaModel();
         m.RegisterContext(typeof(Bar));                   // not supported
     } finally {
         MetaModel.ResetRegistrationException();
     }
 }
Beispiel #22
0
        public void Attributes()
        {
            MetaModel m = Utils.CommonInitialize();

            MetaTable t = m.Tables[TestDataContext.TableFooEmpty];

            Assert.IsNotNull(t.Attributes, "#A1");
            Assert.AreEqual(0, t.Attributes.Count, "#A2");
        }
        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");
        }
Beispiel #24
0
        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");
        }
Beispiel #25
0
        public void DataContextPropertyName()
        {
            MetaModel m = Utils.CommonInitialize();

            MetaTable t = m.Tables[TestDataContext.TableFooEmpty];

            Assert.AreEqual("FooEmptyTable", t.DataContextPropertyName, "#A1");
            Assert.AreEqual(t.Name, t.DataContextPropertyName, "#A2");
        }
Beispiel #26
0
        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");
        }
Beispiel #27
0
        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");
        }
Beispiel #28
0
        public void ForeignKeyColumnNames()
        {
            MetaModel m = Utils.CommonInitialize();

            MetaTable t = m.Tables[TestDataContext.TableAssociatedFoo];

            Assert.IsNotNull(t.ForeignKeyColumnsNames, "#A1");
            Assert.IsFalse(t.ForeignKeyColumnsNames.Length == 0, "#A2");
            Assert.AreEqual("ForeignKeyColumn1,ForeignKeyColumn2,PrimaryKeyColumn1", t.ForeignKeyColumnsNames, "#A3");
        }
Beispiel #29
0
        public void Name()
        {
            MetaModel m = Utils.CommonInitialize();

            MetaTable t = m.Tables[TestDataContext.TableFooWithDefaults];

            Assert.IsNotNull(t.Name, "#A1");
            Assert.IsTrue(t.Name.Length > 0, "#A2");
            Assert.AreEqual("FooWithDefaultsTable", t.Name, "#A3");
        }
Beispiel #30
0
        public void Provider()
        {
            MetaModel m     = Utils.CommonInitialize(true);
            var       route = RouteTable.Routes[0] as MyDynamicDataRoute;

            MetaTable t = m.Tables[TestDataContext.TableFooWithDefaults];

            Assert.IsTrue(t.Provider != null, "#A1");
            Assert.AreEqual("FooWithDefaultsTable", t.Provider.Name, "#A1");
        }
Beispiel #31
0
		public void DefaultValues ()
		{
			var model = new MetaModel ();

			Assert.IsNotNull (MetaModel.Default, "#A1");

			// We can't be sure which model will be the default one when running under Nunit
			//Assert.IsTrue (MetaModel.Default == defaultModel, "#A2");
			Assert.IsNotNull (model.Tables, "#A3");
			Assert.IsNotNull (model.VisibleTables, "#A4");
			Assert.IsNotNull (model.FieldTemplateFactory, "#A5");
			Assert.AreEqual ("~/DynamicData/", model.DynamicDataFolderVirtualPath, "#A6");

			Assert.AreEqual (0, model.VisibleTables.Count, "#B1");
			Assert.AreEqual (0, model.Tables.Count, "#B2");
			Assert.AreEqual (typeof (FieldTemplateFactory), model.FieldTemplateFactory.GetType (), "#B3");
		}
Beispiel #32
0
		public void Constructor ()
		{
			// other tests create MetaModel and set Default and this test does not always run first, so it does not make sense anymore.
			//Assert.IsNull (MetaModel.Default, "#1");
			bool isFirst = (MetaModel.Default == null);
			var m = new MetaModel (); // it automatically fills Default
			if (isFirst)
				Assert.AreEqual (m, MetaModel.Default, "#2");

			var r = new DynamicDataRoute ("Dynamic1");
			Assert.AreEqual (MetaModel.Default, r.Model, "#1");
			Assert.IsNull (r.Action, "#2");
			Assert.IsNull (r.Table, "#3");
			Assert.IsNull (r.ViewName, "#4");
			Assert.IsNotNull (r.RouteHandler, "#5");
			Assert.IsNotNull (r.Model, "#6");
			Assert.IsNull (r.RouteHandler.Model, "#7"); // irrelevant to route's MetaModel
		}
Beispiel #33
0
		public void RegisterContext ()
		{
			var m = new MetaModel ();
			try {
				m.RegisterContext (typeof (Foo));
				Assert.Fail ("#1");
			} catch (TargetInvocationException ex) {
				Assert.AreEqual ("ERROR", ex.InnerException.Message, "#2");
			} finally {
				MetaModel.ResetRegistrationException ();
			}
		}
Beispiel #34
0
		public void RegisterContext3 ()
		{
			var m = new MetaModel ();
			try {
				// no public constructor
				m.RegisterContext (typeof (DataContext));
			} finally {
				MetaModel.ResetRegistrationException ();
			}
		}
Beispiel #35
0
		public void ResetRegistrationException ()
		{
			MetaModel.ResetRegistrationException ();

			var m = new MetaModel ();
			try {
				m.RegisterContext (typeof (Foo));
				Assert.Fail ("#1");
			} catch (TargetInvocationException) {
			}

			try {
				m.RegisterContext (typeof (MyDataContext1));
				Assert.Fail ("#2");
			} catch (InvalidOperationException) {
			} finally {
				MetaModel.ResetRegistrationException ();
			}
		}
Beispiel #36
0
		static MetaModelTest ()
		{
			defaultModel = new MetaModel ();
		}
Beispiel #37
0
		public void DynamicDataFolderVirtualPath ()
		{
			var model = new MetaModel ();

			Assert.AreEqual ("~/DynamicData/", model.DynamicDataFolderVirtualPath, "#A1");
			model.DynamicDataFolderVirtualPath = null;
			Assert.AreEqual ("~/DynamicData/", model.DynamicDataFolderVirtualPath, "#A2");
			model.DynamicDataFolderVirtualPath = String.Empty;
			Assert.AreEqual (String.Empty, model.DynamicDataFolderVirtualPath, "#A3");
			model.DynamicDataFolderVirtualPath = "~/FolderNoTrailingSlash";
			Assert.AreEqual ("~/FolderNoTrailingSlash/", model.DynamicDataFolderVirtualPath, "#A4");
			model.DynamicDataFolderVirtualPath = "AnotherFolder";
			Assert.AreEqual ("AnotherFolder/", model.DynamicDataFolderVirtualPath, "#A5");
			model.DynamicDataFolderVirtualPath = "/YetAnotherFolder";
			Assert.AreEqual ("/YetAnotherFolder/", model.DynamicDataFolderVirtualPath, "#A6");
			model.DynamicDataFolderVirtualPath = null;
			Assert.AreEqual ("~/DynamicData/", model.DynamicDataFolderVirtualPath, "#A7");
		}
Beispiel #38
0
		public void RegisterContext2 ()
		{
			try {
				var m = new MetaModel ();
				m.RegisterContext (typeof (Bar)); // not supported
			} finally {
				MetaModel.ResetRegistrationException ();
			}
		}