Open Source on .NET evening at UK Tech Days April 14th #uktechdays


Note: Cross posted from IUpdateable from Eric Nelson.

Permalink

That fine chap http://twitter.com/serialseb is pulling together an interesting evening of fun on the Wednesday in London and I for one will definitely be there.

Lots of goodness to learn about. If you are a .NET developer who still isn’t looking at Open Source, then the 14th is a great opportunity to see what you are missing out on.

Current program:

  • OpenRasta – A web application framework for .net
  • An introduction to IoC with Castle Windsor
  • FluentValidation, doing your validation in code
  • CouchDB, NoSQL: designing document databases
  • Testing your asp.net applications with IronRuby
  • Building a data-driven app in 15 minutes with FluentNHibernate

Register now

Related Links:

Microsoft Generation 4 Datacenter using ITPACs


Note: Cross posted from IUpdateable from Eric Nelson.

Permalink

Microsoft is continuing to make significant investments in Datacenter technology and is focused on solving issues such as long lead times, significant up-front costs and over capacity. Enter the world of modular Datacenters and ITPACs – IT Pre-Assembled Components. In simple terms – air handling and IT units which are pre-assembled (looking somewhat like a container) and then installed on concrete bases. Each unit can hold  between 400 and 2500 servers (which means many more virtual machines depending on your density)

image

image

Kevin Timmons’, manager of the datacenter operations team, just posted a great post digging into the detail One Small Step for Microsoft’s Cloud, Another Big Step for Sustainability which includes a short video on how we build one of these ITPACs.

You might also want to check out this video from the PDC:

Get Microsoft SilverlightNote: Cross posted from IUpdateable from Eric Nelson.

Permalink

5 Steps to getting started with IronRuby


Note: Cross posted from IUpdateable from Eric Nelson.

Permalink

IronRuby is a Open Source implementation of the Ruby programming language for .NET, heavily relying on Microsoft’s Dynamic Language Runtime. The project’s #1 goal is to be a true Ruby implementation, meaning it runs existing Ruby code. Check out this summary of using the Ruby standard library and 3rd party libraries in IronRuby. IronRuby has tight integration with .NET, so any .NET types can be used from IronRuby and the IronRuby runtime can be embedded into any .NET application.

These 5 steps should get you nicely up and running on IronRuby – OR … you could just watch a video session from the lead developer which took place earlier this month (March 2010 – 60mins). But the 5 steps will be quicker :-)

Step 1 – Install IronRuby :-)

You can install IronRuby automatically using an MSI or manually. For simplicity I would recommend the MSI install.

TIP: As of the 25th of March IronRuby has not quite shipped. The download above is a Release Candidate (RC) which means it is still undergoing final testing by the team. You will need to uninstall this version (RC3) once the final release is available. The good news is that uninstalling IronRuby RC3 will work without a hitch as the MSI does relatively little.

Step 2 – Install an IronRuby friendly editor

You will need to Install an editor to work with IronRuby as there is no designer support for IronRuby inside Visual Studio. There are many editors to choose from but I would recommend you either went with:

  • SciTE (Download the MSI): This is a lightweight text editor which is simple to get up and running. SciTE understands Ruby syntax and allows you to easily run IronRuby code within the editor with a small change to the config file.
  • SharpDevelop 3.2 (Download the MSI): This is an open source development environment for C#, VB, Boo and now IronRuby. IronRuby support is new but it does include integrated debugging. You might also want to check out the main site for SharpDevelop.

TIP: There are commercial tools for Ruby development which offer richer support such as intellisense.. They can be coerced into working with IronRuby. A good one to start with is RubyMine which needs some small changes to make it work with IronRuby.

Step 3 – Run the IronRuby Tutorial

Run through the IronRuby tutorial which is included in the IronRuby download. It covers off the basics of the Ruby languages and how IronRuby integrates with .NET. In a typical install it will end up at C:\Program Files\IronRuby 0.9.4.0\Samples\Tutorial.

image

Which will give you the tutorial implemented in .NET and Ruby.

image

TIP: You might also want to check out these two introductory posts Using IronRuby and .NET to produce the ‘Hello World of WPF’ and What’s IronRuby, and how do I put it on Rails?

Step 4 – Get some good books to read

Get a great book on Ruby and IronRuby. There are several free ebooks on Ruby which will help you learn the language. The little book of Ruby is a good place to start.

