I started to use Rhino-Mocks and Unit-Tests a few days ago so I'm new in this.
I created a disposable class like this:
public class SomeClass : IDisposable
{
private bool _disposed;
public SomeOtherClass ObjB { get; private set; }
public SomeClass(SomeOtherClass b)
{
ObjB = b;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (_disposed)
return;
if (disposing)
{
// set all properties to null
ObjB = null;
// ...
}
_disposed = true;
}
}
and the unit test which should check if the dispose was done correctly:
[TestFixture]
public class SomeClassTests
{
[Test]
public void ShouldDisposeCorrectly()
{
var classB = MockRepository.GenerateStrictMock<SomeOtherClass>()
SomeClass smth;
using (smth = MockRepository.GenerateStrictMock<SomeClass>(classB))
{ }
smth.Expect(p => p.ObjB).Should().BeNull();
}
}
Now when I start the test it throws the following error: Rhino.Mocks.Exceptions.ExpectationViolationException : SomeClass.Dispose(True); Expected #0, Actual #1.
Can you help me to find the missing step? :-)