Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to mock System.Data.Linq.Table<MyClass>
    primarykey
    data
    text
    <p>One of my base repository classes contains a method:</p> <pre><code>public abstract class RepositoryBase&lt;T, TDb&gt; : IRepository&lt;T&gt; where T : IEntity where TDb : class, IDbEntity, new() { protected internal abstract Table&lt;TDb&gt; GetTable(); ... } </code></pre> <p>I am writing unit test for derived repository class that contains implementation of mentioned method:</p> <pre><code>public class CmOptionRepository : RepositoryBase&lt;ICmOption, CMCoreDAL.DbData.CMOption&gt;, ICmOptionRepository { protected internal override System.Data.Linq.Table&lt;CMCoreDAL.DbData.CMOption&gt; GetTable() { return Context.CMOptions; } .... } </code></pre> <p>Here: Context - is Linq-model of DB, CMOptions - one of the DB tables.</p> <p>I want my 'GetTable()' method returning a special set of data. </p> <p>I am going to mock the method:</p> <pre><code> System.Data.Linq.Table&lt;CMCoreDAL.DbData.CMOption&gt; table = ...; Mock&lt;CmOptionRepository&gt; mockRepository = new Mock&lt;CmOptionRepository&gt;(MockBehavior.Strict); mockRepository.Setup(mock =&gt; mock.GetTable()).Returns(table); </code></pre> <p>But don't know how to create an instance of <code>System.Data.Linq.Table&lt;CMCoreDAL.DbData.CMOption&gt;</code> class.</p> <p>Question: how can I mock the <code>System.Data.Linq.Table&lt;&gt;</code>? Or probably I need to change method signature in order to avoid <code>System.Data.Linq.Table&lt;&gt;</code> class usage?</p> <p>Please advise. Any thoughts are welcome.</p> <p>P.S. I am using Moq.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload