Sunday, September 12, 2010

Visual Studio Editor Extension for Code Contracts

Just a quickie. The DevLabs team have released an editor extension for Code Contracts which allows you to view the contract requirements for a given method in intellisense. It can be downloaded from the Visual Studio gallery here or the DevLabs Code Contracts site. Two things to note are that it is only for Visual Studio 2010 and currently only works with C#.

Thursday, September 09, 2010

Silverlight and the TabNavigation Property

In Silverlight 3 and onwards there is a TabNavigation property on controls that can have one of three values: “Once”, “Cycle” and “Local”. These values modify the tabbing behaviour of your application and it is worth knowing what affect each one has.

The following are some rough notes that have come out of playing around with these values

  • Setting the root user control’s TabNavigation property to “Local” (with all of its child controls tab navigation also set to “Local”) will navigate through all of the tabbable controls in the Silverlight app and then move out to the browser controls and eventually return to the app.
  • Setting the root user control’s TabNavigation property to “Cycle” will limit the tabbing to only the Silverlight app.
  • Setting the root user control to “Once” is just stupid.
  • If you set a control such as a textbox to “Cycle” once you hit that control you will never be able to tab out of it. If the control is a listbox or similar and it’s TabNavigation is set to “Cycle” tabbing will cycle through that  control’s child items.

These were quick observations and there are probably other quirks that need to be identified but that will do for the moment.

Monday, March 15, 2010

Oz WPF Mailing List is Up

Paul Stovell has announced the set-up of the Oz WPF mailing list.

You can read the announcement on Paul’s blog (OzWPF) or you can subscribe to the list by sending an email to ozwpf-subscribe@list.ozwpf.com or through http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf

Sunday, September 20, 2009

Ikebana and Design

Catching up on a backlog of unread blogs came across this one on Ikebana at Presentation Zen (10 design lessons from the art of Ikebana). What I particularly liked were the lessons for one’s creative life. I have reproduced them below verbatim but as my team is about to embark on UI design it would be good if I could introduce these ideas to them. I truly believe that it is time that software developers stop passing the buck when it comes to UI and user experience.

  1. Empty space is as important as the positive elements. Learn to see space. Learn to create space.
  2. Space allows other elements to “breath," to move, and connect — with each other and the viewer.
  3. Empty space is a powerful amplifier, helping to create a whole that is more engaging than the sum of individual parts.
  4. Suggestion and subtly in design engages the viewer, allowing her to complete the uncompleted.
  5. Arrangements (designs) should stimulate the imagination of the viewer.
  6. In formality there exists creativity and freedom of expression. No structure, no freedom.
  7. In simplicity there exists clarity, beauty, and meaning.
  8. Asymmetrical balance is natural, dynamic, and engaging.
  9. For the designer (or artist), focus, calm, vision, and gentleness of spirit are more important qualities than raw enthusiasm. Slow down your busy mind.
  10. Careful arrangement of the elements based on solid principles creates beauty and engagement without decoration.

Tuesday, May 12, 2009

Weird things with LINQ - stripping unwanted unicodes.

So here was my problem, I needed to strip any unicode characters above 255.
At first I thought of using a regular expression to do a replace with but then the exclusion clause might be a bit long. Then I thought "can I do it with LINQ?".

Here is the result:

  private static string StripUniCode(string originalText)

        {

            var chars = originalText.ToCharArray();

            var result = from chr in chars

                        where chr <= 255

                        select chr;

            StringBuilder sb = new StringBuilder();

            sb.Append(result.ToArray<char>());

 

            return sb.ToString().Trim();

 

        }


Not brilliant but what the hell. You gotta love LINQ.
 

    

Thursday, January 08, 2009

Integration testing for WCF with MSTest

As part of my research on WCF (with an eye on upgrading our existing web services) I started investigating how to create automated integration tests for WCF services. With our current services we write our integration tests in MSTest. To run the tests we all also need to either have the services set-up in IIS or or spin them up in an instance of Visual Studio. This makes running the tests fiddly and also complicates if we want to automate them as part of the build process.

With WCF we now can self-host a service which gives us some new options in regard to testing.
Howard van Rooijen in his blog offered a solution (Configuring WCF services for Unit Testing) which created an internal ServiceHost wrapper class for a new instance of the service host for testing. Though this solution worked there was a couple of areas where I thought it could be improved.

What I have done is:
a) remove the need for creating and maintaining a configuration file
b) move the whole thing into a seperate generic class ( called ServiceManager) which the contract and service as type parameters.
c) simplifying the the set-up process so it is more "set and forget" for a set of tests
d) incorporated the ChannelFactory creation into the class.

The code for this can be downloaded from the following link: Service manager for WCF tests.

To use the ServiceManager class we first create an instance of it:


[TestClass]

public class WebServiceIntegrationTests

{

static string baseAddress = @"http://localhost:8000/WebServiceTests";

static ServiceManager<IPeopleService, PeopleServiceType> serviceManager =

new ServiceManager<IPeopleService, PeopleServiceType>(baseAddress);


Having do that we then add the following code to the class initialise and cleanup methods:

[ClassInitialize()]

public static void ClassInitialize(TestContext testContext)

{

serviceManager.StartService();

}

[ClassCleanup()]

public static void ClassCleanup()

{

serviceManager.StopService();

}


With the service of the service host running all we need to do is write our testing using an instance of the ChannelFactory class:


[TestMethod]

public void GetNewPersonFromService()

{

string firstName = "Bob";

string lastName = "Builder";

int age = 35;

RelationshipType relation = RelationshipType.Business;

using (var factory = serviceManager.GetChannelFactory())

{

IPeopleService client = factory.CreateChannel();

Person person = client.GetNewPerson(firstName, lastName, age, relation);

Assert.AreEqual<string>(firstName, person.FirstName);

Assert.AreEqual<string>(lastName, person.LastName);

Assert.AreEqual<int>(age, person.Age);

Assert.AreEqual<RelationshipType>(relation, person.Relationship);

}

}


The key thing with this solution is that it is very easy to set-up and we don't have to worry about configuration settings for the services since it is all done programmatically. This means that setting and maintaining the tests is a lot easier which is always a good thing.




Monday, October 13, 2008

Interesting article on locking

Thread locking is one of those things where one moment I understand it with crystal clarity and the next moment become a blithering idiot. One day I know it is going to stick.

In the mean time here is an interesting article by Jeff Moser on how locks lock