3302

.NET 3.5 SP1, VS2008 SP1 And TFS2008 SP1 Released

Microsoft .NET Framework 3.5 Service Pack 1

Microsoft Visual Studio 2008 Service Pack 1 (iso)

Visual Studio 2008 Team Foundation Server Service Pack 1

Visual Studio 2008 Service Pack 1 Expected Next Week

According to the MSDN Subscriptions home page, we should expect Visual Studio 2008 Service Pack 1 availability after August 11, 2008.

Using Random Values For Unit Testing

When writing my unit tests I don’t like to use hard coded fixed values because I either end up using the same values or, because of that, tests may succeed by coincidence.

Over time, I have developed an helper class to generate random values for testing.

namespace PauloMorgado.VisualStudio.TestTools.UnitTesting
{
    public static class RandomGenerator
    {
        public static bool Boolean();
        public static string String();
        public static string String(string prefix);
        public static short Int8();
        public static short Int8(short maxValue);
        public static short Int8(short minValue, short maxValue);
        public static short Int16();
        public static short Int16(short maxValue);
        public static short Int16(short minValue, short maxValue);
        public static int Int32();
        public static int Int32(int maxValue);
        public static int Int32(int minValue, int maxValue);
        public static TEnum Enum<TEnum>();
        public static TEnum EnumFlagsWith<TEnum>(TEnum flagsToAdd);
        public static TEnum EnumFlagsWithout<TEnum>(TEnum flagsToRemove);
        public static TEnum Enum<TEnum>(int maxValue);
        public static TEnum Enum<TEnum>(int minValue, int maxValue);
        public static System.Guid Guid();
    }
}

This is something that I would like to find on mock frameworks (like Typemock Isolator, Rhino.Mocks or MoQ).

It’s still a work in progress, but if you want to try it, it’s on my MSDN Code Gallery: Random Generator For Unit Testing

Microsoft Source Analysis for C# (aka StyleCop)

I’ve learned from a fellow GASPer of the release of Microsoft Source Analysis for C# (aka StyleCop).

It’s still a work in progress but it’s already very useful.

Typemock Isolator v4.2.4 Released

Typemock released version 4.2.4 of its Isolator mock framework.

You can check out the release notes in The Typemock Insider blog and download it from the Typemock Isolator Download page.

Stretching Type Inference

Note: Code in italics is not actual C# 3.0 syntax.


Local Variable Type Inference


C# 3.0 brought us local variable type inference mainly because of LINQ. The output of a query can vary from an IEnumerable<T> or an IQueryable<T> to a single instance of T where T can even be a projection which means that its type is an anonymous type.


Take the following query as an example:

from p in persons
select new { Name = p.FirstName + " " + p.LastName, Age = p.Age };

If persons is an IEnumerable<Person>, the output of the query will be an IEnumerable<T> where T is an anonymous type.


Now the question that arises is: How do I declare a variable to receive the output of the query?


The solution was the introduction of the new var keyword that instructs the compiler to determine the type of the output of the query. Now, all it takes to declare a variable to receive the output of the query is:

var q =
from p in persons
select new { Name = p.FirstName + " " + p.LastName, Age = p.Age };

Since the compiler can infer the type of something that looks so complex, it's obvious that it can infer the type of something so straightforward as:

var v = new Dictionary<Point, Stack<Person>>();

It's obvious that this is the same as:

Dictionary<Point, Stack<Person>> v = new Dictionary<Point, Stack<Person>>();

with less typing and margin for typing errors.


Field Type Inference


The same technique could be applied to field inference:

class Class
{
private someDicionary = new Dictionary<string, List<string>>();

// ...
}


with the same benefits of less typing and margin for typing errors.


If field type inference were to be applied to public fields, one constraint must be enforced though: the inferenced type cannot be or have as a type parameter an anonymous type.


But I wouldn't recommend that because it would be easy and not obvious that a small change in the field initialization could bring unobvious changes to the public interface of the class.


Method Output  And Parameter Type Inference


Since type inference would be possible outside of methods, should it be allowed on method output and parameter values? Something like this:

