Created
September 29, 2011 15:19
-
-
Save alecwhittington/1250958 to your computer and use it in GitHub Desktop.
Testing a Task
This file contains 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
[TestFixture] | |
public class MyTaskTests | |
{ | |
private MyTask sut; | |
private IRepository<Help> helpRepository; | |
private IAnotherRepository anotherRepository; | |
[Test] | |
public void My_Sample_Test() | |
{ | |
// Arrange | |
Another result; | |
Another toSave = new Another { MyValue = 1 }; | |
this.anotherRepository.Stub(a => a.SaveOrUpdate(null)).IgnoreArguments().Return(new Another()); | |
//// You could create a return item above the previous line - assign it properties, etc, then return that instead. | |
// Act | |
result = this.sut.SaveOrUpdate(toSave); | |
// Assert | |
this.anotherRepository.AssertWasCalled(a => a.SaveOrUpdate(Arg<Another>.Is.Anything)); | |
//// Other assertions here. | |
} | |
[SetUp] | |
public void SetUp() | |
{ | |
this.helpRepository = MockRepository.GenerateStub<IRepository<Help>>(); | |
this.anotherRepository = MockRepository.GenerateStub<IAnotherRepository>(); | |
this.sut = new MyTask(this.helpRepository, this.anotherRepository); | |
} | |
[TearDown] | |
public void TearDown() | |
{ | |
this.sut = null; | |
this.helpRepository = null; | |
this.anotherRepository = null; | |
} | |
} |
This file contains 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
public class MyTask : IMyTask | |
{ | |
private readonly IRepository<Help> helpRepository; | |
private readonly IAnotherRepository anotherRepository; | |
public MyTask(IRepository<Help> helpRepository, IAnotherRepository anotherRepository) | |
{ | |
this.helpRepository = helpRepository; | |
this.anotherRepository = anotherRepository; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment