OK, so nobody had any thing usefull to add to my original post below;
I have been playing away with this when i have had the time and while
I have made some progress I am not sure that I am getting the AAA
syntax.
Same code as the original post but I have concentrated on the Save
event since that originally called a sub. Here I ran in to a wall.
While VB.net 2010 lambda expression can generate Subs they obviously
do not behave like C# void methods as far as Rhino Mocks is concerned.
So I replaced my subs with functions that return true if successful.
Not totally happy with that but it is Rhino Mocks that is my object of
study not VB design.
So I redid the tests with that in mind for the save event. One the old
way and the other the AAA way.
So
<TestMethod()> Public Sub TestViewEventSaveIsHandled()
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.DynamicMock(Of ICalendarEngine)()
Dim calendarName As String = "Dale Reckoning"
view.CalendarName = calendarName
AddHandler view.Save, Nothing
LastCall.Constraints(Constraints.Is.NotNull)
Dim saveCalendarEventRaiser As IEventRaiser =
LastCall.GetEventRaiser()
Rhino.Mocks.Expect.Call(model.SaveCalendar(c)).IgnoreArguments.Return(True)
moMockery.ReplayAll()
Dim controller = New CalendarsController(view, model)
'
saveCalendarEventRaiser.Raise(CType(view, Object), e)
End Sub
Works as expected but
Public Sub TestEventSaveIsHandledAAAWay()
Dim view As ICalendarsView
Dim model As ICalendarEngine
view = MockRepository.GenerateStub(Of ICalendarsView)()
model = MockRepository.GenerateMock(Of ICalendarEngine)()
Dim c As New Calendar
model.Stub(Function(e)
e.SaveCalendar(c)).IgnoreArguments().Return(True)
Dim controller As New CalendarsController(view, model)
view.GetEventRaiser(Sub(x) AddHandler x.Save,
Nothing).Raise(view, New EventArgs)
model.AssertWasCalled(Function(e) e.SaveCalendar(c))
End Sub
does not, instead I get the error
Test method
TestCalendars.TestCalendarsController.TestEventSaveIsHandledAAAWay
threw exception:
Rhino.Mocks.Exceptions.ExpectationViolationException:
ICalendarEngine.SaveCalendar(ArdoughterSoftware.FantasyCalendar.Calendar);
Expected #1, Actual #0.
Now, the code works as far as I am concerned and the tests work if I
do it the record/replay way but the AAA way is beating me in this
case. What am I doing wrong? or should I just give up on Rhino Mocks
with vb?
On Apr 24, 6:46 pm, Joseph Dineen <[email protected]> wrote:
> Hi,
> Back again, still tinkering with Rhino and VB.NET 2010. I am having
> some progress but I have hit another impasse and I hope I am not being
> blind or stupid again, but.
> I am testing this class:
>
> Public Class CalendarsController
>
> Private _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
> .....
> AddHandler _view.Save, AddressOf OnSaveCalendar
> End Sub
>
> Private Sub OnCreateNewCalendar(ByVal sender As Object, ByVal e As
> EventArgs)
> Dim c As Calendar = _model.CreateNewCalendar(CType(sender,
> ICalendarsView).CalendarName)
> End Sub
> ......
> Private Sub OnSaveCalendar(ByVal sender As Object, ByVal e As
> EventArgs)
> Dim v As ICalendarsView = CType(sender, ICalendarsView)
> Dim c As New Calendar(v.CalendarName, v.WeekDayNames,
> v.MonthNames, v.MonthLengths, v.StartDayNameForYear)
> _model.SaveCalendar(c)
>
> End Sub
>
> End Class
>
> I have a test:
>
> <TestMethod()> Public Sub TestCreateNewCalendarFromView()
> Dim view As ICalendarsView
> view = MockRepository.GenerateStub(Of ICalendarsView)()
> Dim model As ICalendarEngine
> model = MockRepository.GenerateMock(Of ICalendarEngine)()
> Dim c As New Calendar
> view.CalendarName = "Dale Reckoning"
> model.Stub(Function(e)
> e.CreateNewCalendar(view.CalendarName)).IgnoreArguments.Return(c)
> Dim controller As New CalendarsController(view, model)
>
> view.GetEventRaiser(Sub(x) AddHandler x.CreateNewCalendar,
> Nothing).Raise(view, New EventArgs)
> model.AssertWasCalled(Function(e)
> e.CreateNewCalendar(view.CalendarName))
>
> End Sub
>
> It works pretty much as expected.
>
> Now this test;
>
> <TestMethod()>
> Public Sub TestEventSaveIsHandledAAAWay()
> Dim view As ICalendarsView
> Dim model As ICalendarEngine
> view = MockRepository.GenerateStub(Of ICalendarsView)()
> model = MockRepository.GenerateMock(Of ICalendarEngine)()
>
> model.Stub(Sub(e) e.SaveCalendar(Nothing)).IgnoreArguments()
> Dim controller As New CalendarsController(view, model)
> view.GetEventRaiser(Sub(x) AddHandler x.Save,
> Nothing).Raise(view, New EventArgs)
> model.AssertWasCalled(Sub(e) e.SaveCalendar(New Calendar))
>
> End Sub
> Does not work. It fails and tells that that it expected #1 and actual
> of #0
> Now, the only difference I can see is that in the latter test I am
> setting the expectation call on a Sub and in hte other I am setting it
> on a Function.
>
> I am in the process of downloading the final release of VS2010 so I
> have only been working on the release canditate so far.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Rhino.Mocks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group
> athttp://groups.google.com/group/rhinomocks?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Rhino.Mocks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rhinomocks?hl=en.