public void Connect() { using (var source = new CancellationTokenSource()) { var commands = new Mock <ICompositionCommands>(); { commands.Setup(c => c.Add(It.IsAny <GroupCompositionId>(), It.IsAny <GroupDefinition>())) .Returns( Task.Factory.StartNew( () => { }, source.Token, TaskCreationOptions.None, new CurrentThreadTaskScheduler())); commands.Setup(c => c.Connect(It.IsAny <GroupConnection>())) .Returns( Task.Factory.StartNew( () => { }, source.Token, TaskCreationOptions.None, new CurrentThreadTaskScheduler())); } var connector = new Mock <IConnectGroups>(); { connector.Setup( c => c.GenerateConnectionFor( It.IsAny <GroupDefinition>(), It.IsAny <GroupImportDefinition>(), It.IsAny <GroupDefinition>())) .Callback <GroupDefinition, GroupImportDefinition, GroupDefinition>( (importingGroup, importDef, exportingGroup) => { }) .Returns(Enumerable.Empty <PartImportToPartExportMap>()); } var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null); var layer = new ProxyCompositionLayer(commands.Object, connector.Object, systemDiagnostics); var exportingDefinition = new GroupDefinition("Group1"); var addTask = layer.Add(exportingDefinition); var exportingId = addTask.Result; var importingDefinition = new GroupDefinition("Group2"); addTask = layer.Add(importingDefinition); var importingId = addTask.Result; var importDefinition = GroupImportDefinition.CreateDefinition( "a", new GroupRegistrationId("b"), null, Enumerable.Empty <ImportRegistrationId>()); var connectTask = layer.Connect(importingId, importDefinition, exportingId); connectTask.Wait(); Assert.IsTrue(layer.IsConnected(importingId, importDefinition)); Assert.IsTrue(layer.IsConnected(importingId, importDefinition, exportingId)); Assert.AreEqual(exportingId, layer.ConnectedTo(importingId, importDefinition)); } }
public void ReloadFromDataset() { var importingId = new GroupCompositionId(); var exportingId = new GroupCompositionId(); var importingGroup = new GroupDefinition("Group1"); var exportingGroup = new GroupDefinition("Group2"); var importDefinition = GroupImportDefinition.CreateDefinition( "a", new GroupRegistrationId("b"), null, Enumerable.Empty <ImportRegistrationId>()); var state = new GroupCompositionState( new List <Tuple <GroupCompositionId, GroupDefinition> > { new Tuple <GroupCompositionId, GroupDefinition>(importingId, importingGroup), new Tuple <GroupCompositionId, GroupDefinition>(exportingId, exportingGroup), }, new List <Tuple <GroupCompositionId, GroupImportDefinition, GroupCompositionId> > { new Tuple <GroupCompositionId, GroupImportDefinition, GroupCompositionId>(importingId, importDefinition, exportingId) }); using (var source = new CancellationTokenSource()) { var commands = new Mock <ICompositionCommands>(); { commands.Setup(c => c.CurrentState()) .Returns( Task <GroupCompositionState> .Factory.StartNew( () => state, source.Token, TaskCreationOptions.None, new CurrentThreadTaskScheduler())); } var connector = new Mock <IConnectGroups>(); var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null); var layer = new ProxyCompositionLayer(commands.Object, connector.Object, systemDiagnostics); var task = layer.ReloadFromDataset(); task.Wait(); Assert.IsTrue(layer.Contains(importingId)); Assert.AreEqual(importingGroup, layer.Group(importingId)); Assert.IsTrue(layer.Contains(exportingId)); Assert.AreEqual(exportingGroup, layer.Group(exportingId)); Assert.IsTrue(layer.IsConnected(importingId, importDefinition)); Assert.IsTrue(layer.IsConnected(importingId, importDefinition, exportingId)); Assert.AreEqual(exportingId, layer.ConnectedTo(importingId, importDefinition)); } }
public void IsConnectedWithUnknowns() { var commands = new Mock <ICompositionCommands>(); var connector = new Mock <IConnectGroups>(); var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null); var layer = new ProxyCompositionLayer(commands.Object, connector.Object, systemDiagnostics); var importDefinition = GroupImportDefinition.CreateDefinition( "a", new GroupRegistrationId("b"), null, Enumerable.Empty <ImportRegistrationId>()); Assert.IsFalse(layer.IsConnected(null, importDefinition)); Assert.IsFalse(layer.IsConnected(new GroupCompositionId(), null)); Assert.IsFalse(layer.IsConnected(new GroupCompositionId(), importDefinition)); }
public void Connect() { using (var source = new CancellationTokenSource()) { var commands = new Mock<ICompositionCommands>(); { commands.Setup(c => c.Add(It.IsAny<GroupCompositionId>(), It.IsAny<GroupDefinition>())) .Returns( Task.Factory.StartNew( () => { }, source.Token, TaskCreationOptions.None, new CurrentThreadTaskScheduler())); commands.Setup(c => c.Connect(It.IsAny<GroupConnection>())) .Returns( Task.Factory.StartNew( () => { }, source.Token, TaskCreationOptions.None, new CurrentThreadTaskScheduler())); } var connector = new Mock<IConnectGroups>(); { connector.Setup( c => c.GenerateConnectionFor( It.IsAny<GroupDefinition>(), It.IsAny<GroupImportDefinition>(), It.IsAny<GroupDefinition>())) .Callback<GroupDefinition, GroupImportDefinition, GroupDefinition>( (importingGroup, importDef, exportingGroup) => { }) .Returns(Enumerable.Empty<PartImportToPartExportMap>()); } var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null); var layer = new ProxyCompositionLayer(commands.Object, connector.Object, systemDiagnostics); var exportingDefinition = new GroupDefinition("Group1"); var addTask = layer.Add(exportingDefinition); var exportingId = addTask.Result; var importingDefinition = new GroupDefinition("Group2"); addTask = layer.Add(importingDefinition); var importingId = addTask.Result; var importDefinition = GroupImportDefinition.CreateDefinition( "a", new GroupRegistrationId("b"), null, Enumerable.Empty<ImportRegistrationId>()); var connectTask = layer.Connect(importingId, importDefinition, exportingId); connectTask.Wait(); Assert.IsTrue(layer.IsConnected(importingId, importDefinition)); Assert.IsTrue(layer.IsConnected(importingId, importDefinition, exportingId)); Assert.AreEqual(exportingId, layer.ConnectedTo(importingId, importDefinition)); } }
public void ReloadFromDataset() { var importingId = new GroupCompositionId(); var exportingId = new GroupCompositionId(); var importingGroup = new GroupDefinition("Group1"); var exportingGroup = new GroupDefinition("Group2"); var importDefinition = GroupImportDefinition.CreateDefinition( "a", new GroupRegistrationId("b"), null, Enumerable.Empty<ImportRegistrationId>()); var state = new GroupCompositionState( new List<Tuple<GroupCompositionId, GroupDefinition>> { new Tuple<GroupCompositionId, GroupDefinition>(importingId, importingGroup), new Tuple<GroupCompositionId, GroupDefinition>(exportingId, exportingGroup), }, new List<Tuple<GroupCompositionId, GroupImportDefinition, GroupCompositionId>> { new Tuple<GroupCompositionId, GroupImportDefinition, GroupCompositionId>(importingId, importDefinition, exportingId) }); using (var source = new CancellationTokenSource()) { var commands = new Mock<ICompositionCommands>(); { commands.Setup(c => c.CurrentState()) .Returns( Task<GroupCompositionState>.Factory.StartNew( () => state, source.Token, TaskCreationOptions.None, new CurrentThreadTaskScheduler())); } var connector = new Mock<IConnectGroups>(); var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null); var layer = new ProxyCompositionLayer(commands.Object, connector.Object, systemDiagnostics); var task = layer.ReloadFromDataset(); task.Wait(); Assert.IsTrue(layer.Contains(importingId)); Assert.AreEqual(importingGroup, layer.Group(importingId)); Assert.IsTrue(layer.Contains(exportingId)); Assert.AreEqual(exportingGroup, layer.Group(exportingId)); Assert.IsTrue(layer.IsConnected(importingId, importDefinition)); Assert.IsTrue(layer.IsConnected(importingId, importDefinition, exportingId)); Assert.AreEqual(exportingId, layer.ConnectedTo(importingId, importDefinition)); } }
public void IsConnectedWithUnknowns() { var commands = new Mock<ICompositionCommands>(); var connector = new Mock<IConnectGroups>(); var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null); var layer = new ProxyCompositionLayer(commands.Object, connector.Object, systemDiagnostics); var importDefinition = GroupImportDefinition.CreateDefinition( "a", new GroupRegistrationId("b"), null, Enumerable.Empty<ImportRegistrationId>()); Assert.IsFalse(layer.IsConnected(null, importDefinition)); Assert.IsFalse(layer.IsConnected(new GroupCompositionId(), null)); Assert.IsFalse(layer.IsConnected(new GroupCompositionId(), importDefinition)); }