Microsoft Content Management Server - Unit test MCMS using VS 2005 and Test Project

This is Interesting: Free IT Magazines  
Home > Archive > Microsoft Content Management Server > February 2007 > Unit test MCMS using VS 2005 and Test Project





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Unit test MCMS using VS 2005 and Test Project
George Leithead

2007-02-21, 1:16 pm

Hi all,

I was wondering if anyone has implemented any unit testing for their
Microsoft Content Management (MCMS) applications? If they have do
they have any examples of how to implement unit tests for things such
as preparing an application context for a MCMS console Application,
the creating of mock MCMS API objects and populating them for testing
purposes?

Basically any help on Unit testing MCMS using Visual Studio 2005 and
it's built in Unit Testing facilities would be a great help. Have
looked on the Web but not very successfully!

George Leithead

2007-02-26, 1:15 pm

On 21 Feb, 16:30, "George Leithead" <george.leith...@gmail.com> wrote:
> Hi all,
>
> I was wondering if anyone has implemented any unit testing for their
> Microsoft Content Management (MCMS) applications? If they have do
> they have any examples of how to implement unit tests for things such
> as preparing an application context for a MCMS console Application,
> the creating of mock MCMS API objects and populating them for testing
> purposes?
>
> Basically any help on Unit testing MCMS using Visual Studio 2005 and
> it's built in Unit Testing facilities would be a great help. Have
> looked on the Web but not very successfully!


Hi all,

By the defaning sounds of silence in regards to Unit Testing MCMS,
I'll assume that the MCMS developer community at large does not unit
test their code :-) So, I thought I'd share a little. I'm still
looking for more, if you have any?

In order to implement unit tests for Microsoft Content Management
Server (MCMS) applications, it is often necessary to create postings.
In order to do this there is a number of things that you must
remember.

-You need a CMS Application Context
-You need to authenticate as a valid MCMS User
-You must authenticate in Update mode
-A posting is created utilising a Template and is created within a
channel.
-The authenticated user must have the appropriate autor rights to the
said Template and channel

An example of creating a CMS Application Context:
Microsoft.ContentManagement.Publishing.CmsApplicationContext cc = new
Microsoft.ContentManagement.Publishing.CmsApplicationContext();

An example of authenticated as a user in Update mode:
cc. AuthenticateAsCurrentUser(PublishingMode
.Update);

An Example of obtaining the template object for which to create the
posting against:
// To create a new posting, it MUST be based on a Template! In this
case, the template from the ROOT template gallery is in the "LSC"
gallery and is called "Standard"
Template template = cc.RootTemplateGallery.GetByRelativePath("LSC/
Standard") as Template;

An example of obtaining the channel object in where to create the
posting:
// Just going to create the posting in the first child channel from
the root
Channel channel = cc.RootChannel.Channels[1];

An example of creating a posting within a channel, based on a
template:
Posting newPosting = channel.CreatePosting(template);

Spencer Harbar [MVP]

2007-02-28, 7:15 pm

First and foremost, whether VS 2003 with NUnit for .Net 1.1 or VS 2005 Test
is used (or even NUnit for .Net 2.0) as the unit testing framework it will
greatly ease the effort involved using a solid mocking library.



Nowadays, I would thoroughly recommend using TypeMock for that purpose
(compatible for use on .Net 1.1 and 2.0) - it has capabilities not offered
by other mocking libraries including the ability to mock concrete classes
(think, HttpContext objects etc). Unfortunately, it comes at a price but at
only $299 per developer I believe it is well worth it.



The trickier parts of the test driven development were typically parts of
the solution which referenced contextualised objects from the http or mcms
framework - for the most part these were the template code-behinds and
custom navigation, authoring and presentation web controls. Naturally, when
these objects are being tested with the framework of NUnit or VS there is no
context within which to run and they will fail. The same can be said for the
Sharepoint framework if you're looking at integration to Sharepoint.



Some folks have suggested approaching this by producing interfaced wrappers
for the contextual objects and mocking the interfaces in the test code - I
personally think this is a bad idea. You are adding complexity to your
production code to ease your test code implementation, unnecessarily
complicating your design pattern. With TypeMock it is possible to create
typed mocks which can mock any concrete classes (including private,
protected and internal methods, properties etc) and eliminate such elaborate
mechanisms.



I think the biggest pitfall which may easily be avoided when following a TDD
approach on a project is not to get carried away with intellectual
pursuits - typically, you can achieve everything you need to do to have a
clean, testable code base without resorting to exotic means if you just
think about what you're doing before you do it J Following best practices
and proven patterns will never let you down.



Keeping tests simple is also a key to success - each test should test for 1
thing and 1 thing only. Follow the red-green-refactor rule and you will also
ensure that you eliminate false positives and negatives. It may sound
excessive to have reams of tests but if they are developed intelligently
they can easily be maintained. My attention to design is as acute for my
test code as the production code and includes frequent reviews and
refactorings where appropriate.



I hope this is of some use and if there are any specific questions/problems
I would be happy to answer them.

--
Cheers
Spence
www.harbar.net
www.mcmsfaq.com
MVP - Office SharePoint Server

"George Leithead" <george.leithead@gmail.com> wrote in message
news:1172075407.921417.233870@j27g2000cwj.googlegroups.com...
> Hi all,
>
> I was wondering if anyone has implemented any unit testing for their
> Microsoft Content Management (MCMS) applications? If they have do
> they have any examples of how to implement unit tests for things such
> as preparing an application context for a MCMS console Application,
> the creating of mock MCMS API objects and populating them for testing
> purposes?
>
> Basically any help on Unit testing MCMS using Visual Studio 2005 and
> it's built in Unit Testing facilities would be a great help. Have
> looked on the Web but not very successfully!
>

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com