Skip to content

Instantly share code, notes, and snippets.

@Rookian
Created March 26, 2012 11:43
Show Gist options
  • Save Rookian/2204561 to your computer and use it in GitHub Desktop.
Save Rookian/2204561 to your computer and use it in GitHub Desktop.
FakeItEasyAbstractClassAndVirtualMembers
[Subject(typeof(Presenter<>))]
public class When_disposing_a_presenter
{
static IUnitOfWork UnitOfWork;
static Presenter<IView> Presenter;
static IView View;
Establish context = () =>
{
UnitOfWork = A.Fake<IUnitOfWork>();
View = A.Fake<IView>();
Presenter = A.Fake<Presenter<IView>>(); //new TestPresenter(View, UnitOfWork);
};
Because of = () => Presenter.Dispose();
It should_dispose_the_unit_of_work = () => A.CallTo(() => UnitOfWork.Dispose()).MustHaveHappened();
class TestPresenter : Presenter<IView>
{
public TestPresenter(IView currentView, IUnitOfWork unitOfWork) : base(currentView, unitOfWork) { }
}
}
public interface IUnitOfWork : IDisposable
{
void Commit();
void RollBack();
}
public abstract class Presenter<TView> : IPresenter<TView> where TView : class
{
readonly TView _currentView;
readonly IUnitOfWork _unitOfWork;
protected Presenter(TView currentView, IUnitOfWork unitOfWork)
{
_currentView = currentView;
_unitOfWork = unitOfWork;
Ensure.That(currentView).IsNotNull();
Ensure.That(unitOfWork).IsNotNull();
}
public TView CurrentView
{
get { return _currentView; }
}
public virtual void Dispose()
{
_unitOfWork.Dispose();
}
protected void ShowDialog(IView newForm, object parent)
{
newForm.ShowDialog((IWin32Window) parent);
}
}
public interface IPresenter<out TView> : IDisposable
{
TView CurrentView { get; }
}
public interface IView : IDisposable
{
event EventHandler CloseClick;
void Close();
DialogResult ShowDialog(IWin32Window parent);
}
@Rookian
Copy link
Author

Rookian commented Mar 26, 2012

OK, thank you Björn :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment