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 async void SimulationHandlesErrors()
        {
            var coreLink = new DummyCoreLink {
                Fail = true
            };

            var coreController = new CoreController(coreLink);

            var coreProxy = new CoreProxy(coreController, m_modelUpdater);

            Assert.Equal(CoreState.Disconnected, coreProxy.State);

            coreProxy.State = CoreState.Empty;

            await Assert.ThrowsAsync <RemoteCoreException>(() => coreProxy.LoadBlueprintAsync("{}"));
        }
        public void RefreshesState()
        {
            const int timeoutMs = 150;

            var waitEvent = new AutoResetEvent(false);

            var coreControllerMock = new Mock <ICoreController>();

            coreControllerMock.Setup(controller => controller.StartStateChecking(It.IsAny <Action <KeepaliveResult> >()))
            .Callback(() => waitEvent.Set());
            var coreController = coreControllerMock.Object;

            var coreProxy = new CoreProxy(coreController, m_modelUpdater);

            Assert.True(waitEvent.WaitOne(timeoutMs));
        }
Exemple #6
0
        /// <summary>
        /// Provides one of the services on which the current service depends.
        /// </summary>
        /// <param name="dependency">The dependency service.</param>
        public override void ConnectTo(KernelService dependency)
        {
            var core = dependency as CoreProxy;

            if (core != null)
            {
                m_Core = core;
                m_Core.OnStartupComplete += OnStartupComplete;
            }

            var projects = dependency as ProjectService;

            if (projects != null)
            {
                m_Projects = projects;
            }
        }
        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 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 async void StateMachineTransitionsCorrectly()
        {
            // TODO(HonzaS): Rewrite this test to take advantage of the control methods being async.
            ICoreLink coreLink = new DummyCoreLink();

            var coreController = new CoreController(coreLink, keepaliveIntervalMs: 20);

            var coreProxy = new CoreProxy(coreController, m_modelUpdater);

            Assert.Equal(CoreState.Disconnected, coreProxy.State);

            // Simulate the core sending first state information.
            coreProxy.State = CoreState.Empty;

            await coreProxy.LoadBlueprintAsync("{}");

            Assert.Equal(CoreState.Paused, coreProxy.State);

            await coreProxy.RunAsync();

            Assert.Equal(CoreState.Running, coreProxy.State);

            await coreProxy.PauseAsync();

            Assert.Equal(CoreState.Paused, coreProxy.State);

            await coreProxy.ClearAsync();

            Assert.Equal(CoreState.Empty, coreProxy.State);

            // Test direct Clear from a Running state.
            await coreProxy.LoadBlueprintAsync("{}");

            await coreProxy.RunAsync();

            await coreProxy.ClearAsync();

            await coreProxy.ShutdownAsync();

            Assert.Equal(CoreState.ShuttingDown, coreProxy.State);
        }
        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);
        }
        /// <summary>
        /// Provides one of the services on which the current service depends.
        /// </summary>
        /// <param name="dependency">The dependency service.</param>
        public override void ConnectTo(KernelService dependency)
        {
            var core = dependency as CoreProxy;
            if (core != null)
            {
                m_Core = core;
                m_Core.OnStartupComplete += OnStartupComplete;
            }

            var projects = dependency as ProjectService;
            if (projects != null)
            {
                m_Projects = projects;
            }
        }
        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 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 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 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);
        }