I am writing a unit test to Mock a System.Data.Linq.Table in a data context. My code is as follows (Please find the data context, the entity and the unit test) below. The code does not compile saying it cannot resolve the method. How can I alter this code to be a well formed test?
[global::System.Data.Linq.Mapping.DatabaseAttribute(Name = "MyDB")]
public partial class Table1DataContext : System.Data.Linq.DataContext
{
private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
partial void OnCreated();
public Table1DataContext() :
base(global::Properties.Settings.Default.DBConnectionString, mappingSource)
{
OnCreated();
}
public System.Data.Linq.Table<Table1Definition> Table1Definitions
{
get
{
return this.GetTable<Table1Definition>();
}
}
}
[global::System.Data.Linq.Mapping.TableAttribute(Name = "dbo.Table1Definition")]
public partial class Table1Definition : INotifyPropertyChanging, INotifyPropertyChanged
{
private int _ID;
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_ID", AutoSync = AutoSync.OnInsert, DbType = "Int NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
public int ID
{
get
{
return this._ID;
}
set
{
if ((this._ID != value))
{
this.OnIDChanging(value);
this.SendPropertyChanging();
this._ID = value;
this.SendPropertyChanged("ID");
this.OnIDChanged();
}
}
}
public event PropertyChangingEventHandler PropertyChanging;
public event PropertyChangedEventHandler PropertyChanged;
partial void OnIDChanging(int value);
partial void OnIDChanged();
protected virtual void SendPropertyChanging()
{
if ((this.PropertyChanging != null))
{
this.PropertyChanging(this, emptyChangingEventArgs);
}
}
protected virtual void SendPropertyChanged(String propertyName)
{
if ((this.PropertyChanged != null))
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
[TestClass]
public class TestClass
{
private Mock<Table1DataContext> dataContextMock;
[TestMethod]
public void ShoulReturnValidDefinition()
{
this.dataContextMock = new Mock<Table1DataContext>();
this.dataContextMock.SetupGet(x => x.Table1Definitions).Returns(GetFakeEntityDefinition());
}
private static IList<Table1Definition> GetFakeEntityDefinition()
{
return new List<Table1Definition> { new Table1Definition { ID = 1 } };
}
}
Aucun commentaire:
Enregistrer un commentaire