public void RegisterNotificationWithExistingName()
        {
            var commands          = new Mock <ICommandContainer>();
            var notificationNames = new MockNotificationNameConstants();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var builder           = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As <ICommandContainer>();
                builder.Register(c => notificationNames).As <INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As <SystemDiagnostics>();
            }

            Action <IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);

            Action <INotificationArguments> callback = obj => { };

            service.RegisterNotification(notificationNames.SystemShuttingDown, callback);

            Assert.DoesNotThrow(() => service.RegisterNotification(notificationNames.SystemShuttingDown, obj => { }));
        }
        public void ServicesToConnectTo()
        {
            var commands          = new Mock <ICommandContainer>();
            var notificationNames = new MockNotificationNameConstants();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var builder           = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As <ICommandContainer>();
                builder.Register(c => notificationNames).As <INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As <SystemDiagnostics>();
            }

            Action <IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);

            Assert.That(
                service.ServicesToConnectTo(),
                Is.EquivalentTo(
                    new[]
            {
                typeof(CoreProxy),
                typeof(ProjectService),
            }));
        }
        public void InvokeWithIdAndContextNotFullyFunctional()
        {
            var commands = new Mock <ICommandContainer>();
            {
                commands.Setup(c => c.Invoke(It.IsAny <CommandId>(), It.IsAny <ICommandContext>()))
                .Verifiable();
            }

            var notificationNames = new MockNotificationNameConstants();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var builder           = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As <ICommandContainer>();
                builder.Register(c => notificationNames).As <INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As <SystemDiagnostics>();
            }

            Action <IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);

            Assert.Throws <ArgumentException>(() => service.Invoke(new CommandId("bla"), new Mock <ICommandContext>().Object));
        }
        public void Contains()
        {
            var commands = new Mock <ICommandContainer>();
            {
                commands.Setup(c => c.Contains(It.IsAny <CommandId>()))
                .Returns(false);
            }

            var notificationNames = new MockNotificationNameConstants();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var builder           = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As <ICommandContainer>();
                builder.Register(c => notificationNames).As <INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As <SystemDiagnostics>();
            }

            Action <IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);

            Assert.IsFalse(service.Contains(new CommandId("bla")));
        }
        public void StopWithMultipleNotifications()
        {
            var commands          = new Mock <ICommandContainer>();
            var notificationNames = new MockNotificationNameConstants();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var builder           = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As <ICommandContainer>();
                builder.Register(c => notificationNames).As <INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As <SystemDiagnostics>();
            }

            Action <IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);

            bool wasFirstInvoked = false;

            service.RegisterNotification(notificationNames.SystemShuttingDown, obj => { wasFirstInvoked = true; });

            bool wasSecondInvoked = false;

            service.RegisterNotification(notificationNames.SystemShuttingDown, obj => { wasSecondInvoked = true; });

            var proxy = new CoreProxy(new Mock <IKernel>().Object, systemDiagnostics);

            service.ConnectTo(proxy);

            ITimeline timeline   = new Timeline(BuildStorage);
            var       proxyLayer = new Mock <IProxyCompositionLayer>();
            var       projects   = new ProjectService(
                () => timeline,
                d => new DatasetStorageProxy(
                    d,
                    new GroupSelector(
                        new Mock <IConnectGroups>().Object,
                        proxyLayer.Object),
                    proxyLayer.Object),
                new Mock <IHelpDistributingDatasets>().Object,
                new Mock <ICollectNotifications>().Object,
                systemDiagnostics,
                new Mock <IBuildProjects>().Object);

            service.ConnectTo(projects);

            service.Start();
            Assert.AreEqual(StartupState.Started, service.StartupState);

            service.Stop();
            Assert.AreEqual(StartupState.Stopped, service.StartupState);
            Assert.IsTrue(wasFirstInvoked);
            Assert.IsTrue(wasSecondInvoked);
        }
        public void HandleApplicationStartupCompleteMessage()
        {
            var commands          = new Mock <ICommandContainer>();
            var notificationNames = new MockNotificationNameConstants();

            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);

            bool isStarted = false;
            Action <INotificationArguments> onApplicationStartup = obj => { isStarted = true; };

            var builder = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As <ICommandContainer>();
                builder.Register(c => notificationNames).As <INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As <SystemDiagnostics>();
            }

            Action <IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);

            service.RegisterNotification(notificationNames.StartupComplete, onApplicationStartup);

            var proxy = new CoreProxy(new Mock <IKernel>().Object, systemDiagnostics);

            service.ConnectTo(proxy);

            ITimeline timeline   = new Timeline(BuildStorage);
            var       proxyLayer = new Mock <IProxyCompositionLayer>();
            var       projects   = new ProjectService(
                () => timeline,
                d => new DatasetStorageProxy(
                    d,
                    new GroupSelector(
                        new Mock <IConnectGroups>().Object,
                        proxyLayer.Object),
                    proxyLayer.Object),
                new Mock <IHelpDistributingDatasets>().Object,
                new Mock <ICollectNotifications>().Object,
                systemDiagnostics,
                new Mock <IBuildProjects>().Object);

            service.ConnectTo(projects);

            service.Start();

            proxy.NotifyServicesOfStartupCompletion();
            Assert.IsTrue(isStarted);
        }
        public void InvokeWithIdAndContextFullyFunctional()
        {
            var commands = new Mock <ICommandContainer>();
            {
                commands.Setup(c => c.Invoke(It.IsAny <CommandId>(), It.IsAny <ICommandContext>()))
                .Verifiable();
            }

            var notificationNames = new MockNotificationNameConstants();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var builder           = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As <ICommandContainer>();
                builder.Register(c => notificationNames).As <INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As <SystemDiagnostics>();
            }

            Action <IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);

            var proxy = new CoreProxy(new Mock <IKernel>().Object, systemDiagnostics);

            service.ConnectTo(proxy);

            ITimeline timeline   = new Timeline(BuildStorage);
            var       proxyLayer = new Mock <IProxyCompositionLayer>();
            var       projects   = new ProjectService(
                () => timeline,
                d => new DatasetStorageProxy(
                    d,
                    new GroupSelector(
                        new Mock <IConnectGroups>().Object,
                        proxyLayer.Object),
                    proxyLayer.Object),
                new Mock <IHelpDistributingDatasets>().Object,
                new Mock <ICollectNotifications>().Object,
                systemDiagnostics,
                new Mock <IBuildProjects>().Object);

            service.ConnectTo(projects);
            service.Start();

            service.Invoke(new CommandId("bla"), new Mock <ICommandContext>().Object);
            commands.Verify(c => c.Invoke(It.IsAny <CommandId>(), It.IsAny <ICommandContext>()), Times.Exactly(1));
        }
        public void StopWithMissingAction()
        {
            var commands          = new Mock <ICommandContainer>();
            var notificationNames = new MockNotificationNameConstants();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var builder           = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As <ICommandContainer>();
                builder.Register(c => notificationNames).As <INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As <SystemDiagnostics>();
            }

            Action <IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);

            var proxy = new CoreProxy(new Mock <IKernel>().Object, systemDiagnostics);

            service.ConnectTo(proxy);

            ITimeline timeline   = new Timeline(BuildStorage);
            var       proxyLayer = new Mock <IProxyCompositionLayer>();
            var       projects   = new ProjectService(
                () => timeline,
                d => new DatasetStorageProxy(
                    d,
                    new GroupSelector(
                        new Mock <IConnectGroups>().Object,
                        proxyLayer.Object),
                    proxyLayer.Object),
                new Mock <IHelpDistributingDatasets>().Object,
                new Mock <ICollectNotifications>().Object,
                systemDiagnostics,
                new Mock <IBuildProjects>().Object);

            service.ConnectTo(projects);

            service.Start();
            Assert.AreEqual(StartupState.Started, service.StartupState);

            Assert.Throws <MissingNotificationActionException>(service.Stop);
        }
        public void Create()
        {
            var commandCollection = new List <CommandId>();
            var commands          = new Mock <ICommandContainer>();
            {
                commands.Setup(c => c.Add(It.IsAny <CommandId>(), It.IsAny <Func <ICommand> >()))
                .Callback <CommandId, Func <ICommand> >(
                    (id, command) =>
                {
                    commandCollection.Add(id);
                });
            }

            var notificationNames = new MockNotificationNameConstants();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);

            var builder = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As <ICommandContainer>();
                builder.Register(c => notificationNames).As <INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As <SystemDiagnostics>();
            }

            Action <IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);

            // Check that everything is the right place
            {
                var original = new List <CommandId>
                {
                    ShutdownApplicationCommand.CommandId,
                    CreateProjectCommand.CommandId,
                    LoadProjectCommand.CommandId,
                    UnloadProjectCommand.CommandId,
                };
                Assert.That(commandCollection, Is.EquivalentTo(original));
                Assert.IsNotNull(service);
            }
        }
        public void ConnectTo()
        {
            var commands          = new Mock <ICommandContainer>();
            var notificationNames = new MockNotificationNameConstants();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var builder           = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As <ICommandContainer>();
                builder.Register(c => notificationNames).As <INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As <SystemDiagnostics>();
            }

            Action <IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);

            Assert.IsFalse(service.IsConnectedToAllDependencies);

            var proxy = new CoreProxy(new Mock <IKernel>().Object, systemDiagnostics);

            service.ConnectTo(proxy);

            ITimeline timeline   = new Timeline(BuildStorage);
            var       proxyLayer = new Mock <IProxyCompositionLayer>();
            var       projects   = new ProjectService(
                () => timeline,
                d => new DatasetStorageProxy(
                    d,
                    new GroupSelector(
                        new Mock <IConnectGroups>().Object,
                        proxyLayer.Object),
                    proxyLayer.Object),
                new Mock <IHelpDistributingDatasets>().Object,
                new Mock <ICollectNotifications>().Object,
                systemDiagnostics,
                new Mock <IBuildProjects>().Object);

            service.ConnectTo(projects);
            Assert.IsTrue(service.IsConnectedToAllDependencies);
        }
        public void RegisterNotificationWithNullCallback()
        {
            var commands          = new Mock <ICommandContainer>();
            var notificationNames = new MockNotificationNameConstants();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var builder           = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As <ICommandContainer>();
                builder.Register(c => notificationNames).As <INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As <SystemDiagnostics>();
            }

            Action <IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);

            Assert.Throws <ArgumentNullException>(() => service.RegisterNotification(new NotificationName("bla"), null));
        }
        public void ConnectTo()
        {
            var commands = new Mock<ICommandContainer>();
            var notificationNames = new MockNotificationNameConstants();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var builder = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As<ICommandContainer>();
                builder.Register(c => notificationNames).As<INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As<SystemDiagnostics>();
            }

            Action<IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);
            Assert.IsFalse(service.IsConnectedToAllDependencies);

            var proxy = new CoreProxy(new Mock<IKernel>().Object, systemDiagnostics);
            service.ConnectTo(proxy);

            ITimeline timeline = new Timeline(BuildStorage);
            var proxyLayer = new Mock<IProxyCompositionLayer>();
            var projects = new ProjectService(
                () => timeline,
                d => new DatasetStorageProxy(
                    d,
                    new GroupSelector(
                        new Mock<IConnectGroups>().Object,
                        proxyLayer.Object),
                    proxyLayer.Object),
                new Mock<IHelpDistributingDatasets>().Object,
                new Mock<ICollectNotifications>().Object,
                systemDiagnostics,
                new Mock<IBuildProjects>().Object);
            service.ConnectTo(projects);
            Assert.IsTrue(service.IsConnectedToAllDependencies);
        }
        public void Create()
        {
            var commandCollection = new List<CommandId>();
            var commands = new Mock<ICommandContainer>();
            {
                commands.Setup(c => c.Add(It.IsAny<CommandId>(), It.IsAny<Func<ICommand>>()))
                    .Callback<CommandId, Func<ICommand>>(
                        (id, command) =>
                            {
                                commandCollection.Add(id);
                            });
            }

            var notificationNames = new MockNotificationNameConstants();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);

            var builder = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As<ICommandContainer>();
                builder.Register(c => notificationNames).As<INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As<SystemDiagnostics>();
            }

            Action<IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);

            // Check that everything is the right place
            {
                var original = new List<CommandId>
                    {
                        ShutdownApplicationCommand.CommandId,
                        CreateProjectCommand.CommandId,
                        LoadProjectCommand.CommandId,
                        UnloadProjectCommand.CommandId,
                    };
                Assert.That(commandCollection, Is.EquivalentTo(original));
                Assert.IsNotNull(service);
            }
        }
        public void InvokeWithIdFullyFunctional()
        {
            var commands = new Mock<ICommandContainer>();
            {
                commands.Setup(c => c.Invoke(It.IsAny<CommandId>()))
                    .Verifiable();
            }

            var notificationNames = new MockNotificationNameConstants();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var builder = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As<ICommandContainer>();
                builder.Register(c => notificationNames).As<INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As<SystemDiagnostics>();
            }

            Action<IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);

            var proxy = new CoreProxy(new Mock<IKernel>().Object, systemDiagnostics);
            service.ConnectTo(proxy);

            ITimeline timeline = new Timeline(BuildStorage);
            var proxyLayer = new Mock<IProxyCompositionLayer>();
            var projects = new ProjectService(
                () => timeline,
                d => new DatasetStorageProxy(
                    d,
                    new GroupSelector(
                        new Mock<IConnectGroups>().Object,
                        proxyLayer.Object),
                    proxyLayer.Object),
                new Mock<IHelpDistributingDatasets>().Object,
                new Mock<ICollectNotifications>().Object,
                systemDiagnostics,
                new Mock<IBuildProjects>().Object);
            service.ConnectTo(projects);
            service.Start();

            service.Invoke(new CommandId("bla"));
            commands.Verify(c => c.Invoke(It.IsAny<CommandId>()), Times.Exactly(1));
        }
        public void InvokeWithIdNotFullyFunctional()
        {
            var commands = new Mock<ICommandContainer>();
            {
                commands.Setup(c => c.Invoke(It.IsAny<CommandId>()))
                    .Verifiable();
            }

            var notificationNames = new MockNotificationNameConstants();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var builder = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As<ICommandContainer>();
                builder.Register(c => notificationNames).As<INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As<SystemDiagnostics>();
            }

            Action<IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);

            Assert.Throws<ArgumentException>(() => service.Invoke(new CommandId("bla")));
        }
        public void RegisterNotificationWithExistingName()
        {
            var commands = new Mock<ICommandContainer>();
            var notificationNames = new MockNotificationNameConstants();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var builder = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As<ICommandContainer>();
                builder.Register(c => notificationNames).As<INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As<SystemDiagnostics>();
            }

            Action<IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);

            Action<INotificationArguments> callback = obj => { };
            service.RegisterNotification(notificationNames.SystemShuttingDown, callback);

            Assert.DoesNotThrow(() => service.RegisterNotification(notificationNames.SystemShuttingDown, obj => { }));
        }
        public void RegisterNotificationWithNullName()
        {
            var commands = new Mock<ICommandContainer>();
            var notificationNames = new MockNotificationNameConstants();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var builder = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As<ICommandContainer>();
                builder.Register(c => notificationNames).As<INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As<SystemDiagnostics>();
            }

            Action<IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);

            Assert.Throws<ArgumentNullException>(() => service.RegisterNotification(null, obj => { }));
        }
        public void ServicesToConnectTo()
        {
            var commands = new Mock<ICommandContainer>();
            var notificationNames = new MockNotificationNameConstants();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var builder = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As<ICommandContainer>();
                builder.Register(c => notificationNames).As<INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As<SystemDiagnostics>();
            }

            Action<IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);

            Assert.That(
                service.ServicesToConnectTo(),
                Is.EquivalentTo(
                    new[]
                    {
                        typeof(CoreProxy),
                        typeof(ProjectService),
                    }));
        }
        public void StopWithMissingAction()
        {
            var commands = new Mock<ICommandContainer>();
            var notificationNames = new MockNotificationNameConstants();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var builder = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As<ICommandContainer>();
                builder.Register(c => notificationNames).As<INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As<SystemDiagnostics>();
            }

            Action<IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);

            var proxy = new CoreProxy(new Mock<IKernel>().Object, systemDiagnostics);
            service.ConnectTo(proxy);

            ITimeline timeline = new Timeline(BuildStorage);
            var proxyLayer = new Mock<IProxyCompositionLayer>();
            var projects = new ProjectService(
                () => timeline,
                d => new DatasetStorageProxy(
                    d,
                    new GroupSelector(
                        new Mock<IConnectGroups>().Object,
                        proxyLayer.Object),
                    proxyLayer.Object),
                new Mock<IHelpDistributingDatasets>().Object,
                new Mock<ICollectNotifications>().Object,
                systemDiagnostics,
                new Mock<IBuildProjects>().Object);
            service.ConnectTo(projects);

            service.Start();
            Assert.AreEqual(StartupState.Started, service.StartupState);

            Assert.Throws<MissingNotificationActionException>(service.Stop);
        }
        public void HandleApplicationStartupCompleteMessage()
        {
            var commands = new Mock<ICommandContainer>();
            var notificationNames = new MockNotificationNameConstants();

            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);

            bool isStarted = false;
            Action<INotificationArguments> onApplicationStartup = obj => { isStarted = true; };

            var builder = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As<ICommandContainer>();
                builder.Register(c => notificationNames).As<INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As<SystemDiagnostics>();
            }

            Action<IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);
            service.RegisterNotification(notificationNames.StartupComplete, onApplicationStartup);

            var proxy = new CoreProxy(new Mock<IKernel>().Object, systemDiagnostics);
            service.ConnectTo(proxy);

            ITimeline timeline = new Timeline(BuildStorage);
            var proxyLayer = new Mock<IProxyCompositionLayer>();
            var projects = new ProjectService(
                () => timeline,
                d => new DatasetStorageProxy(
                    d,
                    new GroupSelector(
                        new Mock<IConnectGroups>().Object,
                        proxyLayer.Object),
                    proxyLayer.Object),
                new Mock<IHelpDistributingDatasets>().Object,
                new Mock<ICollectNotifications>().Object,
                systemDiagnostics,
                new Mock<IBuildProjects>().Object);
            service.ConnectTo(projects);

            service.Start();

            proxy.NotifyServicesOfStartupCompletion();
            Assert.IsTrue(isStarted);
        }
        public void Contains()
        {
            var commands = new Mock<ICommandContainer>();
            {
                commands.Setup(c => c.Contains(It.IsAny<CommandId>()))
                    .Returns(false);
            }

            var notificationNames = new MockNotificationNameConstants();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var builder = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As<ICommandContainer>();
                builder.Register(c => notificationNames).As<INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As<SystemDiagnostics>();
            }

            Action<IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);

            Assert.IsFalse(service.Contains(new CommandId("bla")));
        }
        public void StopWithMultipleNotifications()
        {
            var commands = new Mock<ICommandContainer>();
            var notificationNames = new MockNotificationNameConstants();
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var builder = new ContainerBuilder();
            {
                builder.Register(c => commands.Object).As<ICommandContainer>();
                builder.Register(c => notificationNames).As<INotificationNameConstants>();
                builder.Register(c => systemDiagnostics).As<SystemDiagnostics>();
            }

            Action<IContainer> onStartService = c => { };

            var service = new UserInterfaceService(
                builder.Build(),
                onStartService,
                systemDiagnostics);

            bool wasFirstInvoked = false;
            service.RegisterNotification(notificationNames.SystemShuttingDown, obj => { wasFirstInvoked = true; });

            bool wasSecondInvoked = false;
            service.RegisterNotification(notificationNames.SystemShuttingDown, obj => { wasSecondInvoked = true; });

            var proxy = new CoreProxy(new Mock<IKernel>().Object, systemDiagnostics);
            service.ConnectTo(proxy);

            ITimeline timeline = new Timeline(BuildStorage);
            var proxyLayer = new Mock<IProxyCompositionLayer>();
            var projects = new ProjectService(
                () => timeline,
                d => new DatasetStorageProxy(
                    d,
                    new GroupSelector(
                        new Mock<IConnectGroups>().Object,
                        proxyLayer.Object),
                    proxyLayer.Object),
                new Mock<IHelpDistributingDatasets>().Object,
                new Mock<ICollectNotifications>().Object,
                systemDiagnostics,
                new Mock<IBuildProjects>().Object);
            service.ConnectTo(projects);

            service.Start();
            Assert.AreEqual(StartupState.Started, service.StartupState);

            service.Stop();
            Assert.AreEqual(StartupState.Stopped, service.StartupState);
            Assert.IsTrue(wasFirstInvoked);
            Assert.IsTrue(wasSecondInvoked);
        }