I would also recommend you purchase IronRuby Unleashed (Buy on Amazon UK | Buy on Amazon USA). You might also want to check out this mini-review.

Other books are due out soon including IronRuby in Action.

TIP: Also check out the official documentation for using .NET from IronRuby.

Step 5 – Keep an eye on the team blogs

Keep an eye on the IronRuby team blogs including Jimmy Schementi, Jim Deville and Tomas Matousek (full list)

TIP: And keep a watch out for the final release of IronRuby – due anytime soon!

Note: Cross posted from IUpdateable from Eric Nelson.

Permalink

GuestPost: Unit Testing Entity Framework (v1) Dependent Code using TypeMock Isolator


Time for another guest post (check out others in the series), this time bringing together the world of mocking with the world of Entity Framework. A big thanks to Moses for agreeing to do this.

Unit Testing Entity Framework Dependent Code using TypeMock Isolator by Muhammad Mosa

image

Introduction

Unit testing data access code in my opinion is a challenging thing. Let us consider unit tests and integration tests. In integration tests you are allowed to have environmental dependencies such as a physical database connection to insert, update, delete or retrieve your data. However when performing unit tests it is often much more efficient and productive to remove environmental dependencies. Instead you will need to fake these dependencies. Faking a database (also known as mocking) can be relatively straight forward but the version of Entity Framework released with .Net 3.5 SP1 has a number of implementation specifics which actually makes faking the existence of a database quite difficult.

Faking Entity Framework

As mentioned earlier, to effectively unit test you will need to fake/simulate Entity Framework calls to the database. There are many free open source mocking frameworks that can help you achieve this but it will require additional effort to overcome & workaround a number of limitations in those frameworks.

Examples of these limitations include:

  • Not able to fake calls to non virtual methods
  • Not able to fake sealed classes
  • Not able to fake LINQ to Entities queries (replace database calls with in-memory collection calls)

There is a mocking framework which is flexible enough to handle limitations such as those above. The commercially available TypeMock Isolator can do the job for you with less code and ultimately more readable unit tests.

I’m going to demonstrate tackling one of those limitations using MoQ as my mocking framework. Then I will tackle the same issue using TypeMock Isolator.

Mocking Entity Framework with MoQ

One basic need when faking Entity Framework is to fake the ObjectContext. This cannot be done by passing any connection string. You have to pass a correct Entity Framework connection string that specifies CSDL, SSDL and MSL locations along with a provider connection string. Assuming we are going to do that, we’ll explore another limitation.

The limitation we are going to face now is related to not being able to fake calls to non-virtual/overridable members with MoQ.

I have the following repository method that adds an EntityObject (instance of a Blog entity) to Blogs entity set in an ObjectContext.

public override void Add(Blog blog)
{
    if(BlogContext.Blogs.Any(b=>b.Name == blog.Name))
    {
        throw new InvalidOperationException("Blog with same name already exists!");
    }
    BlogContext.AddToBlogs(blog);
}

The method does a very simple check that the name of the new Blog entity instance doesn’t exist. This is done through the simple LINQ query above. If the blog doesn’t already exist it simply adds it to the current context to be saved when SaveChanges of the ObjectContext instance (e.g. BlogContext) is called. However, if a blog with the same name exits, and exception (InvalideOperationException) will be thrown.

Let us now create a unit test for the Add method using MoQ.

