How to Mock RoutedEventArgs.OrginalSource

58 views
Skip to first unread message

Vamsi Nudurupati

unread,
Sep 16, 2014, 11:45:36 AM9/16/14
to rhino...@googlegroups.com
Hi,

I am trying to Mock the OriginalSource in the RoutedEventArgs using Rhino Mocks. Can any one please suggest on how to make this test pass as the OriginalSource is null so the test fails as its not able to Convert the EventArgs to ViewModel?

[Test]
        public void Covert_ShouldReturnViewModel_WhenArgsIsPassed()
        {
            
            var routedEventArgs = MockRepository.GenerateStub<RoutedEventArgs>();
   var mockOriginalSource = routedEventArgs.Expect(eArgs => eArgs.OriginalSource).Return("test mock");

            var ViewModel = MockRepository.GenerateStub<ViewModel>();
            
            var eventArgsConverterHelper = MockRepository.GenerateMock<EventArgsConverterHelper>();
            eventArgsConverterHelper.Stub(
                eArgs => eArgs.GetCallReasonViewModelMethod(mockOriginalSource))
                .Return(callReasonViewModel)
                .Repeat.Once();

            var dTEventArgs = new EventArgsConverter();

            Assert.That(dTEventArgs.Convert(routedEventArgs), Is.EqualTo(ViewModel));
        }

thanks,
Vamsi

Patrick Steele

unread,
Sep 17, 2014, 9:56:02 AM9/17/14
to rhino...@googlegroups.com
Unfortunately, OriginalSource is not virtual so you can't mock it with Rhino.Mocks.

--
You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rhinomocks+...@googlegroups.com.
To post to this group, send email to rhino...@googlegroups.com.
Visit this group at http://groups.google.com/group/rhinomocks.
For more options, visit https://groups.google.com/d/optout.

haifisch

unread,
Sep 18, 2014, 2:03:47 AM9/18/14
to rhino...@googlegroups.com
Hi,

I think for your test it wouldn't make sense to use a mocked RoutedEventArgs object at all - why couldn't you just use a real RoutedEventArgs object?

Br,

Andreas
Reply all
Reply to author
Forward
0 new messages