예제 #1
0
        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));
            }
        }
예제 #2
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 RemoveWhileConnected()
        {
            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.Remove(It.IsAny<GroupCompositionId>()))
                        .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));

                var removeTask = layer.Remove(exportingId);
                removeTask.Wait();

                Assert.IsTrue(layer.Contains(importingId));
                Assert.IsFalse(layer.Contains(exportingId));
                Assert.IsFalse(layer.IsConnected(importingId, importDefinition));
                Assert.IsFalse(layer.IsConnected(importingId, importDefinition, exportingId));
                Assert.IsNull(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));
            }
        }
예제 #6
0
        public void DisconnectFromAll()
        {
            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()));

                    commands.Setup(c => c.Disconnect(It.IsAny <GroupCompositionId>()))
                    .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));

                var disconnectTask = layer.Disconnect(importingId);
                disconnectTask.Wait();

                Assert.IsTrue(layer.Contains(importingId));
                Assert.IsTrue(layer.Contains(exportingId));
                Assert.IsFalse(layer.IsConnected(importingId, importDefinition));
                Assert.IsFalse(layer.IsConnected(importingId, importDefinition, exportingId));
                Assert.IsNull(layer.ConnectedTo(importingId, importDefinition));
            }
        }