|
using System;
using System.Data;
using Model;
using Model.Data.Interfaces;
using NUnit.Framework;
using Presentation.Interfaces;
using Rhino.Mocks;
using Rhino.Mocks.Constraints;
namespace Presentation.Tests
{
[TestFixture]
public class EmployeesPresenterFixture
{
MockRepository mocks = null;
IDataReader dataReader = null;
IEmployeesView view = null;
IDomainDAO<IEmployee> model = null;
EmployeesPresenter presenter = null;
private int employeeID = 1;
private int eventProductID = 0;
[SetUp]
public void SetUp()
{
mocks = new MockRepository();
view = mocks.DynamicMock<IEmployeesView>();
model = mocks.DynamicMock<IDomainDAO<IEmployee>>();
dataReader = mocks.DynamicMock<IDataReader>();
presenter = new EmployeesPresenter(view, model);
}
[TearDown]
public void TestCleanup()
{
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void NullViewShouldThrowArgumentNullException()
{
presenter = new EmployeesPresenter(null, model);
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void NullModelShouldThrowArgumentNullException()
{
presenter = new EmployeesPresenter(view, null);
}
[Test]
public void InitViewShouldSetEmployeesAndRefreshTimeOnViewWhenIsPostBackIsFalse()
{
SetUpInitView();
presenter.InitView(false);
mocks.VerifyAll();
}
[Test]
public void InitViewShouldAlwaysSetRefreshTimeOnView()
{
SetUpInitView();
presenter.InitView(false);
presenter.InitView(true);
mocks.VerifyAll();
}
private void SetUpInitView()
{
view.SetEmployees(dataReader);
LastCall.Constraints(Is.TypeOf(typeof(IDataReader)) && Is.NotNull());
SetupResult.For(model.FetchAllByName(true)).Return(dataReader);
view.SetRefreshTime(DateTime.Now);
LastCall.Constraints(Is.TypeOf(typeof(DateTime)) && Is.NotNull());
mocks.ReplayAll();
}
[Test]
public void UpdateEmployeeDetailsShouldSetEmployeeDetailsOnView()
{
IEmployee employee = mocks.DynamicMock<IEmployee>();
SetupResult.For(model.FetchByID(employeeID.ToString())).Return(employee);
view.SetEmployeeDetails(employee);
LastCall.Constraints(Is.TypeOf(typeof(IEmployee)) && Is.NotNull());
mocks.ReplayAll();
presenter.UpdateEmployeeDetails(employeeID.ToString());
mocks.VerifyAll();
}
[Test]
public void EditEmployeeShouldRaiseRequestEmployeeEditEvent()
{
presenter.RequestEmployeeEdit += new EventHandler<SingleValueEventArgs<int>>(RequestEmployeeEditListener);
Assert.AreEqual(0, eventProductID);
presenter.EditEmployee(employeeID);
Assert.AreEqual(1, eventProductID);
}
private void RequestEmployeeEditListener(object sender, SingleValueEventArgs<int> e)
{
eventProductID = e.Value;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.