Esempio n. 1
0
        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));
            }
        }
Esempio n. 2
0
        public void ConnectWithUnknownExportingGroup()
        {
            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()));
                }

                var connector         = new Mock <IConnectGroups>();
                var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
                var layer             = new ProxyCompositionLayer(commands.Object, connector.Object, systemDiagnostics);

                var exportingGroup = new GroupDefinition("Group1");
                var task           = layer.Add(exportingGroup);
                task.Wait();

                var importDefinition = GroupImportDefinition.CreateDefinition(
                    "a",
                    new GroupRegistrationId("b"),
                    null,
                    Enumerable.Empty <ImportRegistrationId>());
                Assert.Throws <UnknownPartGroupException>(() => layer.Connect(task.Result, importDefinition, new GroupCompositionId()));
            }
        }
Esempio n. 3
0
        public void Remove()
        {
            GroupCompositionId storedId         = null;
            GroupDefinition    storedDefinition = null;

            using (var source = new CancellationTokenSource())
            {
                var commands = new Mock <ICompositionCommands>();
                {
                    commands.Setup(c => c.Add(It.IsAny <GroupCompositionId>(), It.IsAny <GroupDefinition>()))
                    .Callback <GroupCompositionId, GroupDefinition>(
                        (id, def) =>
                    {
                        storedId         = id;
                        storedDefinition = def;
                    })
                    .Returns(
                        Task.Factory.StartNew(
                            () => { },
                            source.Token,
                            TaskCreationOptions.None,
                            new CurrentThreadTaskScheduler()));

                    commands.Setup(c => c.Remove(It.IsAny <GroupCompositionId>()))
                    .Callback <GroupCompositionId>(id => storedId = id)
                    .Returns(
                        Task.Factory.StartNew(
                            () => { },
                            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 definition = new GroupDefinition("Group1");
                var task       = layer.Add(definition);
                task.Wait();

                Assert.AreSame(storedId, task.Result);
                Assert.AreSame(definition, storedDefinition);
                Assert.IsTrue(layer.Contains(task.Result));

                var otherTask = layer.Remove(task.Result);
                otherTask.Wait();

                Assert.AreSame(task.Result, storedId);
                Assert.IsFalse(layer.Contains(task.Result));
            }
        }
        public void Add()
        {
            GroupCompositionId storedId = null;
            GroupDefinition storedDefinition = null;
            using (var source = new CancellationTokenSource())
            {
                var commands = new Mock<ICompositionCommands>();
                {
                    commands.Setup(c => c.Add(It.IsAny<GroupCompositionId>(), It.IsAny<GroupDefinition>()))
                        .Callback<GroupCompositionId, GroupDefinition>(
                            (id, def) =>
                            {
                                storedId = id;
                                storedDefinition = def;
                            })
                        .Returns(
                            Task.Factory.StartNew(
                                () => { },
                                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 definition = new GroupDefinition("Group1");
                var task = layer.Add(definition);
                task.Wait();

                Assert.AreSame(storedId, task.Result);
                Assert.AreSame(definition, storedDefinition);
                Assert.IsTrue(layer.Contains(task.Result));
            }
        }
        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 ConnectWithUnknownImportingGroup()
        {
            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()));
                }

                var connector = new Mock<IConnectGroups>();
                var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
                var layer = new ProxyCompositionLayer(commands.Object, connector.Object, systemDiagnostics);

                var exportingGroup = new GroupDefinition("Group1");
                var task = layer.Add(exportingGroup);
                task.Wait();

                var importDefinition = GroupImportDefinition.CreateDefinition(
                    "a",
                    new GroupRegistrationId("b"),
                    null,
                    Enumerable.Empty<ImportRegistrationId>());
                Assert.Throws<UnknownPartGroupException>(() => layer.Connect(new GroupCompositionId(), importDefinition, task.Result));
            }
        }