[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public void Add_Should_Throw_InvalidOperationException_When_Blog_With_Same_Name_Already_Exits()
{
//(1) We shouldn't depend on configuration when doing unit tests! But, 
//its a workaround to fake the ObjectContext
    string connectionString = ConfigurationManager
                                .ConnectionStrings["MyBlogConnString"]
                                .ConnectionString;

    //(2) Arrange: Fake ObjectContext
    var fakeContext = new Mock<MyBlogContext>(connectionString);

    //(3) Next Line will pass, as ObjectContext now can be faked with proper connection string
    var repo = new BlogRepository(fakeContext.Object);

    //(4) Create fake ObjectQuery<Blog>. Will be used to substitute MyBlogContext.Blogs property
    var fakeObjectQuery = new Mock<ObjectQuery<Blog>>("[Blogs]",
                                                        fakeContext.Object);
    //(5) Arrange: Set Expectations
    //Next line will throw an exception by MoQ: 
    //System.ArgumentException: Invalid setup on a non-overridable member
    fakeContext.SetupGet(c=>c.Blogs).Returns(fakeObjectQuery.Object);
    fakeObjectQuery.Setup(q => q.Any(b => b.Name == "NewBlog")).Returns(true);

    //Act
    repo.Add(new Blog { Name = "NewBlog" });
}

This test method is checking to see if the correct exception ([ExpectedException(typeof(InvalidOperationException))]) is thrown when a developer attempts to Add a blog with a name that’s already exists.

  • On (1) a connection string is initialized from configuration file. To retrieve the full connection string.
  • On (2) a fake ObjectContext is being created. The ObjectContext here is MyBlogContext and its being created using this var fakeContext = new Mock<MyBlogContext>(connectionString); This way a fake context is being created using MoQ.
  • On (3) a BlogRepository instance is created. BlogRepository has dependency on generate Entity Framework ObjectContext, MyObjectContext. And so the fake context is passed to the constructor.

    var repo = new BlogRepository(fakeContext.Object);

  • On (4) a fake instance of ObjectQuery<Blog> is being created to use as a substitute to MyObjectContext.Blogs property as we will see in (5).
  • On (5) setup an expectation for calling Blogs property of MyBlogContext and substitute the return result with the fake ObjectQuery<Blog> instance created on (4).

When you run this test it will fail with MoQ throwing an exception because of this line:

fakeContext.SetupGet(c=>c.Blogs).Returns(fakeObjectQuery.Object);

This happens because the generate property MyBlogContext.Blogs is not virtual/overridable. And assuming it is virtual or you managed to make it virtual it will fail at the following line throwing the same exception:

fakeObjectQuery.Setup(q => q.Any(b => b.Name == “NewBlog”)).Returns(true);

This time the test will fail because the Any extension method is not virtual/overridable. You won’t be able to replace ObjectQuery<Blog> with fake in memory collection to test your LINQ to Entities queries.

Now lets see how replacing MoQ with TypeMock Isolator can help.

Mocking Entity Framework with TypeMock Isolator

The following is the same test method we had above for MoQ but this time implemented using TypeMock Isolator:

[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public void Add_New_Blog_That_Already_Exists_Should_Throw_InvalidOperationException()
{
    //(1) Create fake in memory collection of blogs
    var fakeInMemoryBlogs = new List<Blog> {new Blog {Name = "FakeBlog"}};

    //(2) create fake context
    var fakeContext = Isolate.Fake.Instance<MyBlogContext>();

    //(3) Setup expected call to MyBlogContext.Blogs property through the fake context
    Isolate.WhenCalled(() => fakeContext.Blogs)
           .WillReturnCollectionValuesOf(fakeInMemoryBlogs.AsQueryable());

    //(4) Create new blog with a name that already exits in the fake in memory collection in (1)
    var blog = new Blog {Name = "FakeBlog"};

    //(5) Instantiate instance of BlogRepository (Class under test)
    var repo = new BlogRepository(fakeContext);

    //(6) Acting by adding the newly created blog ()
    repo.Add(blog);
}

When running the above test method it will pass as the Add method of BlogRepository is going to throw an InvalidOperationException which is the expected behaviour. Nothing prevents us from faking out the database interaction! Even faking ObjectContext  at (2) didn’t require a connection string. On (3) Isolator sets up a faking result for MyBlogContext.Blogs when its being called through the fake instance fakeContext created on (2). The faking result is just an in-memory collection declared an initialized on (1).

Finally at (6) action we call the Add method of BlogRepository passing a new Blog instance that has a name that’s already exists in the fake in-memory collection which we set up at (1). As expected the test will pass because it will throw the expected exception defined on top of the test method – InvalidOperationException.

TypeMock Isolator succeeded in faking Entity Framework with ease.

Conclusion

We explored how to write a simple unit test using TypeMock Isolator for code which is using Entity Framework. We also explored a few of the limitations of other mocking frameworks which TypeMock is successfully able to handle. There are workarounds that you can use to overcome limitations when using MoQ or Rhino Mock, however the workarounds will require you to write more code and your tests will likely be more complex.

For a comparison between different mocking frameworks take a look at this document produced by TypeMock. You might also want to check out this open source project to compare mocking frameworks.

I hope you enjoyed this post

Muhammad Mosa

http://mosesofegypt.net/

http://twitter.com/mosessaur

Screencast of unit testing Entity Framework

Related Links

Note: Cross posted from IUpdateable from Eric Nelson.

Permalink

FREE Windows Azure evening in London on April 15th including FREE access to Windows Azure


Note: Cross posted from IUpdateable from Eric Nelson.

Permalink

[Did I overdo the use of FREE in the title? :-)]

April 12th to 16th is Microsoft Tech Days – 5 days of sessions on Visual Studio 2010 through to Windows 7 Phone Series. Many of these days are now full (Tip – Thursday still has room if rich client applications is your thing) but the good news is the development community in the UK has pulled together an awesome series of “fringe events” during April in London and elsewhere in the UK. There are sessions on Silverlight, SQL Server 2008 R2, Sharepoint 2010 and … the Windows Azure Platform.

The UK AzureNET user group is planning to put on a great evening and

AzureNET will be giving away hundreds of free subscriptions to the Windows Azure Platform during the evening.

The subscription includes up to 20 Windows Azure Compute nodes and 3 SQL Azure databases for you to play with over the 2 weeks following the event. This is a great opportunity to really explore the Windows Azure Platform in detail – without a credit card!

Register now! (and you might also want to join the UK Fans of Azure Community while I have your attention)

FYI The Thursday day time event includes an introduction to Windows Azure session delivered by my colleague David – which would be an ideal session to attend if you are new to Azure and want to get the most out of the evening session.

7:00pm: See the difference: How Windows Azure helped build a new way of giving
Simon Evans and James Broome (@broomej)
They will cover the business context for Azure and then go into patterns used and lessons learnt from the project….as well as showing off the app of course!

8:00pm: UK AzureNET update

8:15pm: NoSQL databases or: How I learned to love the hash table
Mark Rendle (@markrendle)
In this session Mark will look at how Azure Table Service works and how to use it. We’ll look briefly at the high-level Data Services SDK, talk about its limitations, and then quickly move on to the REST API and how to use it to improve performance and reduce costs. We’ll make-up some pretend real-world problems and solve them in new and interesting ways. We’ll denormalise data (for fun and profit). We’ll talk about how certain social networking sites can deal with huge volumes of data so quickly, and why it sometimes goes wrong.

Check out the complete list of fringe events which covers the UK fairly well:

image

Rob Blackwell on interoperability and Azure


Note: Cross posted from IUpdateable from Eric Nelson.

Permalink

At QCon in March we had a sample Azure application implemented in both Java and Ruby to demonstrate that the Windows Azure Platform is not just about .NET. The following is an interesting interview with Rob Blackwell, the R&D director of the partner who implemented the application.

UK Interoperability Team Interviews Rob Blackwell, R&D Director at Active Web Solutions.

Is Microsoft taking interoperability seriously?

Yes. In the past, I think Microsoft has, quite rightly come in for criticism, but architects and developers should look at this again. The Interoperability Bridges site (http://www.interoperabilitybridges.com/ ) shows a wide range of projects that allow interoperability from Java, Ruby and PHP for example.

The Windows Azure platform has been architected with interoperable APIs in mind. It’s straightforward to access the various storage facilities from just about any language or platform. Azure compute is capable of running more than just C# applications!

Why is interoperability important to you?

My company provides consultancy and bespoke development services. We’re a Microsoft Gold Partner, but we live in the real world where companies have a mix of technologies provided by a variety of vendors.

When developing an enterprise software solution, you rarely have a completely blank canvas. We often see integration scenarios where we need to exchange data with legacy systems. It’s not unusual to see modern Silverlight applications being built on top of Java or Mainframe based back ends.

Could you give us some examples of where interoperability has been important for your projects?

We developed an innovative Sea Safety system for the RNLI Lifeboats here in the UK. Commercial Fishing is one of the most dangerous professions and we helped developed the MOB Guardian System which uses satellite technology and man overboard devices to raise the alarm when a fisherman gets into trouble. The solution is implemented in .NET running on Windows, but without interoperable standards, it would have been impossible to communicate with the satellite gateway technology. For more information, please see the case study: http://www.microsoft.com/casestudies/Case_Study_Detail.aspx?CaseStudyID=4000005892

More recently, we were asked to build a web site to accompany the QCon 2010 conference in London to help demonstrate and promote interoperability. We built the site using Java and Restlet and hosted it in Windows Azure Compute. The site accepts feedback from visitors and all the data is stored in Windows Azure Storage. We also ported the application to Ruby on Rails for demonstration purposes. Visitors to the stand were surprised that this was even possible.

Why should Java developers be interested in Windows Azure?

Windows Azure Storage consists of Blobs, Queues and Tables. The storage is scalable, durable, secure and cost-effective. Using the WindowsAzure4j library, it’s easy to use, and takes just a few lines of code. If you are writing an application with large data storage requirements, or you want an offsite backup, it makes a lot of sense.

Running Java applications in Azure Compute is straightforward with tools like the Tomcat Solution Accelerator (http://code.msdn.microsoft.com/winazuretomcat )and AzureRunMe (http://azurerunme.codeplex.com/ ).

The Windows Azure AppFabric Service Bus can also be used to connect heterogeneous systems running on different networks and in different data centres.

How can The Service Bus be considered an interoperability solution?

I think that the Windows Azure AppFabric Service Bus is one of Microsoft’s best kept secrets. Think of it as “a globally scalable application plumbing kit in the sky”.

If you have used Enterprise Service Buses before, you’ll be familiar with the concept. Applications can connect to the service bus to securely exchange data – these can be point to point or multicast links.

With the AppFabric Service Bus, the applications can exist anywhere that has access to the Internet and the connections can traverse firewalls. This makes it easy to extend or scale your application or reach out to other networks and technologies.

For example, let’s say you have a SQL Server database running on premises and you want to expose the data to a Java application running in the cloud. You could set up a point to point Service Bus connection and use JDBC. Traditionally this would have been difficult or impossible without punching holes in firewalls and compromising security.

Rob Blackwell is R&D Director at Active Web Solutions, www.aws.net , a Microsoft Gold Partner specialising in leading edge software solutions. He is an occasional writer and conference speaker and blogs at www.robblackwell.org.uk

Related Links:

Live examples of the Windows Azure Platform running Java and Ruby on Rails


Note: Cross posted from IUpdateable from Eric Nelson.

Permalink

At QCon in March we had a booth focused on interoperability out of which came the idea to create an application implemented in both Java and Ruby on Rails, running on top of the Windows Azure Platform.

Nothing fancy, just an application to capture attendees view on Microsoft and Interoperability. It was implemented by Active Web Solutions, long time fans of Azure.

Wroth a quick squint :-) Check out the related links below for info to get you up and running.

image

Check out

Related Links:

Slides and links for Entity Framework 4 and Azure from Devweek 2010


Note: Cross posted from IUpdateable from Eric Nelson.

Permalink

Last week (March 2010) I presented on Entity Framework 4 and the Windows Azure Platform at www.devweek.com. As usual, it was a great conference and I caught up with lots of old friends and made some new ones along the way.

Entity Framework 4

Windows Azure and SQL Azure

Entity Framework 4 Related Links

  • Poll on Entity Framework 4 – one year on
  • 101 EF4 Resources
  • Recent resources on Entity Framework 4
  • Installing all the bits to demo Entity Framework 4 on the Visual Studio 2010 Release Candidate

    Azure Related Links

  • UK Azure Online Community – join today.
  • UK Windows Azure Site
  • Start working with Windows Azure
  • TCO and ROI calculator for Windows Azure

     

  • Windows Azure guidance from the Patterns and Practices team


    Note: Cross posted from IUpdateable from Eric Nelson.

    Permalink

    The P&P team have started to share guidance on the Windows Azure Platform.  They plan to group their efforts around:

    1. Moving to the Cloud
    2. Integrating with the Cloud
    3. Leveraging the Cloud

    First up is a document which explains the capabilities and limitations of Enterprise Library 5.0 Beta 2 in terms of use within .NET applications designed to run with the Windows Azure platform. You can download it here.

    Related Links:

    Slides and links from Cloud Computing Congress session on Windows Azure Platform


    Note: Cross posted from IUpdateable from Eric Nelson.

    Permalink

    On Tuesday (16th March 2010) I presented on Azure to a none technical audience at the Cloud Computing Congress. Great audience, lots of folks, lots of questions during and after – although it did feel odd to do a session with no code :-)

    Lots of people asked me for my slide deck – which is a 30minute none technical overview.

    I will get it on my slideshare.net (which is being temperamental) but in the meantime I have hosted it on skydrive.

    or download link.

    Related Links: