Ayende @ Rahien
Technology, life, .Net and all the rest...

Projects News

Rhino Mocks 3.5 RTM

Today I decided that I had enough time to get bugs for the 3.5 RC, so I fixed all the remaining bugs, updated the Rhino Mocks 3.5 Documentation, and put the binaries out the site.

For this release, I actually have 4 binary packages. One for .NET 3.5 and one for .NET 2.0, but I have an additional criteria, with the castle assemblies merged (default) and with the castle assemblies included). The reason for having those two options is that people who want to extend Rhino Mocks directly can do it more easily. In general, I suggest using the merged version.

So, what do we actually have here (feature differences from 3.4)?

Features:

  •  Assert Act Arrange syntax for mocking
    • Including support for .NET 2.0
  • Added a way to access the mocked method at runtime, using WhenCalled (similar to Do(), but without the pain of having to specify a special delegate).
  • CreateMock() is deprecated and marked with the [Obsolete] attribute. Use StrictMock() instead.
  • Inline constraints.
  • Support for mocking interface in C++ that mix native and managed types. (Note, may require that you install kb957541 to get around  bug introduced to the framework on SP1).
  • New event raising syntax:
    eventHolder.Raise(stub => stub.Blah += null, this, EventArgs.Empty);
  • Better support for multi threaded replays.
    • Note that access to the mock object is now serialized.
  • Support AssertWasCalled on parial mocks.

Patches:

  • From Sebastian Jancke, adding support for SetPropertyAndIgnoreArguments() and SetPropertyWithArguments( o );
  • From Yann Trevin, adding support for List.Element("MyKey", ...), so we are not limited to just integers.
  • From David Tchepak, adding support for ctor arguments when creating a mock using static method.

Improvements:

  • Better handling of exception in raising events from mock objects
  • Better error message when trying to set expectation on properties of a stub.
  • Better error handling for AAA syntax abuse
  • Will give better errors if you call Verify on a mock that is in record mode.
  • Allowing to return to record mode without losing expectations.
  • BackToRecord extension method.
  • AAA syntax now works with Ordering
  • Better error message if trying to use SetupResult on stubbed mock properties.
  • Better error message when trying to mock null instance.

Bug fixes:

  • Fixing an issue with mock objects that expose methods with output parameter of type System.IntPtr.
  • Fixed an issue with merging, would cause issues if you are also using Castle Dynamic Proxy.
  • Fixed various typos
  • Fixed issue with mocking internal classes and interfaces.
  • OutRef params was not copied when creating new expectation from an existing one.
  • Fixing an issue with leaking expectationReplaced in mocks.
04/10/2008 22:49:12 Ayende Rahien Rhino Mocks

Rhino Queues

One of the things that often come up in the NServiceBus mailing list is the request for an xcopy, zero administration, queuing service. This is especially the case when you have smart clients or want to have queues over the Internet.

I decided to try to build such a thing, because it didn't seem such a hard problem. I turned out to be wrong, but it was an interesting experiment. Actually, the problem isn't that it is hard to do this, the problem was that I wanted durable queuing, and that led me to a lot of technologies that weren't suitable for my needs.

You can get the bits here: https://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools/branches/rhino-queues-1.0

What it is:

  • XCopyable, Zero Administration, Embedded, Async queuing service
  • Robust in the face of networking outages
  • System.Transactions support
  • Fast
  • Works over HTTP

What it isn't:

  • Durable queuing service
  • Wetted by production use

Broadly, using Rhino Queues you get async queues over HTTP. But, it keeps all the data in memory, so if you restart the application, it will lose all waiting messages. It also tries its best (but does not guarantee) to ensure message ordering and ensure delivery.

Let us take a look at the code, and then discuss the implementation details from there.

Server usage:

using(var factory = new Configuration("server")
	.Map("server").To("http://localhost:9999/server/")
	.Map("client").To("http://localhost:9999/client/")
	.RegisterQueue("echo")
	.BuildQueueFactory())
{

factory.Start();
using (var queue = factory.OpenQueue("echo")) { var message = queue.Recieve(); var str = (string)message.Value; var rev = new string(str.Reverse().ToArray()); using(var remoteQueue = factory.OpenQueue(message.Source)) { Console.WriteLine("Handled message"); remoteQueue.Send(rev); } } }

And the client usage:

using(var factory = new Configuration("client")
	.Map("server").To("http://localhost:9999/server/")
	.Map("client").To("http://localhost:9999/client/")
	.RegisterQueue("echo-reply")
	.BuildQueueFactory())
{

	factory.Start();

	using (var tx = new TransactionScope())
	using (var serverQueue = factory.OpenQueue("echo@server"))
	{
		Console.WriteLine("Sending 'hello there'");
		serverQueue.Send("Hello there").Source = new Destination("echo-reply@client");
		tx.Complete();
	}
	
	using (var clientQueue = factory.OpenQueue("echo-reply"))
	{
		var msgText = clientQueue.Recieve();
		Console.WriteLine(msgText.Value);
	}
}

As you can see, we map a nice name to an endpoint, so we can send message to [queue]@[endpoint nice name], sending a message to just [queue] send it to the local machine. It is expected that the nice name for an endpoint would be the machine name, which alleviate the need of syncing names across all endpoints.

You can also see the usage of System.Transaction and without System.Transactions.

One thing that would probably raise questions is why Rhino Queues doesn't have a durable mode, after all, I just spent some time building a durable queue infrastructure. The reason for that is very simple, I spent too much time on that, and I can't spend more time on this at the moment. So I am putting both Rhino Queues and Rhino Queues Storage Disk out there, and I'll let the community bring them together.

A word of warning, Rhino Queues is a cool project, but it is not a replacement for such things as MSMQ. If you can, you probably want to make use of MSMQ, specifically because there is a lot more production time using it.

01/08/2008 19:22:30 Ayende Rahien Rhino Commons

You leave a team alone for one week...

And they go ahead and write Outlook Web Access behind your back...

image

I am going over the code, and I am simply amazed. JavaScript & HTML component, using DomainJSon Generation and some additional smarts around that idea.

03/12/2007 11:54:14 Ayende Rahien Brail

NHibernate Query Analyzer And DuplicateMappingException

One of the most common issues that people have run into with using NHQA is the DuplicateMappingException. The root problem is that you are adding both the DLL (which contained embedded resources mapping files) and the mapping files themselves.

Well, after getting tried of answering that question so often, I decided to fix the issue, and let NHQA knows about the issue, and try to resolve it. The fix is in the repository now, but I would like to have some more input before I would release it.

18/08/2007 12:33:42 Ayende Rahien NHibernate Query Analyzer