Note that there are some explanatory texts on larger screens.

plurals
  1. PORhino Mocks / Repository testing - NUnit test suite fails, but single mocked unit test passes?
    primarykey
    data
    text
    <p>As per my previous question: <a href="https://stackoverflow.com/questions/8122145/rhino-mocks-testing-repository-layer-returns-object-reference-not-set-to-inst">Rhino Mocks - Testing Repository layer returns &quot;object reference not set to instance&quot; error</a></p> <p>I am having an issue when passing the NUnit test when it is run in conjunction with the other tests in the suite.</p> <p>The entire test class is as follows:</p> <pre><code>using System; using System.Linq; using System.Linq.Expressions; using NUnit.Framework; using System.Collections.Generic; using Rhino.Mocks; using Assert = NUnit.Framework.Assert; Tests.DAO { /// &lt;summary&gt; /// Uses the 3A method of Unit Testing; Arrange, Act, Assert. /// /// Tests the Billing DAO /// &lt;/summary&gt; [TestFixture] public class BillingTests { private IDataContextWrapper _dataContext; private Repository _intRepository; /// &lt;summary&gt; /// Sets up the following constructs for testing. /// /// - DataContext /// - InternalRepository /// - Billing /// &lt;/summary&gt; [TestFixtureSetUp] public void TestFixtureSetup() { _dataContext = MockRepository.GenerateMock&lt;IDataContextWrapper&gt;(); } /// &lt;summary&gt; /// /// &lt;/summary&gt; [TestFixtureTearDown] public void TestFixtureTearDown() { _dataContext.Dispose(); } /// &lt;summary&gt; /// Tests adding a Billing object to the Database. /// &lt;/summary&gt; [Test] public void Add() { // Arrange var billing = new Billing(); _intRepository = new Repository(_dataContext); // Act _intRepository.AddRecord(billing); // Assert _dataContext.AssertWasCalled(x =&gt; x.InsertOnSubmit(billing)); _dataContext.AssertWasCalled(x =&gt; x.SubmitChanges()); } /// &lt;summary&gt; /// The test attempts to remove the Billing before asserting that it no-longer /// exists in the database by attempting to delete it again. /// &lt;/summary&gt; [Test] public void Delete() { // Arrange var billing = new Billing(); _intRepository = new Repository(_dataContext); // Arrange _intRepository.DeleteRecord(billing); // Assert _dataContext.AssertWasCalled(x =&gt; x.DeleteOnSubmit(billing)); _dataContext.AssertWasCalled(x =&gt; x.SubmitChanges()); } /// &lt;summary&gt; /// The test retrieves the Billing from /// the database and asserts that /// the original Billing and /// the one retrieved are the same. /// &lt;/summary&gt; [Test] public void GetRecordWhere() { // Arrange var list = new List&lt;Billing&gt; {new Billing {BillingId = 1}}; const int testId = 1; _dataContext.Stub(x =&gt; x.GetTable&lt;Billing&gt;()).Return(list.AsQueryable()); _intRepository = new Repository(_dataContext); // Act var result = _intRepository.GetRecordWhere&lt;Billing&gt;(x =&gt; x.BillingId == testId); // Assert Assert.IsNotNull(result); Assert.AreEqual(result.BillingId, testId); _dataContext.AssertWasCalled(x =&gt; x.GetTable&lt;Billing&gt;()); } /// &lt;summary&gt; /// /// &lt;/summary&gt; [Test] public void GetAllRecordsWhere() { } /// &lt;summary&gt; /// Retrieves the total number of Billings in the database /// and compares it against how many were added by the testFixture. /// &lt;/summary&gt; [Test] public void GetAllBillings() { // Arrange _dataContext.Stub(x =&gt; x.GetTable&lt;Billing&gt;()).Return(new List&lt;Billing&gt; { new Billing { BillingId = 1 } }.AsQueryable()); _intRepository = new Repository(_dataContext); // Act var result = _intRepository.GetAllRecords&lt;Billing&gt;(); // Assert Assert.AreEqual(typeof(EnumerableQuery&lt;Billing&gt;), result.GetType()); _dataContext.AssertWasCalled(x =&gt; x.GetTable&lt;Billing&gt;()); } /// &lt;summary&gt; /// Tests find all Billings. Expects the return type to be of IQeryable /// &lt;/summary&gt; [Test] public void FindAllBillings() { // Arrange _dataContext.Stub(x =&gt; x.GetTable&lt;Billing&gt;()).Return(new List&lt;Billing&gt;().AsQueryable()); _intRepository = new Repository(_dataContext); // Act var result = _intRepository.FindAll&lt;Billing&gt;(); // Assert Assert.IsNotNull(result); Assert.AreEqual(typeof(EnumerableQuery&lt;Billing&gt;), result.GetType()); } } } </code></pre> <p>The test which has now been fixed (or rather my understanding has been fixed) passes when run on its own. But not when the tests are run together? Am i missing something in the SetUp / TearDown features of NUnit? Is the dataContext or the Repository being persisted where i want it not to be?</p> <p>Thanks for any help!</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.
 

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