Paulo Morgado

.NET Development & Architecture
PDC2008: Are Windows Forms Dead?

This year’s PDC is all about the cloud (or cloudy as I call it) and the .NET Framework 4.0.

No one at Microsoft has ever told me that Windows Forms are dead (quite the opposite) but looking at the list of sessions for this year’s PDC I can only see WPF.

So the question remains: Are Windows Forms dead?

Steve Ballmer In Portugal

Last Friday, October 3rd, Steve Ballmer (you know who he is – Microsoft’s CEO) was in Portugal.

He was at a local Microsoft event, but I couldn’t attend because I was in Madrid in an MVP OpenDay (one could say that Steve paid for it, in part :)). I think Portuguese MVPs where well represented by Jota.

You can watch his interview to a Portuguese news channel here.

Typemock Isolator 5.1 Released

This major version adds static method support and non-public method faking to the AAA API. Check out the release notes.

I don’t like the reflective approach to testing private methods.

With the new additions to the AAA API, testing this class:

public class MyClass
{
    public string Public()
    {
        return this.Private();
    }

    private string Private()
    {
        throw new NotImplementedException();
    }
}

can be done like this:

[TestMethod]
[Isolated]
public void PrivateTest()
{
    MyClass fake = Isolate.Fake.Instance<MyClass>();

    Isolate.WhenCalled(() => fake.Public()).CallOriginal();

    Isolate.NonPublic.WhenCalled(fake, "Private").WillReturn("FAKE");

    string fakePublic = fake.Public();

    Assert.AreEqual("FAKE", fakePublic);

    Isolate.Verify.WasCalledWithExactArguments(() => fake.Public());

    Isolate.Verify.NonPublic.WasCalled(fake, "Private");
}

I would like it better if it was like this:

[TestMethod]
[Isolated]
public void PrivateTest()
{
    MyClass fake = Isolate.Fake.Instance<MyClass>();

    MyClass_Accessor fakeAccessor = MyClass_Accessor.AttachShadow(fake);

    Isolate.WhenCalled(() => fakeAccessor.Private()).WillReturn("FAKE");

    Isolate.WhenCalled(() => fake.Public()).CallOriginal();

    string fakePublic = fake.Public();

    Assert.AreEqual("FAKE", fakePublic);

    Isolate.Verify.WasCalledWithExactArguments(() => fake.Public());

    Isolate.Verify.WasCalledWithExactArguments(() => fakeAccessor.Private());
}

Looks almost the same but there aren’t any method names in the test code.

They were able to do it for Natural Mocks. I’m sure they will eventually do it for AAA.

Faking Output Parameters With Typemock Isolator

Some time ago I was asked if it was possible to fake output parameters with Typemock Isolator.

It’s actually very easy using any of the APIs.

Given this class:

public class MyClass
{
    public bool MyMethod(string input, out int output1, out double output2)
    {
        throw new NotImplementedException();
    }
}

Using the new AAA API, it's as clean as:

[TestMethod]
[Isolated]
public void TestMethodIsolated()
{
    MyClass target = Isolate.Fake.Instance<MyClass>();

    string input = "test value";
    int expectedOutput1 = 1;
    double expectedOutput2 = 2;

    Isolate.WhenCalled(() => target.MyMethod(input, out expectedOutput1, out expectedOutput2)).WillReturn(true);

    int output1;
    double output2;
    bool result = target.MyMethod(input, out output1, out output2);

    Assert.IsTrue(result);
    Assert.AreEqual<int>(expectedOutput1, output1);
    Assert.AreEqual<double>(expectedOutput2, output2);
}

Using Natural Mocks, it's as easy as:

