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?
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.
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.
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.
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.
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 :) ).
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 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.
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.
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.
Let’s face it, if you don’t know .NET Reflector, you can never claim to be a .NET developer.
Today Red Gate announced the acquisition of Lutz Roeder’s .NET Reflector.
On .NET Reflector’s page, Red Gate states that “will continue to maintain a free version for the benefit of the community”.
You can read an interview with Lutz Roeder and James Moore (general manager of .NET Developer Tools at Red Gate) at simple-talk.
James doesn’t know yet how to improve Reflector, but I do. Reflector needs a major improvement on UI usability and performance. Let’s see if I can come up with a list:
- For me, search as you type is not a good idea as it is in Reflector.
- Still in the search theme, search as you type would be nice for the active code window.
- I cannot understand why changing any of the options fires a total repaint and lost of the view of the active code item.
- Settings like code, documentation and number formatting should possible to change on the fly with a simple toolbar click.
I’m sure Red Gate is more than capable of taking good care of .NET Reflector.
Typemock has released an alpha version of its newest product: Typemock Racer.
Typemock Racer is the tool that uses dynamic and static analysis to find deadlocks in .NET code that had been previously announced by Roy Osherove.
Typemock has released version 5.0 of its unit testing tool: Isolator. Check out the release notes.
This new version comes with a new API: Arrange Act Assert:
I’ll have to say that I liked Isolator better over Isolate.
Also new in this version is the inclusion of the help file in the installation package.
While installing SQL Server 2008 in a Virtual PC virtual machine I run out of disk space.
Looking around, I found this great tool: VHD Resizer. Registration is required to download the tool.
In the past I presented another possible use for the using keyword: as hints on LINQ.
I’ve been giving some thought about this lately and refined my proposal.
var q = from person in personCollection using MyEnumerableExtensions
group person by person.LastName into g using new MyOtherComparer()
orderby g.Key using new MyComparer()
select person;
The above query would be converted to:
var q = MyEnumerableExtensions.OrderBy<string, Person>(
MyEnumerableExtensions.GroupBy<string, Person>(
personCollection,
person => person.LastName,
new MyComparer(),
),
g => g.Key,
mew MyOtherComparer()
);
What do you think of this?
C# 3.0 introduced object and collection initializers. It is now easier to initialize objects or collections:
var person = new Person { FirstName = "Paulo", LastName = "Morgado" };
var persons = new List<Person> {
new Person { FirstName = "Paulo", LastName = "Morgado" },
new Person { FirstName = "Luís", LastName = "Abreu" }
};
var personDirectory = new Dictionary<string, Person> {
{ "Lisboa", new Person { FirstName = "Paulo", LastName = "Morgado" } },
{ "Funchal", new Person { FirstName = "Luís", LastName = "Abreu" } }
};
Wouldn't be nice to be able to do the same on already created objects and collections?
But, what would the syntax used be? Something like this?
var person = new Person();
person = { FirstName = "Paulo", LastName = "Morgado" };
var persons = new List<Person>();
persons += {
new Person { FirstName = "Paulo", LastName = "Morgado" },
new Person { FirstName = "Luís", LastName = "Abreu" }
};
var personDirectory = new Dictionary<string, Person>();
personDirectory += {
{ "Lisboa", new Person { FirstName = "Paulo", LastName = "Morgado" } },
{ "Funchal", new Person { FirstName = "Luís", LastName = "Abreu" } }
};
What do you think of this?
According to the MSDN Subscriptions home page, we should expect Visual Studio 2008 Service Pack 1 availability after August 11, 2008.

SQL Server 2008 is finally out and comes with the Entity Framework, which means that SP1 for Visual Studio 2008 and the .NET Framework is almost out.
ASP.NET provides out of the box three session state stores:
| Provider |
Description |
| InProc |
Session state is stored in the ASP.NET cache. |
| SQLServer |
Session state is stored out-of-process in an SQL Server database. |
| StateServer |
Session state is stored out-of-process in an ASP.NET state service. |
Because with SQLServer and StateServer providers the state must cross the AppDomain boundary it needs to be serialized when stored and deserialized when loaded. Because the state needs to be loaded and stored on each request, it is only available from the PostAcquireRequestState to the ReleaseRequestState events. And, because of serialization and deserialization, all objects stored must be serializable any reference held to one of the session state items won’t be to the same item after being deserialized.
On the other hand, with the InProc provider, the state will never be serialized or deserialized, which means that objects don’t need to be serializable and any reference to an item in the state is always a reference to the item in the state even before the PostAcquireRequestState event and after the ReleaseRequestState event.
In practice, developers use the InProc provider and applications are deployed to production using the SQLServer provider. This usually leads to application errors, like storing non serializable objects in the state, that are only uncovered in production. That’s why I’ve written a serializable in-process session state store. You can find the sources here.
More Posts
Next page »