Language: C#
First integration test of the semantic model for the conventional catalog
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"; } } }
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

