Dennis van der Stelt

If you have one problem and use cache to solve it, you now have two problems.

Community

Email Notifications

News

  • Addicted to Refactor! Pro

I read...

I Use...

Tags

Recent Posts

Archives

Blog Subscription Form

  • Email Notifications
    Go

February 2009 - Posts

Cloud service in Azure : Speedtraps

For the 828 event next Thursday I’m developing some examples. One of them is where I get all speed traps (Flitsers in Dutch) from http://www… a source that I won’t mention here. I then want to expose these via WCF via SOAP and REST. Of course this will be so extremely popular, that I have to use Windows Azure and be able to scale immensely so you folks won’t miss out on the latest speed traps.

Anyway, after first writing “w00t” in the cloud, I now got my first WCF service in the cloud which actually does something.

You can find the REST version here:

http://flitsservice.cloudapp.net/speedtraps.svc/Flitsers
http://flitsservice.cloudapp.net/speedtraps.svc/Status

And the root location, including MEX and WSDL stuff right here:
http://flitsservice.cloudapp.net/speedtraps.svc

Unfortunately you won’t be able to add a reference (proxy class) because of some internal stuff going wrong inside Azure. But maybe I’ll supply you in the future with that as well, and even a client application. Maybe I’ll create an syndicated version of it, but for now you can read the REST version and use it in your own apps. I have no idea how long this will run though.

Faking extension methods

I just read a post from Daniel Cazzulino about mocking extension methods. He wants to mock an extension method so that it behaves as he defines in his test, instead of actually calling the real method.

To do this, Daniel creates an interface where every method signature is copied to, modifies the original static class so it’s not static anymore and holds a reference to the object that the extension method was for in the first place. It’s a really cool article, but as Daniel says himself “This is more work, I know, but now you can…”

I break him off there. You know what I have to write to mock my extension methods? Here’s the code:

//
//
//

How do I do this? Easy, I’m using Typemock Isolator. Imagine I’ve got the following extension method:

public static class MessagingExtensions
{
    public static SendResult SendTo(this SomeType target, string address)
    {
        // Do something
        throw new NotImplementedException("Don't do anything!!!");
    }
}

The extension method is for the type SomeType, which doesn’t have any members. It’s just here for show. I’ve explicitly added the exception so we’ll be sure this method will never get executed. I’ve also got a Worker class that I want to test.

public class Worker
{
    public SendResult Execute()
    {
        SomeType st = new SomeType();
        return st.SendTo("dvdstelt@gmail.com");
    }
}

I want to test if everything goes well with this method. It doesn’t do anything exciting, so there aren’t a lot of options, but this method isn’t what this article is about. What we want to see is that the extension method SendTo is never actually called. So how about it? Here’s my test:

[TestMethod, Isolated]
public void ExecuteSucceeds()
{
    // Arrange
    Isolate.Fake.StaticMethods(typeof(MessagingExtensions));
    Isolate.WhenCalled(() => MessagingExtensions.SendTo(null, "")).WillReturn(SendResult.Sent);

    // Act
    Worker worker = new Worker();
    SendResult result = worker.Execute();

    // Assert
    Assert.AreEqual<SendResult>(SendResult.Sent, result);
    Isolate.Verify.WasCalledWithAnyArguments(() => MessagingExtensions.SendTo(null, ""));
}

Line 5 makes sure that all static methods to MessagingExtensions are never actually called, and for our demo this isn’t even necessary.
Line 6 makes sure that when SendTo is called, it will return the right result.

Line 13 is actually a bogus verification, because I’m really testing here if Isolator is returning the right result. But to be sure, we’ll keep it in. Line 14 verifies if the extension method was called, as we expected to.

So to conclude, I did not write one line of code extra to mock away the extension method. This is thanks to Typemock Isolator, the tool you just have to have when you’re doing unit testing.

Update february 23, 2009
Eli Lopian commented that you can also call the extenson method on the extended type directly, as shown in the code below.

// Arrange
var dummy = new SomeType();
Isolate.WhenCalled(() => dummy.SendTo("")).WillReturn(SendResult.Sent);

// Assert
Isolate.Verify.WasCalledWithAnyArguments(() => dummy.SendTo(""));

Update februari 23, 2009
You can find a VS2008 solution here, so you can see what’s actually happening.

Broken Azure

azure_failed

Whoops, did I break something?

Update : Things got worse!

azure_kapot

*chirp

Update : The application was renamed to blu. The previous name was much cooler, but they probably have their reasons! :-)
Find it here.

Although Twitter hasn’t taken any forms of hysteria yet in The Netherlands, more and more people start using it. I started learning its advantages during MIX’07 where people would notify the world that they’d go down to a restaurant to have dinner, inviting others to join them. You can probably guess what the talks were about.

So I started using Twitter, but not really often. The thing is, in the USA you can get updates over SMS, but unfortunately this was turned off a few months ago for Europe. So now you need a cool client on your desktop, laptop, mobile and everywhere to effectively use Twitter. I use Tiny Twitter on my mobile and it’s kind of okay. There’s Witty (using WPF) for your desktop, but I haven’t been using it.

chirp Since a few days however, a new desktop client called *chirp was released. It’s using Windows Presentation Foundation for its user interface and it’s looking awesome. As its maker, thirteen23 says, “There have been a lot of attempts at a great Twitter desktop client, but most have have resulted in glorified readers— not a great experience.” And *chirp delivers on the experience.

Some highlights

  • The user interface is awesome. From start to using it to finishing, it delivers!
    • When starting it’s showing a great animation and all messages fly into the application.
    • When refreshing, in the border of the application a light starts scrolling. When refresh is finished, the border flashes.
    • When you want to tweet (update) a balloon start popping up with a great animation. While typing, in the background the number of open characters is displayed and counting down.
    • When a message is a reply to some other message, an arrow is displayed. Clicking the arrow rotates the current message, grays out everything else and displays the messages that was replied on.
    • Scrolling down to read older messages means scrolling endlessly. Messages are loaded from Twitter when needed, so it’s not a x-MB file on messages loading in when *chirp is started.
    • Reply on other messages by clicking the reply button on them.
    • Favorite users get notifications when they added a new message

There are some features missing, like being able to view replies from people you’re not following, TinyUrl (and others) inclusion, ability to see replies to more than one reply deep and minimize into system-tray. But I’m sure they’re coming, as this is just the first drop and thirteen23 have promised to update to tool. They also promised an update a few days ago and it’s still not here, but we’re patient…