public void Initialize()
        {
            var context = new Mock<IContextAware>();
            Func<string, IDisposable> disposeFunc = s => new MockDisposable();

            var view = new Mock<IScriptView>();
            {
                view.SetupProperty(v => v.Model);
            }

            var syntaxVerifier = new Mock<ISyntaxVerifier>();
            var scriptHost = new Mock<IHostScripts>();
            {
                scriptHost.Setup(s => s.VerifySyntax(It.IsAny<ScriptLanguage>()))
                    .Returns(syntaxVerifier.Object);
            }

            var parameter = new ScriptParameter(context.Object);
            var container = new Mock<IDependencyInjectionProxy>();
            {
                container.Setup(c => c.Resolve<IContextAware>())
                    .Returns(context.Object);
                container.Setup(c => c.Resolve<IHostScripts>())
                    .Returns(scriptHost.Object);
                container.Setup(c => c.Resolve<RunScriptCommand>())
                    .Returns(new RunScriptCommand(scriptHost.Object));
                container.Setup(c => c.Resolve<CancelScriptRunCommand>())
                    .Returns(new CancelScriptRunCommand(scriptHost.Object, disposeFunc));
                container.Setup(c => c.Resolve<CloseScriptCommand>())
                    .Returns(new CloseScriptCommand(scriptHost.Object, disposeFunc));
                container.Setup(c => c.Resolve<CloseViewCommand>(It.IsAny<Autofac.Core.Parameter[]>()))
                    .Returns(new CloseViewCommand(new Mock<IEventAggregator>().Object, "a", new ScriptParameter(context.Object)));
                container.Setup(c => c.Resolve<NewScriptCommand>(It.IsAny<Autofac.Core.Parameter[]>()))
                    .Returns(
                        new NewScriptCommand(
                            scriptHost.Object,
                            () => new Tuple<bool, ScriptDescriptionModel>(false, null),
                            (m, s) => { },
                            disposeFunc));
                container.Setup(c => c.Resolve<ISyntaxVerifier>())
                    .Returns(syntaxVerifier.Object);
                container.Setup(c => c.Resolve<OpenScriptCommand>(It.IsAny<Autofac.Core.Parameter[]>()))
                    .Returns(
                        new OpenScriptCommand(
                            scriptHost.Object,
                            () => new Tuple<FileInfo, ScriptDescriptionModel>(null, null),
                            (s, f, v) => { },
                            disposeFunc));
            }

            var presenter = new ScriptPresenter(container.Object);
            ((IPresenter)presenter).Initialize(view.Object, parameter);

            Assert.AreSame(view.Object, presenter.View);
            Assert.AreSame(parameter, presenter.Parameter);
            view.VerifySet(v => v.Model = It.IsAny<ScriptModel>(), Times.Once());
        }
Beispiel #2
0
        /// <summary>
        /// System.Windows.Application.Startup イベントを発生させます。
        /// </summary>
        /// <param name="e">イベント データを格納している System.Windows.StartupEventArgsです。</param>
        protected override async void OnStartup(StartupEventArgs e)
        {
            string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            ProfileOptimization.SetProfileRoot(path);
            ProfileOptimization.StartProfile("Naya.profile");

            if (!Environment.Is64BitOperatingSystem || !Environment.Is64BitProcess)
            {
                MessageBox.Show("Not Support 32BitOS.");
                Environment.Exit(-1);
            }

            AppDomain.CurrentDomain.UnhandledException +=
                new UnhandledExceptionEventHandler(this.CurrentDomain_UnhandledException);

            // Setup PluginPresenter.
            {
                PluginPresenter pluginPresenter = new PluginPresenter();
                string pluginPath = Path.Combine(path, "Plugins");
                pluginPresenter.Setup(pluginPath);

                this.presenter.AddPluginPresenter(pluginPresenter);
            }

            // Setup LogPresenter
            {
                OutputLogFactory factory = new OutputLogFactory();
                LogPresenter logPresenter = new LogPresenter(factory);
                this.presenter.AddLogPresenter(logPresenter);
            }

            // Setup OperationPresenter
            {
                OperationPresenter operationPresenter = new OperationPresenter();
                this.presenter.AddOperationPresenter(operationPresenter);
            }

            // Setup MenuPresenter
            {
                MenuPresenter menuPresenter = new MenuPresenter();
                this.presenter.AddMenuPresenter(menuPresenter);
            }

            // Setup PanelPresenter
            {
                PanelPresenter panelPresenter = new PanelPresenter();
                this.presenter.AddPanelPresenter(panelPresenter);
            }

            // Setup RepositoryPresenter
            {
                RepositoryPresenter repositoryPresenter = new RepositoryPresenter();
                this.presenter.AddRepositoryPresenter(repositoryPresenter);
            }

            // Setup ScriptPresenter
            {
                PythonScriptBridge scriptBridge = new PythonScriptBridge("Naya");
                ScriptPresenter scriptPresenter = new ScriptPresenter(scriptBridge);
                this.presenter.AddScriptPresenter(scriptPresenter);
            }

            MainWindow window = new MainWindow();
            MainViewModel viewModel = new MainViewModel();

            GlobalPresenter.SetOwner(window);

            window.DataContext = viewModel;
            window.Show();

            window.IsEnabled = false;
            await NayaPresenter.Initialize();

            if (LayoutHelper.HasAvalonDockConfigFile())
            {
                window.LoadLayout();
            }
            else
            {
                GlobalPresenter.MakeDefaultTools();
            }

            window.IsEnabled = true;
        }