Google Groups Home
Help | Sign in
TypeMock vs. Rhino.Mocks fluent interface
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Stefan Lieser  
View profile
 More options Feb 16, 8:59 am
From: Stefan Lieser <ste...@lieser-online.de>
Date: Sat, 16 Feb 2008 14:59:08 +0100
Local: Sat, Feb 16 2008 8:59 am
Subject: TypeMock vs. Rhino.Mocks fluent interface
I started to play with TypeMock and did not find a fluent interface of
the form Rhino.Mocks has it. First it was only a bit of uncomfortable
feeling, later I recognized the missing type safety:

// TypeMock
mock.ExpectAndReturn(customer.Orders, new Order[] { order });

// Rhino.Mocks
Expect.Call(customer.Orders).Return(new Order[] { order });

TypeMock's ExpectAndReturn doesn't use generics, so the return value
(2nd parameter) is of type object. Rhino uses generics, so ReSharper
(and of course the compiler) can infer the type for the "Return" parameter.

Besides feeling a bit uncomfortable with TypeMock's syntax I think it
has a major disadvantage: missing type safety. If I change the type of a
property the Rhino tests break at compile time while the TypeMock test
break at runtime. So my feedback loop is getting longer and thats what
TDD is *not* about.

Did I miss something?

Regards,
Stefan Lieser
--
http://www.lieser-online.de


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roy Osherove  
View profile
 More options Feb 16, 10:28 am
From: "Roy Osherove" <r...@osherove.com>
Date: Sat, 16 Feb 2008 17:28:47 +0200
Local: Sat, Feb 16 2008 10:28 am
Subject: Re: [altnetuk-discuss] TypeMock vs. Rhino.Mocks fluent interface

Of course it supports it, using Narutal mocks, or the generic version of
Mock and MockObject<T>
You should use TypeMocks NaturalMocks for typesafe and mocking a chain of
calls for example

using (RecordExpectation r = new RecordExpectation ())

{

  Factory.GetCustomer().Orders();

   r.Return(fakeOrders);

}

On Feb 16, 2008 3:59 PM, Stefan Lieser <ste...@lieser-online.de> wrote:

--
Thanks,

Roy Osherove
www.TypeMock.com - Simplify Unit Testing

Author of "The Art Of Unit Testing" ( http://ArtOfUnitTesting.com )
www.ISerializable.com (blog)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stefan Lieser  
View profile
 More options Feb 16, 1:47 pm
From: Stefan Lieser <ste...@lieser-online.de>
Date: Sat, 16 Feb 2008 19:47:50 +0100
Local: Sat, Feb 16 2008 1:47 pm
Subject: Re: [altnetuk-discuss] Re: TypeMock vs. Rhino.Mocks fluent interface
Roy, I think its time to discuss it on a complete example (see below). I
don't see how to make the call to r.Return(...) compiletime (!)
typesafe. If I change the type of Order.Id from string to int, the test
will compile but break at runtime. With Rhino it breaks at compile time.

Besides the compiletime typesafety I prefer to write the expectations
more fluent like r.CallTo(order.Id).Returns("42), but thats another story.

Please show me how to get this compiletime typesafe.

Regards,
Stefan Lieser

using Microsoft.VisualStudio.TestTools.UnitTesting;
using TypeMock;

namespace TestProject1
{
   public class Order
   {
     public string Id { get; set; }
   }

   [TestClass]
   public class TypeSafeMocking
   {
     [TestMethod]
     public void OrderId() {
       Order order = new Order();

       using (RecordExpectations r = RecorderManager.StartRecording()) {
         var id = order.Id;
         r.Return("42");
       }

       Assert.AreSame("42", order.Id);
     }
   }

}

Roy Osherove schrieb:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roy Osherove  
View profile
 More options Feb 16, 5:28 pm
From: "Roy Osherove" <r...@osherove.com>
Date: Sun, 17 Feb 2008 00:28:24 +0200
Local: Sat, Feb 16 2008 5:28 pm
Subject: Re: [altnetuk-discuss] Re: TypeMock vs. Rhino.Mocks fluent interface

yep. you're right. that's one area where Typemock is not totally typesafe.
perhaps when we drop support for .net 1.1 we can make it so.

On Feb 16, 2008 8:47 PM, Stefan Lieser <ste...@lieser-online.de> wrote:

--
Thanks,

Roy Osherove
www.TypeMock.com - Simplify Unit Testing

Author of "The Art Of Unit Testing" ( http://ArtOfUnitTesting.com )
www.ISerializable.com (blog)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roy Osherove  
View profile
 More options Feb 17, 3:19 am
From: "Roy Osherove" <r...@osherove.com>
Date: Sun, 17 Feb 2008 10:19:31 +0200
Local: Sun, Feb 17 2008 3:19 am
Subject: Re: [altnetuk-discuss] Re: TypeMock vs. Rhino.Mocks fluent interface

BTW - how would you do it with Rhinomocks?

On Feb 17, 2008 12:28 AM, Roy Osherove <r...@osherove.com> wrote:

--
Thanks,

Roy Osherove
www.TypeMock.com - Simplify Unit Testing

Author of "The Art Of Unit Testing" ( http://ArtOfUnitTesting.com )
www.ISerializable.com (blog)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ayende Rahien  
View profile
 More options Feb 17, 3:31 am
From: "Ayende Rahien" <aye...@ayende.com>
Date: Sun, 17 Feb 2008 10:31:53 +0200
Local: Sun, Feb 17 2008 3:31 am
Subject: Re: [altnetuk-discuss] Re: TypeMock vs. Rhino.Mocks fluent interface

I am not following

On 2/17/08, Roy Osherove <r...@osherove.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stefan Lieser  
View profile
 More options Feb 17, 4:42 am
From: Stefan Lieser <ste...@lieser-online.de>
Date: Sun, 17 Feb 2008 10:42:14 +0100
Local: Sun, Feb 17 2008 4:42 am
Subject: Re: [altnetuk-discuss] Re: TypeMock vs. Rhino.Mocks fluent interface
Roy Osherove schrieb:
 > BTW - how would you do it with Rhinomocks?

With Rhino.Mocks I would do it this way:

[TestMethod]
public void OrderId_Rhino() {
     MockRepository mocks = new MockRepository();
     Order order = mocks.DynamicMock<Order>();

     using (mocks.Record()) {
         Expect.Call(order.Id).Return("42");
     }

     Assert.AreSame("42", order.Id);

}

If I change the type of property Order.Id from string to int without
changing Return("42") to Return(42) the compiler will blame me.

Regards,
Stefan


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Roy Osherove  
View profile
 More options Feb 17, 4:47 am
From: "Roy Osherove" <r...@osherove.com>
Date: Sun, 17 Feb 2008 11:47:13 +0200
Local: Sun, Feb 17 2008 4:47 am
Subject: Re: [altnetuk-discuss] Re: TypeMock vs. Rhino.Mocks fluent interface

  using (RecordExpectations r = RecorderManager.StartRecording()) {
        var id = order.Id;
        r.Return("42");
      }

On Feb 17, 2008 10:31 AM, Ayende Rahien <aye...@ayende.com> wrote:

--
Thanks,

Roy Osherove
www.TypeMock.com - Simplify Unit Testing

Author of "The Art Of Unit Testing" ( http://ArtOfUnitTesting.com )
www.ISerializable.com (blog)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google