示例#1
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");
		}
示例#2
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");
		}
示例#3
0
		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");
		}
示例#4
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");
		}
示例#5
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");
		}