PDC2008: Is My House On The Cloud Or Is The Cloud In My House?

This year’s PDC is mostly about the cloud.


Everyone is talking about the cloud: cloud services, cloud computing, etc. but I’m not sure everyone has the same understanding of what the cloud is. Let’s say it’s a cloudy concept.


So, what is this cloud thing, anyway?


Let’s take Windows Home Server (WHS) as an example. Microsoft provides a set of services through homeserver.com that allows me to control my home server and access my other PCs in the home network. I guess I could say that homeserver.com is a cloud platform that puts my house in the cloud.


On the other hand, WHS is built on top of Windows Server 2003 which allows me to take full advantage of its web server (IIS) to expose services through homeserver.com. Services that could be for my personal use or that I could provide to others, thus putting my house on the cloud.


At a larger scale, that’s how I see the cloud and it’s usage. An indistinct universe of service providers and service consumers where some are just providers, others are just consumers and others are both (service aggregators, value added brokers, etc.)


I guess that Microsoft’s view in regards to the cloud and WHS is aligned with mine because there will be two PDC sessions about this:


  • Tue 10/28 | 5:15 PM-6:30 PM | 409A
    Presenter(s): CJ Saretto, Fabian Uhse

    Learn how to build applications and services deployed on Windows Home Server that power PCs and devices throughout a connected home. See an example home automation and energy management service, and watch the creation of an on-premises service that exposes HVAC, window shades, and lighting controls to all devices on the home network. Hear how to package the service as a Windows Home Server add-in, quickly create a configuration UI, deploy a PC application for controlling the service, and demonstrate control from other devices such as TVs and cell phones.

  • Wed 10/29 | 10:30 AM-11:45 AM | 409A
    Presenter(s): Brendan Grant, CJ Saretto

    Learn how to leverage the Remote Access platform in Windows Home Server to expose on-premises services running in the connected home to the Internet. See how to expose a home automation service running on Windows Home Server to the Internet, and watch a demonstration that shows how to expose services that may be hosted on other devices inside the connected home using Windows Home Server as a gateway. Finally, see a sneak preview of Home Server and Live Mesh working together to further enhance the remote experience for the connected home.


Windows Home Server Resources

And, suddenly, a cloud in your future is not a ad thing, quite the opposite.

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.