forked from TimBarcz/rhino-mocks
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add AAA implementation on every tests where it was possible
- Loading branch information
FabienArcellier
committed
Dec 8, 2009
1 parent
d227148
commit 47f74d6
Showing
19 changed files
with
1,707 additions
and
1,238 deletions.
There are no files selected for viewing
24 changes: 12 additions & 12 deletions
24
...tation/00-RhinoMocksIntroduction/00-RhinoMocksIntroduction/Implementation/IProjectView.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
namespace RhinoMocksIntroduction | ||
{ | ||
/// <summary> | ||
/// Minimum implementation to pass the test | ||
/// </summary> | ||
public interface IProjectView | ||
{ | ||
string Title { get; set; } | ||
bool HasChanges { get; set; } | ||
string Ask(string arg1, string arg2); | ||
} | ||
} | ||
namespace RhinoMocksIntroduction | ||
{ | ||
/// <summary> | ||
/// Minimum implementation to pass the test | ||
/// </summary> | ||
public interface IProjectView | ||
{ | ||
string Title { get; set; } | ||
bool HasChanges { get; set; } | ||
string Ask(string arg1, string arg2); | ||
} | ||
} |
57 changes: 29 additions & 28 deletions
57
...on/00-RhinoMocksIntroduction/00-RhinoMocksIntroduction/Implementation/ProjectPresenter.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,29 @@ | ||
namespace RhinoMocksIntroduction | ||
{ | ||
/// <summary> | ||
/// Minimum implementation to pass the test | ||
/// </summary> | ||
public class ProjectPresenter : IProjectPresenter | ||
{ | ||
public IProject m_Prj; | ||
public IProjectView m_View; | ||
|
||
public ProjectPresenter(IProject prj, IProjectView view) | ||
{ | ||
this.m_Prj = prj; | ||
this.m_View = view; | ||
} | ||
|
||
#region IProjectPresenter Members | ||
|
||
bool IProjectPresenter.SaveProjectAs() | ||
{ | ||
string projectName = m_View.Title; | ||
m_View.Ask(null, null); | ||
return false; | ||
} | ||
|
||
#endregion | ||
} | ||
} | ||
using System; | ||
namespace RhinoMocksIntroduction | ||
{ | ||
/// <summary> | ||
/// Minimum implementation to pass the test | ||
/// </summary> | ||
public class ProjectPresenter : IProjectPresenter | ||
{ | ||
public IProject m_Prj; | ||
public IProjectView m_View; | ||
|
||
public ProjectPresenter(IProject prj, IProjectView view) | ||
{ | ||
this.m_Prj = prj; | ||
this.m_View = view; | ||
} | ||
|
||
#region IProjectPresenter Members | ||
|
||
bool IProjectPresenter.SaveProjectAs() | ||
{ | ||
string projectName = m_View.Title; | ||
m_View.Ask(null, null); | ||
return false; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
171 changes: 111 additions & 60 deletions
171
...ntation/00-RhinoMocksIntroduction/00-RhinoMocksIntroduction/RhinoMocksIntroductionTest.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,111 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using NUnit.Framework; | ||
using Rhino.Mocks; | ||
using Rhino.Mocks.Exceptions; | ||
|
||
namespace RhinoMocksIntroduction | ||
{ | ||
/// <summary> | ||
/// The purpose of mock objects is to allow you | ||
/// to test the interactions between components, | ||
/// this is very useful when you test code | ||
/// that doesn't lend itself easily to state based testing. | ||
/// | ||
/// Most of the examples here are tests that check the save routine for a view | ||
/// to see if it is working as expected. | ||
/// </summary> | ||
/// <see cref="http://www.ayende.com/wiki/Rhino+Mocks+Introduction.ashx"/> | ||
public class RhinoMocksIntroductionTest | ||
{ | ||
[Test] | ||
public void SaveProjectAs_CanBeCanceled() | ||
{ | ||
MockRepository mocks = new MockRepository(); | ||
IProjectView projectView = mocks.StrictMock<IProjectView>(); | ||
|
||
Project prj = new Project("Example Project"); | ||
IProjectPresenter presenter = new ProjectPresenter(prj, projectView); | ||
Expect.Call(projectView.Title).Return(prj.Name); | ||
Expect.Call(projectView.Ask(null, null)).Return(null); | ||
|
||
mocks.ReplayAll(); | ||
Assert.IsFalse(presenter.SaveProjectAs()); | ||
mocks.VerifyAll(); | ||
} | ||
|
||
[Test] | ||
[ExpectedException(typeof(ExpectationViolationException), | ||
ExpectedMessage = "IDemo.VoidNoArgs(); Expected #0, Actual #1.")] | ||
public void MockObjectThrowsForUnexpectedCall() | ||
{ | ||
MockRepository mocks = new MockRepository(); | ||
IDemo demo = mocks.StrictMock<IDemo>(); | ||
mocks.ReplayAll(); | ||
demo.VoidNoArgs(); | ||
mocks.VerifyAll();//will never get here | ||
} | ||
|
||
[Test] | ||
public void DyamicMockAcceptUnexpectedCall() | ||
{ | ||
MockRepository mocks = new MockRepository(); | ||
IDemo demo = mocks.DynamicMock<IDemo>(); | ||
mocks.ReplayAll(); | ||
demo.VoidNoArgs(); | ||
mocks.VerifyAll();//works like a charm | ||
} | ||
} | ||
} | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using NUnit.Framework; | ||
using Rhino.Mocks; | ||
using Rhino.Mocks.Exceptions; | ||
|
||
namespace RhinoMocksIntroduction | ||
{ | ||
/// <summary> | ||
/// The purpose of mock objects is to allow you | ||
/// to test the interactions between components, | ||
/// this is very useful when you test code | ||
/// that doesn't lend itself easily to state based testing. | ||
/// | ||
/// Most of the examples here are tests that check the save routine for a view | ||
/// to see if it is working as expected. | ||
/// </summary> | ||
/// <see cref="http://www.ayende.com/wiki/Rhino+Mocks+Introduction.ashx"/> | ||
public class RhinoMocksIntroductionTest | ||
{ | ||
[Test] | ||
public void SaveProjectAs_CanBeCanceled() | ||
{ | ||
MockRepository mocks = new MockRepository(); | ||
IProjectView view = mocks.StrictMock<IProjectView>(); | ||
Project prj = new Project("Example Project"); | ||
IProjectPresenter presenter = new ProjectPresenter(prj, view); | ||
|
||
Expect.Call(view.Title).Return(prj.Name); | ||
Expect.Call(view.Ask(null, null)).Return("a"); | ||
|
||
mocks.ReplayAll(); | ||
Assert.IsFalse(presenter.SaveProjectAs()); | ||
mocks.VerifyAll(); | ||
} | ||
|
||
/// <summary> | ||
/// This Test is the same than above using Arrange/Act/Assert pattern | ||
/// </summary> | ||
[Test] | ||
public void SaveProjectAs_CanBeCanceled_AAA() | ||
{ | ||
//Arrange | ||
IProjectView view = MockRepository.GenerateStrictMock<IProjectView>(); | ||
Project prj = new Project("Example Project"); | ||
IProjectPresenter presenter = new ProjectPresenter(prj, view); | ||
|
||
view.Expect(v => v.Title).Return(null); | ||
view.Expect(v => v.Ask(Arg<string>.Is.Null, Arg<string>.Is.Null)).Return(null); | ||
|
||
//Act | ||
bool isProjectSave = presenter.SaveProjectAs(); | ||
|
||
//Assert | ||
Assert.IsFalse(isProjectSave); | ||
view.VerifyAllExpectations(); | ||
} | ||
|
||
[Test] | ||
[ExpectedException(typeof(ExpectationViolationException), | ||
ExpectedMessage = "IDemo.VoidNoArgs(); Expected #0, Actual #1.")] | ||
public void MockObjectThrowsForUnexpectedCall() | ||
{ | ||
MockRepository mocks = new MockRepository(); | ||
IDemo demo = mocks.StrictMock<IDemo>(); | ||
mocks.ReplayAll(); | ||
demo.VoidNoArgs(); | ||
mocks.VerifyAll();//will never get here | ||
} | ||
|
||
[Test] | ||
[ExpectedException(typeof(ExpectationViolationException), | ||
ExpectedMessage = "IDemo.VoidNoArgs(); Expected #0, Actual #1.")] | ||
public void MockObjectThrowsForUnexpectedCall_AAA() | ||
{ | ||
//Arrange | ||
IDemo demo = MockRepository.GenerateStrictMock<IDemo>(); | ||
|
||
//Act | ||
demo.VoidNoArgs(); | ||
|
||
//Assert is a different, we expect an exception | ||
} | ||
|
||
[Test] | ||
public void DyamicMockAcceptUnexpectedCall() | ||
{ | ||
MockRepository mocks = new MockRepository(); | ||
IDemo demo = mocks.DynamicMock<IDemo>(); | ||
|
||
mocks.ReplayAll(); | ||
demo.VoidNoArgs(); | ||
Assert.Pass(); | ||
mocks.VerifyAll();//works like a charm | ||
} | ||
|
||
[Test] | ||
public void DyamicMockAcceptUnexpectedCall_AAA() | ||
{ | ||
//Arrange | ||
IDemo demo = MockRepository.GenerateMock<IDemo>(); | ||
|
||
//Act | ||
demo.VoidNoArgs(); | ||
|
||
//Assert | ||
Assert.Pass(); | ||
} | ||
} | ||
} |
76 changes: 46 additions & 30 deletions
76
...arted/Documentation/01-RhinoMocksGenerics/01-RhinoMocksGenerics/RhinoMocksGenericsTest.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,46 @@ | ||
using System.Collections.Generic; | ||
using NUnit.Framework; | ||
using Rhino.Mocks; | ||
|
||
namespace RhinoMocksGenerics | ||
{ | ||
/// <summary> | ||
/// While Rhino Mocks is compatible with the .Net framework 1.1, | ||
/// it offer several goodies for those who use the 2.0 version of the .Net framework. | ||
/// | ||
/// Among them are mocking generic interfaces and classes, | ||
/// and using generic version of the methods in order to reduce casting. | ||
/// </summary> | ||
/// <see cref="http://www.ayende.com/wiki/Rhino+Mocks+Generics.ashx"/> | ||
[TestFixture] | ||
public class RhinoMocksGenericsTest | ||
{ | ||
[Test] | ||
public void MockAGenericInterface() | ||
{ | ||
MockRepository mocks = new MockRepository(); | ||
IList<int> list = mocks.StrictMock<IList<int>>(); | ||
Assert.IsNotNull(list); | ||
Expect.Call(list.Count).Return(5); | ||
mocks.ReplayAll(); | ||
Assert.AreEqual(5, list.Count); | ||
mocks.VerifyAll(); | ||
} | ||
} | ||
} | ||
using System.Collections.Generic; | ||
using NUnit.Framework; | ||
using Rhino.Mocks; | ||
|
||
namespace RhinoMocksGenerics | ||
{ | ||
/// <summary> | ||
/// While Rhino Mocks is compatible with the .Net framework 1.1, | ||
/// it offer several goodies for those who use the 2.0 version of the .Net framework. | ||
/// | ||
/// Among them are mocking generic interfaces and classes, | ||
/// and using generic version of the methods in order to reduce casting. | ||
/// </summary> | ||
/// <see cref="http://www.ayende.com/wiki/Rhino+Mocks+Generics.ashx"/> | ||
[TestFixture] | ||
public class RhinoMocksGenericsTest | ||
{ | ||
[Test] | ||
public void MockAGenericInterface() | ||
{ | ||
MockRepository mocks = new MockRepository(); | ||
IList<int> list = mocks.StrictMock<IList<int>>(); | ||
|
||
Expect.Call(list.Count).Return(5); | ||
|
||
mocks.ReplayAll(); | ||
Assert.AreEqual(5, list.Count); | ||
mocks.VerifyAll(); | ||
} | ||
|
||
[Test] | ||
public void MockAGenericInterface_AAA() | ||
{ | ||
//Arrange | ||
IList<int> list = MockRepository.GenerateStrictMock<IList<int>>(); | ||
list.Expect(l => l.Count).Return(5); | ||
|
||
//Act | ||
int count = list.Count; | ||
|
||
//Assert | ||
Assert.AreEqual(5, count); | ||
list.VerifyAllExpectations(); | ||
} | ||
} | ||
} |
Oops, something went wrong.