class SomeClass
{
private listOfStuff = new List<Stuff>();

public void DoIt()
{
if (CreateList(out this.listOfStuff))
{
ProcessList(ref this.listOfStuff);

this.listOfStuff = TransformList(this.listOfStuff);
}
}

private bool CreateList(var out list)
{
list = new List<Stuff>();
return true;
}

private void ProcessList(var ref list)
{
// ...
}

private var TransformList(var list)
{
return list;
}
}


which look very strange and confusing, to say the least. We shouldn't go there.


Constructor Inference


Every since I saw local variable type inference the first time, I have the feeling that more could have been done.


Let's look at this hypothetical set of declarations:

Dictionary<Point, Stack<Person>> v = new();
Point p = new(1, 2);

It's as easy to the compiler or a human reading the code that this is the same as:

Dictionary<Point, Stack<Person>> v = new Dictionary<Point, Stack<Person>>();
Point p = new Point(1, 2);

And this can be more powerful than local variable type inference and used in a lot more scenarios:

class Class
{
private Dictionary<string, List<string>> someDicionary = new();
private Point p;

public Class()
{
this.p = new(1, 1);
}

public void SomeMethod()
{
AnotherMethod(new());
}

private void AnotherMethod(List<string> arg)
{
// ...
}
}


Where To Stop?

The compiler could as easily infer the type of a local variable in this:

public void SomeMethod()
{
var v = new();
AnotherMethod(v);

}

Do we want to go there? I don't think so.


Ambiguities

C# 3.0 also brought object initializers. Instead of this:

XmlReaderSettings settings = new XmlReaderSettings();
settings.CheckCharacters = false;
settings.IgnoreWhitespace = true;

XmlReader reader = XmlReader.Create("someURI", settings);


we can just write this:

XmlReaderSettings settings = new XmlReaderSettings() { CheckCharacters = false, IgnoreWhitespace = true };

XmlReader reader = XmlReader.Create("someURI", settings);


or this:

XmlReader reader = XmlReader.Create("someURI"new XmlReaderSettings() { CheckCharacters = false, IgnoreWhitespace = true });

Wouldn't it be nice to just write:

XmlReaderSettings settings = new() { CheckCharacters = false, IgnoreWhitespace = true };

C# 3.0 object initializers also allow constructor parenthesis to be omitted:

XmlReaderSettings settings = new XmlReaderSettings { CheckCharacters = false, IgnoreWhitespace = true };

which would lead to:

XmlReaderSettings settings = new { CheckCharacters = false, IgnoreWhitespace = true };

which looks exactly like an anonymous object creation expression and could lead to some confusion and ambiguities.


But it would be nice to just write:

XmlReader reader = XmlReader.Create("someURI", new { settings.CheckCharacters = false, settings.IgnoreWhitespace = true });

 


Wouldn't it?

Web Authoring Component install fails when installing Visual Studio 2008

While trying to install Visual Studio 2008 Team Suite in my Windows XP Professional system it kept failing when installing Visual Studio because it couldn't find the Web Authoring Component (after installing having just successfully installed it).

I've looked around for occurrences of this problem but I didn't find anyone with such a problem.

I tried to install Visual Studio several times, successfully installing the Web Authoring Component (you can find it on the DVD - \WCU\WebDesignerCore\WebDesignerCore.EXE) before, but it always failed in the same step and for the same reason as before. And, even more strangely, after that, the Web Authoring Component was no longer installed.

I went through the install log file (%temp%\dd_depcheck_VS_VSTS_90.txt) and found this:

Microsoft Visual Studio Web Authoring Component ==  
    This component uses the FileRegVerCheck version check method. It will compare a given version against the version of a regkey on your machine. Registry key being interrogated: HKLM,SOFTWARE\Microsoft\Web Designer Tools\1033; Value: InstalledVersion; Version: 12.0.4518.1066. Version on user's machine:    12.0.4518.1064 Version to be installed:    12.0.4518.1066 Microsoft Visual Studio Web Authoring Component == Component to be installed.

I went to the registry and changed the value of the installed version to the one expected by Visual Studio installer and it installed it with no problems. And looks like it's working fine.

What strikes me as the most strange is not the fact that the component on the DVD has the wrong version. What strikes me the most is the fact that I had already installed Visual Studio using the same DVD without any problems.

Good System Bad System
Windows Vista Ultimate 64bit with SP1 (clean install) Windows XP Professional with SP2
Office 2007 with SP1 (clean install) Office 2007 with SP1 (upgraded from Office 2003)
  Visual Studio 2003
  Visual Studio 2005 with SP1
  Expression Web

The Web Authoring Component installer uses a Office 2007 wrapper. I wonder if that was the problem.

TypeMock Isolator 4.2 Released

TypeMock has released version 4.2 of its mocking framework: TypeMock Insulator. Check out the release notes.

My four favorite new features in this release are:

Improved mock chaining

(If you want to learn more about chains, read this post from Gil)

Take this class to be tested:

public class TestedClass1
{
    public IDictionary<string, object> Dictionary
    {
        get { throw new NotImplementedException(); }
    }

    public object Method(bool cond)
    {
        if (cond)
        {
            return Dictionary["true"];
        }
        else
        {
            return Dictionary["false"];
        }
    }
}

The following test:

[TestMethod]
[VerifyMocks]
public void TestMethod1()
{
    object trueObject = new object();
    object falseObject = new object();

    TestedClass1 target = RecorderManager.CreateMockedObject<TestedClass1>();

    using (RecordExpectations recorder = RecorderManager.StartRecording())
    {
        recorder.DefaultBehavior.CheckArguments();

        recorder.ExpectAndReturn(target.Dictionary["true"], trueObject);
        recorder.FailWhenCalled(target.Dictionary["false"]);
    }

    object value = target.Method(true);
    Assert.AreEqual(trueObject, value);
}

Would simply fail with:

Test method TestProject1.UnitTest1.TestMethod1 threw exception:  TypeMock.VerifyException: 
TypeMock Verification: Method TestProject1.TestedClass1.get_Dictionary() has 1 more expected calls
.

Now, it just passes.

Debugger evaluation doesn't change the test behavior

Now you can debug your code without having to change your tests. You can query mocked values without influencing your tests.

You can do this and still have the test passing:

Debugger Support

The debugger can be run inside a recording block without confusing the test

You can now step into the recording block and debug it without affecting the recording process and the test.

Recording Block

When you step in the debugger into a mocked method, the mocked method will be painted

When you step into a mocked method (or property) I'll see that it's mocked.

Visual Studio Cues

Web Client Software Factory 2.0 shipped

Web Client Software Factory 2.0

February 2008 Release

 

Resources

About the Deliverable

The Web Client Software Factory (WCSF) provides a set of guidance for architects and developers building enterprise Web applications. The factory includes samples, reusable code and a guidance package which automates key development tasks from within Visual Studio.

Using the Web Client Software Factory assets, developers can create Composite Web applications composed of independently developed and deployed modules. These modules are dynamically brought together at runtime into a common shell. Additionally the factory includes support for ASP.NET AJAX thus providing users with a richer and more responsive user experience.

New In This Release

The February 2008 release of the Web Client Software Factory has the following improvements to the June 2007 release.

  • Full support for Visual Studio 2008 and .NET Framework 3.5
  • Added ASP.NET AJAX extenders for Context Sensitive Autocomplete, AJAX Validation, and Real Time Search that can be used in existing ASP.NET sites and ASP.NET sites built using the Composite Web Application Block.
  • Added UI Composition capability through extending our dependency injection mechanism to support Pages, User Controls and Master Pages.
  • Added Dependency Injection on ASMX Web Services and JSON services.
  • Added a new set of Quickstarts and How-To topics on MVP, Modularity and the new AJAX extenders
  • Added a new Order Entry Reference application that demonstrates all of the new functionality.

In addition, this release of WCSF has the following community issues and fixes:

  • 42 Workitems closed including the top-voted items on CodePlex
  • Add ASP.NET AJAX Support (97 votes)
  • Web Client Software Factory Support for Enterprise Library 3.1 (62 votes)
  • Services through configuration (32 votes)
  • Support for using the Validation Application Block (16 votes)
  • Recipe support for Visual Basic .NET (20 votes)
  • Added Presenter support for Master Pages (11 votes)

Techdays Portugal 2008 – For A World 2.0

Microsoft Portugal will be hosting Techdays 2008 from Mars 12nd to 14th, right after the Portuguese launch of Microsoft Visual Studio 2008, Microsoft SQL Server 2008 and Microsoft Windows Server 2008 on Mars 11th.

This is the biggest and greatest tech event in Portugal and there will be lots of national and international speakers and contests.

I'll be there. Come visit us.