public void ConnectWithNonmatchingExport() { var plugins = CreatePluginTypes(); var repository = new Mock <IPluginRepository>(); { repository.Setup(r => r.Parts()) .Returns(plugins); } var importEngine = new Mock <IConnectParts>(); Func <Type, TypeIdentity> identityGenerator = t => TypeIdentity.CreateDefinition(t); Func <IBuildFixedSchedules> scheduleBuilder = () => new FixedScheduleBuilder(); var builder = new GroupDefinitionBuilder( repository.Object, importEngine.Object, identityGenerator, scheduleBuilder, new PluginFileInfo("a", DateTimeOffset.Now)); var firstInfo = builder.RegisterObject(typeof(ImportOnProperty)); var secondInfo = builder.RegisterObject(typeof(ActionOnMethod)); Assert.Throws <CannotMapExportToImportException>( () => builder.Connect(firstInfo.RegisteredImports.First(), secondInfo.RegisteredExports.First())); }
public void ConnectOverridingCurrentConnection() { var plugins = CreatePluginTypes(); GroupDefinition groupInfo = null; var repository = new Mock <IPluginRepository>(); { repository.Setup(r => r.Parts()) .Returns(plugins); repository.Setup(r => r.AddGroup(It.IsAny <GroupDefinition>(), It.IsAny <PluginFileInfo>())) .Callback <GroupDefinition, PluginFileInfo>((g, f) => groupInfo = g); } var importEngine = new Mock <IConnectParts>(); { importEngine.Setup(i => i.Accepts(It.IsAny <SerializableImportDefinition>(), It.IsAny <SerializableExportDefinition>())) .Returns(true); } Func <Type, TypeIdentity> identityGenerator = t => TypeIdentity.CreateDefinition(t); Func <IBuildFixedSchedules> scheduleBuilder = () => new FixedScheduleBuilder(); var builder = new GroupDefinitionBuilder( repository.Object, importEngine.Object, identityGenerator, scheduleBuilder, new PluginFileInfo("a", DateTimeOffset.Now)); var firstInfo = builder.RegisterObject(typeof(ImportOnProperty)); var secondInfo = builder.RegisterObject(typeof(ExportOnProperty)); builder.Connect(firstInfo.RegisteredImports.First(), secondInfo.RegisteredExports.First()); var thirdInfo = builder.RegisterObject(typeof(ExportOnProperty)); builder.Connect(firstInfo.RegisteredImports.First(), thirdInfo.RegisteredExports.First()); var groupName = "MyGroup"; builder.Register(groupName); Assert.IsNotNull(groupInfo); Assert.AreEqual(firstInfo.RegisteredImports.First(), groupInfo.InternalConnections.First().Import); Assert.AreEqual(1, groupInfo.InternalConnections.First().Exports.Count()); Assert.AreEqual(thirdInfo.RegisteredExports.First(), groupInfo.InternalConnections.First().Exports.First()); }
public void Connect() { var plugins = CreatePluginTypes(); GroupDefinition groupInfo = null; var repository = new Mock<IPluginRepository>(); { repository.Setup(r => r.Parts()) .Returns(plugins); repository.Setup(r => r.AddGroup(It.IsAny<GroupDefinition>(), It.IsAny<PluginFileInfo>())) .Callback<GroupDefinition, PluginFileInfo>((g, f) => groupInfo = g); } var importEngine = new Mock<IConnectParts>(); { importEngine.Setup(i => i.Accepts(It.IsAny<SerializableImportDefinition>(), It.IsAny<SerializableExportDefinition>())) .Returns(true); } Func<Type, TypeIdentity> identityGenerator = t => TypeIdentity.CreateDefinition(t); Func<IBuildFixedSchedules> scheduleBuilder = () => new FixedScheduleBuilder(); var builder = new GroupDefinitionBuilder( repository.Object, importEngine.Object, identityGenerator, scheduleBuilder, new PluginFileInfo("a", DateTimeOffset.Now)); var firstInfo = builder.RegisterObject(typeof(ImportOnProperty)); var secondInfo = builder.RegisterObject(typeof(ExportOnProperty)); builder.Connect(firstInfo.RegisteredImports.First(), secondInfo.RegisteredExports.First()); var groupName = "MyGroup"; builder.Register(groupName); Assert.IsNotNull(groupInfo); Assert.AreEqual(firstInfo.RegisteredImports.First(), groupInfo.InternalConnections.First().Import); Assert.AreEqual(1, groupInfo.InternalConnections.First().Exports.Count()); Assert.AreEqual(secondInfo.RegisteredExports.First(), groupInfo.InternalConnections.First().Exports.First()); }
public void DefineExport() { var plugins = CreatePluginTypes(); GroupDefinition groupInfo = null; var repository = new Mock<IPluginRepository>(); { repository.Setup(r => r.Parts()) .Returns(plugins); repository.Setup(r => r.AddGroup(It.IsAny<GroupDefinition>(), It.IsAny<PluginFileInfo>())) .Callback<GroupDefinition, PluginFileInfo>((g, f) => groupInfo = g); } var importEngine = new Mock<IConnectParts>(); { importEngine.Setup(i => i.Accepts(It.IsAny<SerializableImportDefinition>(), It.IsAny<SerializableExportDefinition>())) .Returns(true); } Func<Type, TypeIdentity> identityGenerator = t => TypeIdentity.CreateDefinition(t); Func<IBuildFixedSchedules> scheduleBuilder = () => new FixedScheduleBuilder(); var builder = new GroupDefinitionBuilder( repository.Object, importEngine.Object, identityGenerator, scheduleBuilder, new PluginFileInfo("a", DateTimeOffset.Now)); var firstInfo = builder.RegisterObject(typeof(ImportOnProperty)); var secondInfo = builder.RegisterObject(typeof(ExportOnProperty)); var thirdInfo = builder.RegisterObject(typeof(ActionOnMethod)); var fourthInfo = builder.RegisterObject(typeof(ConditionOnProperty)); builder.Connect(firstInfo.RegisteredImports.First(), secondInfo.RegisteredExports.First()); var registrator = builder.RegisterSchedule(); { var vertex = registrator.AddExecutingAction(thirdInfo.RegisteredActions.First()); registrator.LinkFromStart(vertex, fourthInfo.RegisteredConditions.First()); registrator.LinkToEnd(vertex); registrator.Register(); } var groupExportName = "groupExport"; builder.DefineExport(groupExportName); var groupName = "MyGroup"; builder.Register(groupName); Assert.IsNotNull(groupInfo); Assert.AreEqual(new GroupRegistrationId(groupName), groupInfo.GroupExport.ContainingGroup); Assert.AreEqual(groupExportName, groupInfo.GroupExport.ContractName); Assert.That( groupInfo.GroupExport.ProvidedExports, Is.EquivalentTo( new List<ExportRegistrationId> { firstInfo.RegisteredExports.First(), thirdInfo.RegisteredExports.First(), fourthInfo.RegisteredExports.First(), })); }
public void ConnectWithNonmatchingExport() { var plugins = CreatePluginTypes(); var repository = new Mock<IPluginRepository>(); { repository.Setup(r => r.Parts()) .Returns(plugins); } var importEngine = new Mock<IConnectParts>(); Func<Type, TypeIdentity> identityGenerator = t => TypeIdentity.CreateDefinition(t); Func<IBuildFixedSchedules> scheduleBuilder = () => new FixedScheduleBuilder(); var builder = new GroupDefinitionBuilder( repository.Object, importEngine.Object, identityGenerator, scheduleBuilder, new PluginFileInfo("a", DateTimeOffset.Now)); var firstInfo = builder.RegisterObject(typeof(ImportOnProperty)); var secondInfo = builder.RegisterObject(typeof(ActionOnMethod)); Assert.Throws<CannotMapExportToImportException>( () => builder.Connect(firstInfo.RegisteredImports.First(), secondInfo.RegisteredExports.First())); }
public void DefineExport() { var plugins = CreatePluginTypes(); GroupDefinition groupInfo = null; var repository = new Mock <IPluginRepository>(); { repository.Setup(r => r.Parts()) .Returns(plugins); repository.Setup(r => r.AddGroup(It.IsAny <GroupDefinition>(), It.IsAny <PluginFileInfo>())) .Callback <GroupDefinition, PluginFileInfo>((g, f) => groupInfo = g); } var importEngine = new Mock <IConnectParts>(); { importEngine.Setup(i => i.Accepts(It.IsAny <SerializableImportDefinition>(), It.IsAny <SerializableExportDefinition>())) .Returns(true); } Func <Type, TypeIdentity> identityGenerator = t => TypeIdentity.CreateDefinition(t); Func <IBuildFixedSchedules> scheduleBuilder = () => new FixedScheduleBuilder(); var builder = new GroupDefinitionBuilder( repository.Object, importEngine.Object, identityGenerator, scheduleBuilder, new PluginFileInfo("a", DateTimeOffset.Now)); var firstInfo = builder.RegisterObject(typeof(ImportOnProperty)); var secondInfo = builder.RegisterObject(typeof(ExportOnProperty)); var thirdInfo = builder.RegisterObject(typeof(ActionOnMethod)); var fourthInfo = builder.RegisterObject(typeof(ConditionOnProperty)); builder.Connect(firstInfo.RegisteredImports.First(), secondInfo.RegisteredExports.First()); var registrator = builder.RegisterSchedule(); { var vertex = registrator.AddExecutingAction(thirdInfo.RegisteredActions.First()); registrator.LinkFromStart(vertex, fourthInfo.RegisteredConditions.First()); registrator.LinkToEnd(vertex); registrator.Register(); } var groupExportName = "groupExport"; builder.DefineExport(groupExportName); var groupName = "MyGroup"; builder.Register(groupName); Assert.IsNotNull(groupInfo); Assert.AreEqual(new GroupRegistrationId(groupName), groupInfo.GroupExport.ContainingGroup); Assert.AreEqual(groupExportName, groupInfo.GroupExport.ContractName); Assert.That( groupInfo.GroupExport.ProvidedExports, Is.EquivalentTo( new List <ExportRegistrationId> { firstInfo.RegisteredExports.First(), thirdInfo.RegisteredExports.First(), fourthInfo.RegisteredExports.First(), })); }