Force Pex To Find Factories In Satellite Pex Assemblies

I am still at my client Pexing out. It’s really neat to explore this whole new framework but honestly I am starting to get a little bored writing nothing but tests, even though Pex makes it a little better.

One problem I ran into when building the tests for my client was Pex was barfing because could not a factory that was located in a satellite Pex assembly. The only way that I could seemingly get it to work was to use to copy the relevant class to the other main Pex assembly, but this is terribly because not having the ambiguous references is pretty bad.

This is fixable however through the use of the assembly level PexExplorableFromFactoriesFromType and PexExplorableFromFactoriesFromAssembly attributes which allow you to specify factory methods to use in a declarative fashion.

This looks like the following:

[csharp]
[assembly: PexExplorableFromFactoriesFromType(typeof(TypeWithFactoryMethod))]
[/csharp]

Addition of the above will allow the mining of the appropriate factory methods.

Share

Casting To SPDocumentLibrary

A friend just asked me the way to cast a SPList To a SPDocumentLibrary so that he could access the document library specific attributes for document library objects. This is one way of doing it:

[csharp]

public static SPWeb GetWeb(string url)
{
using (SPSite site = new SPSite(url))
{
using (SPWeb web = site.OpenWeb())
{
return web;
}
}
}

public static SPDocumentLibrary CastDocumentLibrary(string url, string libraryName)
{
return GetWeb(url).Lists[libraryName] as SPDocumentLibrary;
}

[/csharp]

Obviously, the casting can take on many forms, but the end result is still an SPDocumentLibrary object.

Share