+2008-10-16 Atsushi Enomoto <atsushi@ximian.com>
+
+ * Makefile : added -r:System.Data.
+ * System.Web.DynamicData_test.dll.sources : new file.
+
2008-10-14 Atsushi Enomoto <atsushi@ximian.com>
* Makefile, System.Web.DynamicData.dll.sources : initial checkin.
/r:System.dll \
/r:System.Core.dll \
/r:System.ComponentModel.DataAnnotations.dll \
+ /r:System.Data.dll \
/r:System.Data.Linq.dll \
/r:System.Drawing.dll \
/r:System.Web.dll \
+2008-10-16 Atsushi Enomoto <atsushi@ximian.com>
+
+ * ColumnProvider.cs, TableProvider.cs : implemented constructors.
+ * DLinqDataModelProviders.cs : new, DLinq-based implementation.
+
2008-10-14 Atsushi Enomoto <atsushi@ximian.com>
*.cs : initial checkin. stubs.
[AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public abstract class ColumnProvider
{
- [MonoTODO]
protected ColumnProvider (TableProvider table)
{
- throw new NotImplementedException ();
+ if (table == null)
+ throw new ArgumentNullException ("table");
+ this.Table = table;
}
[MonoTODO]
--- /dev/null
+//
+// DLinqDataModelProvider.cs
+//
+// Author:
+// Atsushi Enomoto <atsushi@ximian.com>
+//
+// Copyright (C) 2008 Novell Inc. http://novell.com
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Data.Linq;
+using System.Data.Linq.Mapping;
+using System.Linq;
+using System.Security.Permissions;
+
+using DMetaModel = System.Data.Linq.Mapping.MetaModel;
+using DMetaTable = System.Data.Linq.Mapping.MetaTable;
+
+namespace System.Web.DynamicData.ModelProviders
+{
+ class DLinqDataModelProvider : DataModelProvider
+ {
+ Func<object> factory;
+ DMetaModel model;
+
+ public DLinqDataModelProvider (Func<object> factory)
+ {
+ this.factory = factory;
+ Type type = CreateContext ().GetType ();
+
+ if (!typeof (DataContext).IsAssignableFrom (type))
+ throw new ArgumentException (String.Format ("Type '{0}' is not supported as data context factory", type));
+
+ this.factory = factory;
+
+ model = new AttributeMappingSource ().GetModel (type);
+ ContextType = model.ContextType;
+
+ var l = new List<TableProvider> ();
+ foreach (var m in model.GetTables ())
+ l.Add (new DLinqTableProvider (this, m));
+ tables = new ReadOnlyCollection<TableProvider> (l);
+ }
+
+ ReadOnlyCollection<TableProvider> tables;
+
+ public override ReadOnlyCollection<TableProvider> Tables {
+ get { return tables; }
+ }
+
+ public override object CreateContext ()
+ {
+ return factory ();
+ }
+ }
+
+ class DLinqTableProvider : TableProvider
+ {
+ public DLinqTableProvider (DataModelProvider owner, DMetaTable meta)
+ : base (owner)
+ {
+ EntityType = meta.RowType.Type;
+
+ Name = meta.TableName;
+ int idx = Name.LastIndexOf ('.');
+ Name = idx < 0 ? Name : Name.Substring (idx + 1);
+
+ var l = new List<ColumnProvider> ();
+ foreach (var c in meta.RowType.DataMembers)
+ l.Add (new DLinqColumnProvider (this, c));
+ columns = new ReadOnlyCollection<ColumnProvider> (l);
+ }
+
+ MetaTable table;
+ ReadOnlyCollection<ColumnProvider> columns;
+
+ public override ReadOnlyCollection<ColumnProvider> Columns {
+ get { return columns; }
+ }
+
+ public override IQueryable GetQuery (object context)
+ {
+ return ((DataContext) context).GetTable (EntityType);
+ }
+
+ public override string ToString ()
+ {
+ return base.ToString ();
+ }
+ }
+
+ class DLinqColumnProvider : ColumnProvider
+ {
+ public DLinqColumnProvider (TableProvider owner, MetaDataMember meta)
+ : base (owner)
+ {
+ if (owner == null)
+ throw new ArgumentNullException ("owner");
+ if (meta == null)
+ throw new ArgumentNullException ("meta");
+
+ this.meta = meta;
+
+ // FIXME: fill more
+ Name = meta.Name;
+ Nullable = meta.CanBeNull;
+ }
+
+ MetaDataMember meta;
+
+ [MonoTODO]
+ public override string ToString ()
+ {
+ return base.ToString ();
+ }
+ }
+}
{
protected TableProvider (DataModelProvider model)
{
- throw new NotImplementedException ();
+ if (model == null)
+ throw new ArgumentNullException ("model");
+ DataModel = model;
}
+ [MonoTODO]
public abstract ReadOnlyCollection<ColumnProvider> Columns { get; }
[MonoTODO]
public DataModelProvider DataModel { get; private set; }
throw new NotImplementedException ();
}
+ [MonoTODO]
public abstract IQueryable GetQuery (object context);
[MonoTODO]
System.Web.DynamicData.ModelProviders/AssociationDirection.cs
System.Web.DynamicData.ModelProviders/AssociationProvider.cs
System.Web.DynamicData.ModelProviders/ColumnProvider.cs
+System.Web.DynamicData.ModelProviders/DLinqDataModelProviders.cs
System.Web.DynamicData.ModelProviders/DataModelProvider.cs
System.Web.DynamicData.ModelProviders/TableProvider.cs
System.Web.DynamicData/ContextConfiguration.cs
+2008-10-16 Atsushi Enomoto <atsushi@ximian.com>
+
+ * DynamicDataManager.cs, DynamicDataRoute.cs,
+ FieldTemplateFactory.cs, MetaChildrenColumn.cs,
+ MetaColumn.cs, MetaForeignKeyColumn.cs, MetaModel.cs, MetaTable.cs:
+ ongoing implementation.
+
2008-10-14 Atsushi Enomoto <atsushi@ximian.com>
*.cs : initial checkin. stubs.
//
-// DynamicDataExtensions.cs
+// DynamicDataManager.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
public DynamicDataRoute (string url)
: base (url, null)
{
- throw new NotImplementedException ();
}
- [MonoTODO]
public string Action { get; set; }
- [MonoTODO]
+
public MetaModel Model { get; set; }
+
[MonoTODO]
public DynamicDataRouteHandler RouteHandler { get; set; }
- [MonoTODO]
+
public string Table { get; set; }
- [MonoTODO]
+
public string ViewName { get; set; }
[MonoTODO]
[MonoTODO]
public virtual void Initialize (MetaModel model)
{
- throw new NotImplementedException ();
+ if (model == null)
+ throw new ArgumentNullException ("model");
+ Model = model;
+ // FIXME: do something more.
}
[MonoTODO]
[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class MetaChildrenColumn : MetaColumn
{
- internal MetaChildrenColumn ()
+ internal MetaChildrenColumn (MetaTable table, ColumnProvider provider)
+ : base (table, provider)
{
}
[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class MetaColumn : IFieldFormattingOptions
{
- internal MetaColumn ()
+ internal MetaColumn (MetaTable table, ColumnProvider provider)
{
+ Table = table;
+ Provider = provider;
}
[MonoTODO]
[MonoTODO]
public AttributeCollection Attributes { get; private set; }
- [MonoTODO]
- public Type ColumnType { get; private set; }
+ public Type ColumnType {
+ get { return Provider.ColumnType; }
+ }
[MonoTODO]
public bool ConvertEmptyStringToNull { get; private set; }
[MonoTODO]
public string DisplayName { get; private set; }
- [MonoTODO]
- public PropertyInfo EntityTypeProperty { get; private set; }
+ public PropertyInfo EntityTypeProperty {
+ get { return Provider.EntityTypeProperty; }
+ }
[MonoTODO]
public bool HtmlEncode { get; private set; }
[MonoTODO]
public bool IsBinaryData { get; private set; }
- [MonoTODO]
- public bool IsCustomProperty { get; private set; }
+ public bool IsCustomProperty {
+ get { return Provider.IsCustomProperty; }
+ }
[MonoTODO]
public bool IsFloatingPoint { get; private set; }
- [MonoTODO]
- public bool IsForeignKeyComponent { get; private set; }
+ public bool IsForeignKeyComponent {
+ get { return Provider.IsForeignKeyComponent; }
+ }
- [MonoTODO]
- public bool IsGenerated { get; private set; }
+ public bool IsGenerated {
+ get { return Provider.IsGenerated; }
+ }
[MonoTODO]
public bool IsInteger { get; private set; }
[MonoTODO]
public bool IsLongString { get; private set; }
- [MonoTODO]
- public bool IsPrimaryKey { get; private set; }
+ public bool IsPrimaryKey {
+ get { return Provider.IsPrimaryKey; }
+ }
[MonoTODO]
public bool IsReadOnly { get; private set; }
[MonoTODO]
public bool IsString { get; private set; }
- [MonoTODO]
- public int MaxLength { get; private set; }
+ public int MaxLength {
+ get { return Provider.MaxLength; }
+ }
- [MonoTODO]
public MetaModel Model { get; private set; }
- [MonoTODO]
- public string Name { get; private set; }
+ public string Name {
+ get { return Provider.Name; }
+ }
[MonoTODO]
public string NullDisplayText { get; private set; }
- [MonoTODO]
public ColumnProvider Provider { get; private set; }
[MonoTODO]
[MonoTODO]
public string SortExpression { get; private set; }
- [MonoTODO]
public MetaTable Table { get; private set; }
[MonoTODO]
[AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class MetaForeignKeyColumn : MetaColumn
{
- internal MetaForeignKeyColumn ()
+ internal MetaForeignKeyColumn (MetaTable table, ColumnProvider provider)
+ : base (table, provider)
{
}
public class MetaModel
{
static MetaModel default_model;
+ static Exception registration_exception;
- [MonoTODO]
public static MetaModel Default {
- get { throw new NotImplementedException (); }
+ get { return default_model; }
internal set { default_model = value; }
}
[MonoTODO]
+ public static MetaModel GetModel (Type contextType)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public static void ResetRegistrationException ()
+ {
+ registration_exception = null;
+ }
+
+ public MetaModel ()
+ {
+ if (default_model == null)
+ default_model = this;
+
+ DynamicDataFolderVirtualPath = "~/DynamicData/";
+ FieldTemplateFactory = new FieldTemplateFactory ();
+ Tables = new ReadOnlyCollection<MetaTable> (new MetaTable [0]);
+ VisibleTables = new List<MetaTable> ();
+ }
+
+ DataModelProvider provider;
+
+
public string DynamicDataFolderVirtualPath { get; set; }
- [MonoTODO]
+
public IFieldTemplateFactory FieldTemplateFactory { get; set; }
- [MonoTODO]
+
public ReadOnlyCollection<MetaTable> Tables { get; private set; }
- [MonoTODO]
+
public List<MetaTable> VisibleTables { get; private set; }
[MonoTODO]
throw new NotImplementedException ();
}
- [MonoTODO]
- public static MetaModel GetModel (Type contextType)
+ public bool TryGetTable (string uniqueTableName, out MetaTable table)
{
- throw new NotImplementedException ();
+ if (uniqueTableName == null)
+ throw new ArgumentNullException ("uniqueTableName");
+ if (provider != null)
+ foreach (var t in Tables)
+ if (t.Name == uniqueTableName) {
+ table = t;
+ return true;
+ }
+ table = null;
+ return false;
}
- [MonoTODO]
public MetaTable GetTable (string uniqueTableName)
{
- throw new NotImplementedException ();
+ MetaTable mt;
+ if (TryGetTable (uniqueTableName, out mt))
+ return mt;
+ throw new ArgumentException (String.Format ("Table '{0}' does not exist in registered context", uniqueTableName));
}
- [MonoTODO]
public MetaTable GetTable (Type entityType)
{
- throw new NotImplementedException ();
+ if (entityType == null)
+ throw new ArgumentNullException ("entityType");
+ if (provider != null)
+ foreach (var t in Tables)
+ if (t.EntityType == entityType)
+ return t;
+ throw new ArgumentException (String.Format ("Entity type '{0}' does not exist in registered context", entityType));
}
[MonoTODO]
throw new NotImplementedException ();
}
- [MonoTODO]
+ void CheckRegistrationError ()
+ {
+ if (registration_exception != null)
+ throw new InvalidOperationException ("An error occured during context model registration", registration_exception);
+ }
+
public void RegisterContext (Func<object> contextFactory)
{
- throw new NotImplementedException ();
+ RegisterContext (contextFactory, null);
}
- [MonoTODO]
public void RegisterContext (Type contextType)
{
- throw new NotImplementedException ();
+ RegisterContext (contextType, null);
}
- [MonoTODO]
public void RegisterContext (DataModelProvider dataModelProvider)
{
- throw new NotImplementedException ();
+ RegisterContext (dataModelProvider, null);
}
- [MonoTODO]
- public void RegisterContext (Func<object> contextFactory, ContextConfiguration configuration)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
public void RegisterContext (Type contextType, ContextConfiguration configuration)
{
- throw new NotImplementedException ();
+ if (contextType == null)
+ throw new ArgumentNullException ("contextType");
+ CheckRegistrationError ();
+Activator.CreateInstance (contextType);
+ RegisterContext (() => Activator.CreateInstance (contextType), configuration);
}
- [MonoTODO]
- public void RegisterContext (DataModelProvider dataModelProvider, ContextConfiguration configuration)
+ public void RegisterContext (Func<object> contextFactory, ContextConfiguration configuration)
{
- throw new NotImplementedException ();
+ if (contextFactory == null)
+ throw new ArgumentNullException ("contextFactory");
+ CheckRegistrationError ();
+ try {
+ // FIXME: entity framework support is not done.
+ RegisterContextCore (new DLinqDataModelProvider (contextFactory), configuration);
+ } catch (Exception ex) {
+ registration_exception = ex;
+ throw;
+ }
}
- [MonoTODO]
- public static void ResetRegistrationException ()
+ public void RegisterContext (DataModelProvider dataModelProvider, ContextConfiguration configuration)
{
- throw new NotImplementedException ();
+ if (dataModelProvider == null)
+ throw new ArgumentNullException ("dataModelProvider");
+ CheckRegistrationError ();
+ try {
+ RegisterContextCore (dataModelProvider, configuration);
+ } catch (Exception ex) {
+ registration_exception = ex;
+ throw;
+ }
}
- [MonoTODO]
- public bool TryGetTable (string uniqueTableName, out MetaTable table)
+ void RegisterContextCore (DataModelProvider dataModelProvider, ContextConfiguration configuration)
{
- throw new NotImplementedException ();
+ var l = new List<MetaTable> ();
+ foreach (var t in dataModelProvider.Tables)
+ l.Add (new MetaTable (this, t, configuration != null && configuration.ScaffoldAllTables));
+ Tables = new ReadOnlyCollection<MetaTable> (l);
+ VisibleTables = l;
}
}
}
[AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class MetaTable
{
- internal MetaTable ()
+ internal MetaTable (MetaModel model, TableProvider provider, bool scaffold)
{
+ this.model = model;
+ Provider = provider;
+ Scaffold = scaffold;
+
+ var l = new List<MetaColumn> ();
+ foreach (var c in provider.Columns)
+ l.Add (new MetaColumn (this, c));
+ Columns = new ReadOnlyCollection<MetaColumn> (l);
+
+ DisplayName = Name;
+ ListActionPath = String.Concat (DisplayName, "/", PageAction.List, ".aspx");
}
+ MetaModel model;
+
[MonoTODO]
public AttributeCollection Attributes { get; private set; }
[MonoTODO]
public string DisplayName { get; private set; }
- [MonoTODO]
- public Type EntityType { get; private set; }
+ public Type EntityType {
+ get { return Provider.EntityType; }
+ }
[MonoTODO]
public string ForeignKeyColumnsNames { get; private set; }
[MonoTODO]
public string ListActionPath { get; private set; }
- [MonoTODO]
- public MetaModel Model { get; private set; }
+ public MetaModel Model {
+ get { return model; }
+ }
- [MonoTODO]
- public string Name { get; private set; }
+ public string Name {
+ get { return Provider.Name; }
+ }
[MonoTODO]
public ReadOnlyCollection<MetaColumn> PrimaryKeyColumns { get; private set; }
- [MonoTODO]
public TableProvider Provider { get; private set; }
- [MonoTODO]
public bool Scaffold { get; private set; }
[MonoTODO]
[MonoTODO]
public object CreateContext ()
{
- throw new NotImplementedException ();
+ return Activator.CreateInstance (EntityType);
}
[MonoTODO]
throw new NotImplementedException ();
}
- [MonoTODO]
public MetaColumn GetColumn (string columnName)
{
- throw new NotImplementedException ();
+ MetaColumn mc;
+ if (TryGetColumn (columnName, out mc))
+ return mc;
+ throw new ArgumentException (String.Format ("Column '{0}' does not exist in the meta table '{1}'", columnName, Name));
}
[MonoTODO]
throw new NotImplementedException ();
}
- [MonoTODO]
public IQueryable GetQuery ()
{
- throw new NotImplementedException ();
+ return GetQuery (CreateContext ());
}
[MonoTODO]
throw new NotImplementedException ();
}
- [MonoTODO]
public bool TryGetColumn (string columnName, out MetaColumn column)
{
- throw new NotImplementedException ();
+ foreach (var m in Columns)
+ if (m.Name == columnName) {
+ column = m;
+ return true;
+ }
+ column = null;
+ return false;
}
}
}
--- /dev/null
+System.Web.DynamicData/MetaModelTest.cs
--- /dev/null
+2008-10-16 Atsushi Enomoto <atsushi@ximian.com>
+
+ * MetaModelTest.cs : initial checkin.
--- /dev/null
+//
+// MetaModelTest.cs
+//
+// Author:
+// Atsushi Enomoto <atsushi@ximian.com>
+//
+// Copyright (C) 2008 Novell Inc. http://novell.com
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Collections.Specialized;
+using System.ComponentModel;
+using System.Data.SqlClient;
+using System.Data.Linq;
+using System.Data.Linq.Mapping;
+using System.Globalization;
+using System.Reflection;
+using System.Security.Permissions;
+using System.Security.Principal;
+using System.Web.Caching;
+using System.Web.DynamicData;
+using System.Web.DynamicData.ModelProviders;
+using NUnit.Framework;
+
+namespace System.Web.DynamicData
+{
+ [TestFixture]
+ public class MetaModelTest
+ {
+ [Test]
+ public void Default ()
+ {
+ Assert.IsNull (MetaModel.Default, "#1");
+ var m = new MetaModel (); // it automatically fills Default
+ Assert.AreEqual (m, MetaModel.Default, "#2");
+ Assert.IsNotNull (m.Tables, "#3");
+ Assert.IsNotNull (m.VisibleTables, "#4");
+ Assert.IsNotNull (m.FieldTemplateFactory, "#5");
+ Assert.AreEqual ("~/DynamicData/", m.DynamicDataFolderVirtualPath, "#6");
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void GetTableNull ()
+ {
+ new MetaModel ().GetTable ((Type) null);
+ }
+
+ [Test]
+ 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 ();
+ }
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void RegisterContext2 ()
+ {
+ try {
+ var m = new MetaModel ();
+ m.RegisterContext (typeof (Bar)); // not supported
+ } finally {
+ MetaModel.ResetRegistrationException ();
+ }
+ }
+
+ [Test]
+ [ExpectedException (typeof (MissingMethodException))]
+ public void RegisterContext3 ()
+ {
+ var m = new MetaModel ();
+ try {
+ // no public constructor
+ m.RegisterContext (typeof (DataContext));
+ } finally {
+ MetaModel.ResetRegistrationException ();
+ }
+ }
+
+ [Test]
+ public void RegisterContext4 ()
+ {
+ var m = new MetaModel ();
+ try {
+ m.RegisterContext (typeof (MyDataContext1));
+ Assert.AreEqual (0, m.Tables.Count, "#1-1");
+ Assert.AreEqual (0, m.VisibleTables.Count, "#1-2");
+ } finally {
+ MetaModel.ResetRegistrationException ();
+ }
+ }
+
+ [Test]
+ public void RegisterContext5 ()
+ {
+ var m = new MetaModel ();
+ try {
+ m.RegisterContext (typeof (MyDataContext2));
+ Assert.AreEqual (1, m.Tables.Count, "#1-1");
+ // VisibleTables property somehow requires live HttpContext.
+ //Assert.AreEqual (1, m.VisibleTables.Count, "#1-2");
+ MetaTable t = m.Tables [0];
+ // Those names are only the last part before '.' (i.e. without schema name).
+ Assert.AreEqual ("FooTable", t.Name, "#2-1");
+ Assert.AreEqual ("FooTable", t.DisplayName, "#2-2");
+ // FIXME: test it too.
+ //Assert.AreEqual ("FooTable", t.DataContextPropertyName, "#2-3");
+ Assert.AreEqual ("FooTable", t.Provider.Name, "#3-1");
+ } finally {
+ MetaModel.ResetRegistrationException ();
+ }
+ }
+
+ [Test]
+ 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 ();
+ }
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void GetTableObject ()
+ {
+ // entity type 'System.Object' not found.
+ new MetaModel ().GetTable (typeof (object));
+ }
+ }
+
+ class MyDataContext1 : DataContext
+ {
+ public MyDataContext1 ()
+ : base (new SqlConnection ("Data Source=localhost"))
+ {
+ }
+ }
+
+ [Database (Name = "MyDB1")]
+ class MyDataContext2 : DataContext
+ {
+ public MyDataContext2 ()
+ : base (new SqlConnection ("Data Source=localhost"))
+ {
+ }
+
+ public Table<Foo> FooTable { get { return GetTable<Foo> (); } }
+ }
+
+ [Table (Name = "dbo...FooTable")]
+ class Foo
+ {
+ public Foo ()
+ {
+ throw new Exception ("ERROR");
+ }
+
+ [Column (Name = "Col1")]
+ public string Column1 { get; set; }
+ }
+
+ [Table (Name = "BarTable")]
+ class Bar
+ {
+ [Column (Name = "Col1")]
+ public string Column1 { get; set; }
+
+ [Column (Name = "Col2")]
+ public string Column2 { get; set; }
+ }
+}