[TestMethod]
[VerifyMocks]
public void TestMethodNatural()
{
    MyClass target = RecorderManager.CreateMockedObject<MyClass>();

    string input = "test value";
    int expectedOutput1 = 1;
    double expectedOutput2 = 2;

    using (RecordExpectations recorder = RecorderManager.StartRecording())
    {
        recorder.ExpectAndReturn(target.MyMethod(input, out expectedOutput1, out expectedOutput2), true);
    }

    int output1;
    double output2;
    bool result = target.MyMethod(input, out output1, out output2);

    Assert.IsTrue(result);
    Assert.AreEqual<int>(expectedOutput1, output1);
    Assert.AreEqual<double>(expectedOutput2, output2);
}

It's also possible using Reflective Mocks:

[TestMethod]
[VerifyMocks]
public void TestMethodReflective()
{
    MockObject<MyClass> targetMock = MockManager.MockObject<MyClass>();

    string input = "test value";
    int expectedOutput1 = 1;
    double expectedOutput2 = 2;

    targetMock.ExpectAndReturn(
        "MyMethod",
        new DynamicReturnValue(delegate(object[] parameters, object context)
            {
                parameters[1] = expectedOutput1;
                parameters[2] = expectedOutput2;
                return true;
            }));

    int output1;
    double output2;
    bool result = targetMock.Object.MyMethod(input, out output1, out output2);

    Assert.IsTrue(result);
    Assert.AreEqual<int>(expectedOutput1, output1);
    Assert.AreEqual<double>(expectedOutput2, output2);
}

All you have to do is choose which one you like most.

Tech·Ed EMEA 2008 Developers: Meet Me In Barcelona

Once again, I’ll be at an ATE Booth at Tech·Ed EMEA 2008 Developers.

As I already said about the PDC, what I like most of these events is networking with Microsoft staff and other attendees. So, if you want to meet me, I’ll be glad to meet you.

LINQ With C# Book

Luís just broke the news on our LINQ with C# book.

I was honored with the invitation from Luís to write this book with him for FCA, for which he has already published a few books [^] [^] [^] before.

This will be an entry level book in Portuguese targeted to anyone wanting to learn LINQ with C#.

It has been a fun project with great discussions (only possible because we have half an ocean between us :) ).

PDC2008: Meet Me In Los Angeles

It’s not the first time I try but, for one reason or another, this is the first time I will go to the PDC (Microsoft’s Professional Developers Conference).

According to the site “The PDC is designed for leading-edge developers and software architects. If you’re interested in the future of the Microsoft platform, you’re responsible for the technical strategy in your organization, or you’re a highly skilled developer who likes to delve deep into the heart of the platform, then the PDC is for you!”. If you fit this description, hurry up and register. Early bird discount has been extended until September 8th.

What I like most of these events is networking with Microsoft staff and other attendees. So, if you want to meet me, I’ll be glad to meet you.

Clone Detective For Visual Studio

Clone Detective for Visual Studio

Clone Detective is a tool that integrates with Visual Studio and uses the ConQAT (Continuous Quality Assessment Toolkit) to analyze C# projects and search for duplicated source code.

Watch the videos and see if this is the tool you were looking for.

E-Reference Library Subscription Discount Offer for The Community

Microsoft Press has created an exclusive discount URL for the E-Reference Library that MVPs can pass along to the broader community without any limitations or restrictions.

To create a trial subscription, community referrals should use the Trial URL (http://microsofteref2.books24x7.com/promo.asp?ref=mvptry).

Any community referrals who subscribe to E-Reference Libraries through the Subscription URL (http://microsofteref2.books24x7.com/promo.asp?ref=mvpbuy) will receive a 40% discount on a one-year subscription.

This discount offer ends on September 30, 2008.

StyleCop 4.3 Is Out

The StyleCop team announced the release of a version 4.3 of the StyleCop tool. You can get it from here.

On this version there are some bug fixes, new rules and documentation.

Also in this version, the list of errors and warnings goes to the Errors List window like with the compilers. I whish that the errors and warnings would also be sent to the Output window.

SDK documentation on how to author custom rules and integrate the tool with custom build environments is expected soon.

More Posts Next page »