CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

First integration test of the semantic model for the conventional catalog

137 Views
Copy Code Show/Hide Line Numbers
public class MefIntegrationTests
{
    [Fact]
    public void ConventionsCatalog_should_export_conventionpart()
    {
        // Setup conventions using the semantic model
        // This is NOT the API that the user will be exposed to,
        // there will be a DSL at the front
 
        var exportConvention =
            new ExportConvention
            {
                Member = typeof (ConventionPart),
                ContractType = typeof(IConventionPart),
            };
 
        var convention =
            new Convention();
 
        convention.Exports.Add(exportConvention);
        convention.Condition = t => t.GetInterfaces().Contains(typeof (IConventionPart));
 
        var model =
            new ConventionModel();
 
        model.Conventions.Add(convention);
 
        // Setup container
 
        var conventionCatalog =
            new ConventionsCatalog(model);
 
        var typeCatalog =
            new TypeCatalog(typeof (AttributedPart));
 
        var aggregated =
            new AggregateCatalog(typeCatalog, conventionCatalog);
 
        var container =
            new CompositionContainer(aggregated);
 
        var part = new AttributedPart();
 
        var batch =
            new CompositionBatch();
        batch.AddPart(part);
 
        container.Compose(batch);
 
        // Assert
 
        part.Part.Count().ShouldEqual(2);
    }
}
 
public class AttributedPart
{
    [ImportMany(typeof(IConventionPart))]
    public IConventionPart[] Part { get; set; }
}
 
public interface IConventionPart
{
    string Name { get; }
}
 
public class ConventionPart : IConventionPart
{
    public string Name
    {
        get { return "ConventionPart"; }
    }
}
 
public class OtherConventionPart : IConventionPart
{
    public string Name
    {
        get { return "OtherConventionPart"; }
    }
}
by TheCodeJunkie
  January 14, 2010 @ 4:43am

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate