Created
January 24, 2014 21:45
-
-
Save kshyju/8607255 to your computer and use it in GitHub Desktop.
Unit testing using Rhino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test] | |
public void Index_Action_Should_Return_BugsListVM_Object_With_Correct_Number_Of_Issues() | |
{ | |
//IF the db has 2 issues of Location "SPRNT", the Index action should return 2 items in the Model/ViewModel | |
//Arrange | |
const int fakeTeamID = 1; | |
var _session = MockRepository.GenerateStrictMock<HttpSessionStateBase>(); | |
_session.Stub(s => s["TB_TeamID"]).Return(fakeTeamID); | |
_session.Stub(s => s["CreateAndEditMode"]).Return(false); | |
var _context = MockRepository.GenerateStrictMock<HttpContextBase>(); | |
_context.Stub(c => c.Session).Return(_session); | |
var projectList = new List<Project>(); | |
projectList.Add(new Project { ID = 1, Name = "TeamBinPro", TeamID = fakeTeamID }); | |
projectList.Add(new Project { ID = 2, Name = "kTable", TeamID = fakeTeamID }); | |
var issueList = new List<Issue>(); | |
issueList.Add(new Issue { ID = 1, Title = "js error", Description = "test", TeamID = fakeTeamID, Location = "SPRNT", CreatedBy = new User { ID = 1, FirstName = "Scott" }, Priority = new Priority { ID = 1, Name = "High" }, Category = new Category { ID = 1, Name = "Bug" }, Status = new Status { ID = 1, Name = "New" }, Project = projectList[0] }); | |
issueList.Add(new Issue { ID = 2, Title = "db error", Description = "test", TeamID = fakeTeamID, Location = "SPRNT", CreatedBy = new User { ID = 1, FirstName = "Scott" }, Priority = new Priority { ID = 1, Name = "High" }, Category = new Category { ID = 1, Name = "Bug" }, Status = new Status { ID = 1, Name = "New" }, Project = projectList[0] }); | |
issueList.Add(new Issue { ID = 3, Title = "error", Description = "test", TeamID = fakeTeamID, Location = "BKLOG", CreatedBy = new User { ID = 1, FirstName = "Scott" }, Priority = new Priority { ID = 1, Name = "High" }, Category = new Category { ID = 1, Name = "Bug" }, Status = new Status { ID = 1, Name = "New" }, Project = projectList[0] }); | |
var repository = MockRepository.GenerateStrictMock<IRepositary>(); | |
repository.Stub(s => s.GetProjects(Arg<int>.Is.Anything)).Return(projectList); | |
repository.Stub(s => s.GetIssues()).Return(issueList); | |
IssuesController accntCntrl = new IssuesController(repository); | |
accntCntrl.ControllerContext = new ControllerContext(_context, new RouteData(), accntCntrl); | |
//Act | |
var result = accntCntrl.Index() as ViewResult; | |
var resultModel = result.Model as IssueListVM; | |
//Assert | |
Assert.AreEqual(resultModel.Bugs.Count, 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment