''' <summary>
''' This the view of the calendars
''' </summary>
Public Interface ICalendarsView
'the events represent user actions that are addressed by the model
Event CreateNewCalendar As EventHandler
Event Save As EventHandler
Event GetCalendarList As EventHandler
Event GetCalendar As EventHandler
Property CalendarName As String
......
'these methods allow the controller to pass data to the view
Sub ShowPreviewForYear(ByVal yearNumber As Integer)
Sub SetCalendar(ByVal c As Calendar)
Sub SetCalendarList(ByVal calList As List(Of Calendar))
End Interface
''' <summary>
''' the Model
''' </summary>
''' <remarks></remarks>
Public Interface ICalendarEngine
Function GetCalendars() As List(Of Calendar)
Function GetCalendar(ByVal name As String) As Calendar
Function CreateNewCalendar(ByVal name As String) As Calendar
Sub SaveCalendar(ByVal c As Calendar)
End Interface
The controller
'' <summary>
''' Controller of the view
''' </summary>
''' <remarks>Instantiated and refers to the model and the view</
remarks>
Public Class CalendarsController
Private WithEvents _view As ICalendarsView
Private _model As ICalendarEngine
Public Sub New(ByVal view As ICalendarsView, ByVal model As
ICalendarEngine)
If IsNothing(view) Or IsNothing(model) Then
Throw New ArgumentNullException("Passed parameters were
not instantiated")
End If
_view = view
_model = model
'Add the event handlers
AddHandler _view.CreateNewCalendar, AddressOf
OnCreateNewCalendar
End Sub
Private Sub OnCreateNewCalendar(ByVal sender As Object, ByVal e As
EventArgs)
Dim c As Calendar = _model.GetCalendar(CType(sender,
ICalendarsView).CalendarName)
End Sub
The test
Imports System.Text
Imports ArdoughterSoftware.FantasyCalendar
Imports Rhino.Mocks
Imports Rhino.Mocks.Interfaces
<TestClass()>
Public Class TestCalendarsController
Private testContextInstance As TestContext
'''<summary>
'''Gets or sets the test context which provides
'''information about and functionality for the current test run.
'''</summary>
Public Property TestContext() As TestContext
Get
Return testContextInstance
End Get
Set(ByVal value As TestContext)
testContextInstance = value
End Set
End Property
Private moMockery As MockRepository
' Use TestInitialize to run code before running each test
<TestInitialize()> Public Sub MyTestInitialize()
moMockery = New MockRepository
End Sub
'
' Use TestCleanup to run code after each test has run
<TestCleanup()> Public Sub MyTestCleanup()
moMockery.VerifyAll()
End Sub
Public Sub TestCreateNewCalendarEventIsRaisedTheOldWay()
Dim e As New EventArgs
Dim c As New Calendar
Dim view As ICalendarsView
view = moMockery.Stub(Of ICalendarsView)()
Dim model As ICalendarEngine
model = moMockery.StrictMock(Of ICalendarEngine)()
Dim calendarName As String = "Dale Reckoning"
view.CalendarName = calendarName
AddHandler view.CreateNewCalendar, Nothing
LastCall.Constraints(Constraints.Is.NotNull)
Dim CreateNewCalendarEventRaiser As IEventRaiser =
LastCall.GetEventRaiser()
Rhino.Mocks.Expect.Call(model.CreateNewCalendar(view.CalendarName)).Repeat.AtLeastOnce.Return(c)
moMockery.ReplayAll()
Dim controller = New CalendarsController(view, model)
CreateNewCalendarEventRaiser.Raise(CType(view, Object), e)
End Sub
End Class
The Error message
Test method
TestCalendars.TestCalendarsController.TestCreateNewCalendarEventIsRaisedTheOldWay
threw exception:
Rhino.Mocks.Exceptions.ExpectationViolationException:
ICalendarEngine.GetCalendar("Dale Reckoning"); Expected #0, Actual #1.
TestCleanup method TestCalendars.TestCalendarsController.MyTestCleanup
threw exception. Rhino.Mocks.Exceptions.ExpectationViolationException:
Rhino.Mocks.Exceptions.ExpectationViolationException:
ICalendarEngine.GetCalendar("Dale Reckoning"); Expected #0, Actual
#1..
Now Googling that message, would indicate that the method and the
event raise are not getting the parameters they expect and that they
are expecting a particular instance of an object. Which I do not
understand as they are getting the same instance of the object. I have
tried placing IgnoreArguments qualifiers on the expected calls and the
GetEventRiser method but it does not appear to make any difference.
What am I not getting? I am sure it is one of those things that is
obvious once you know it,
Also if I do get this code working how would i put it in AAA syntax?
Thanks
Joe
--
You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group.
To post to this group, send email to rhino...@googlegroups.com.
To unsubscribe from this group, send email to rhinomocks+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en.
> > Rhino.Mocks.Expect.Call(model.CreateNewCalendar(view.CalendarName)).Repeat.AtLeastOnce.Return(c)
Should create the expectation and I know the event is raised because I
can see the call in the event in the debugger.
The problem arises when the cal is made to the model.GetCalendar
method. There the expectation exception gets raised.
I have akso tried adding IgnoreArguments to no avial.
I am sure I am missing something but I do not know what.
On Apr 13, 8:39 pm, Tim Barcz <timba...@gmail.com> wrote:
> It appears you are using strict mocks...which means any call not "expected"
> will cause the test to fail.
>
> > rhinomocks+...@googlegroups.com<rhinomocks%2Bunsu...@googlegroups.com>
Whe you use a StrictMock, you have to set an expectation for EVERY
call made on that object. So it is completely expeted that a call to
model.GetCalendar will throw an expectation excepton, since you have
not set up such an expectation.
On Apr 14, 11:07 am, Joseph Dineen <joseph.din...@gmail.com> wrote:
> Well I have tried it using DynamicMock instead of StrictMock and it
> made no difference.
> Besides, the line
>
> > > Rhino.Mocks.Expect.Call(model.CreateNewCalendar(view.CalendarName)).Repeat.AtLeastOnce.Return(c)
> > > Rhino.Mocks.Expect.Call(model.CreateNewCalendar(view.CalendarName)).Repeat.AtLeastOnce.Return(c)
>
> > > moMockery.ReplayAll()
>
> > > Dim controller = New CalendarsController(view, model)
>
> > > CreateNewCalendarEventRaiser.Raise(CType(view, Object), e)
> > > End Sub
>
> > > End Class
>
> > > The Error message
>
> > > Test method
>
> > > TestCalendars.TestCalendarsController.TestCreateNewCalendarEventIsRaisedTheOldWay
> > > threw exception:
> > > Rhino.Mocks.Exceptions.ExpectationViolationException:
> > > ICalendarEngine.GetCalendar("Dale Reckoning"); Expected #0, Actual #1.
> > > TestCleanup method TestCalendars.TestCalendarsController.MyTestCleanup
> > > threw exception. Rhino.Mocks.Exceptions.ExpectationViolationException:
> > > Rhino.Mocks.Exceptions.ExpectationViolationException:
> > > ICalendarEngine.GetCalendar("Dale Reckoning"); Expected #0, Actual
> > > #1..
>
> > > Now Googling that message, would indicate that the method and the
> > > event raise are not getting the parameters they expect and that they
> > > are expecting a particular instance of an object. Which I do not
> > > understand as they are getting the same instance of the object. I have
> > > tried placing IgnoreArguments qualifiers on the expected calls and the
> > > GetEventRiser method but it does not appear to make any difference.
>
> > > What am I not getting? I am sure it is one of those things that is
> > > obvious once you know it,
>
> > > Also if I do get this code working how would i put it in AAA syntax?
>
> > > Thanks
> > > Joe
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "Rhino.Mocks" group.
> > > To post to this group, send email to rhino...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > rhinomocks+...@googlegroups.com<rhinomocks%2Bunsubscribe@googlegroups.com>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/rhinomocks?hl=en.
>
> > --
> > Tim Barcz
> > Microsoft C# MVP
> > Microsoft ASPInsiderhttp://timbarcz.devlicio.ushttp://www.twitter.com/timbarcz- Hide quoted text -
>
> - Show quoted text -
Rhino.Mocks.Expect.Call(model.CreateNewCalendar(view.CalendarName)).Repeat.AtLeastOnce.Return(c)
Sets up such an expectation?
If it does not then how does one set up the expectation?
On Apr 14, 11:49 am, bill richards <bill.richa...@greyskin.co.uk>
wrote:
> > > Microsoft ASPInsiderhttp://timbarcz.devlicio.ushttp://www.twitter.com/timbarcz-Hide quoted text -
I expect the member CreateNewCalendar to be called on model using the
value view.CalendarName as a parameter.
I expect it to be called at least once and it will return c.
Nowhere have you stated that you expect model.GetCalendar to be
called.
On Apr 14, 12:08 pm, Joseph Dineen <joseph.din...@gmail.com> wrote:
> But I thought that the Line in my test
>
> Rhino.Mocks.Expect.Call(model.CreateNewCalendar(view.CalendarName)).Repeat.AtLeastOnce.Return(c)
> > > > Microsoft ASPInsiderhttp://timbarcz.devlicio.ushttp://www.twitter.com/timbarcz-Hidequoted text -
>
> > > - Show quoted text -- Hide quoted text -
this is the reasn for my reluctance to use StrictMock : the use of a
StrictMock implies your internal knowledge of the item being mocked,
you need to know what the internal implications are for making a call.
To me, this is at far too granular a level.
On Apr 14, 12:42 pm, bill richards <bill.richa...@greyskin.co.uk>
wrote:
> ...
>
> read more »- Hide quoted text -
So can anyone point me at a good resource to recast it in the newer
AAA syntax?
On Apr 14, 12:45 pm, bill richards <bill.richa...@greyskin.co.uk>
> ...
>
> read more »
--
You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group.
To post to this group, send email to rhino...@googlegroups.com.
To unsubscribe from this group, send email to rhinomocks+...@googlegroups.com.
Anyhoo thanks to everyone for the help and if I make no progress I
guess I'll be back.
On Apr 14, 1:10 pm, David Tchepak <tche...@gmail.com> wrote:
> Not sure if it helps for this particular case, but I wrote an intro to AAA
> with Rhino Mocks a while back, although you'll have to translate it from C#:
>
> http://www.davesquared.net/2008/10/very-basics-of-aaa-with-rhino-mock...
>
> <http://www.davesquared.net/2008/10/very-basics-of-aaa-with-rhino-mock...>Oh,
> you asked for a "good" resource. Never mind. ;)
>
> ...
>
> read more »
> ...
>
> read more »