public void TestExceptions()
 {
     var executor = new Executor(new Mock<IStore>(MockBehavior.Loose).Object);
     executor.Invoking(x => x.Start(new Selections {Command = Command.NameRun}))
         .ShouldThrow<ExecutorException>(because: "Selections with no implementations should be rejected");
     executor.Invoking(x => x.Start(new Selections {Implementations = {new ImplementationSelection()}}))
         .ShouldThrow<ExecutorException>(because: "Selections with no start command should be rejected");
 }
 private static void ExpectCommandException(Selections selections)
 {
     var storeMock = new Mock<IStore>(MockBehavior.Loose);
     storeMock.Setup(x => x.GetPath(It.IsAny<ManifestDigest>())).Returns("test path");
     var executor = new Executor(storeMock.Object);
     executor.Invoking(x => x.GetStartInfo(selections))
         .ShouldThrow<ExecutorException>(because: "Invalid Selections should be rejected");
 }
        public void TestGetStartInfoForEachArgs()
        {
            var selections = SelectionsTest.CreateTestSelections();
            selections.Implementations.Insert(0, new ImplementationSelection {InterfaceUri = new FeedUri("http://0install.de/feeds/test/dummy.xml")}); // Should be ignored by Executor

            selections.Implementations[1].Commands[0].Arguments.Add(new ForEachArgs
            {
                ItemFrom = "SPLIT_ARG",
                Arguments = {"pre1 $item post1", "pre2 $item post2"}
            });
            selections.Implementations[2].Bindings.Add(new EnvironmentBinding {Name = "SPLIT_ARG", Value = "split1" + Path.PathSeparator + "split2"});

            var executor = new Executor(GetMockStore(selections));
            var startInfo = executor.GetStartInfo(selections);
            startInfo.FileName.Should().Be(
                Path.Combine(Test2Path, FileUtils.UnifySlashes(selections.Implementations[2].Commands[0].Path)),
                because: "Should combine runner implementation directory with runner command path");
            startInfo.Arguments.Should().Be(
                new[]
                {
                    selections.Implementations[2].Commands[0].Arguments[0].ToString(),
                    selections.Implementations[1].Commands[0].Runner.Arguments[0].ToString(),
                    Path.Combine(Test1Path, FileUtils.UnifySlashes(selections.Implementations[1].Commands[0].Path)),
                    selections.Implementations[1].Commands[0].Arguments[0].ToString(),
                    "pre1 split1 post1", "pre2 split1 post2", "pre1 split2 post1", "pre2 split2 post2"
                }.JoinEscapeArguments(),
                because: "Should combine core and additional runner arguments with application implementation directory and command path");

            VerifyEnvironment(startInfo, selections);
        }
        public void TestGetStartInfoPathlessCommand()
        {
            var selections = SelectionsTest.CreateTestSelections();
            selections.Implementations.Insert(0, new ImplementationSelection {InterfaceUri = new FeedUri("http://0install.de/feeds/test/dummy.xml")}); // Should be ignored by Executor
            selections.Implementations[1].Commands[0].Path = null;

            var executor = new Executor(GetMockStore(selections));
            var startInfo = executor.GetStartInfo(selections, "--custom");
            startInfo.FileName.Should().Be(
                Path.Combine(Test2Path, FileUtils.UnifySlashes(selections.Implementations[2].Commands[0].Path)));
            startInfo.Arguments.Should().Be(
                new[]
                {
                    selections.Implementations[2].Commands[0].Arguments[0].ToString(),
                    selections.Implementations[1].Commands[0].Runner.Arguments[0].ToString(),
                    selections.Implementations[1].Commands[0].Arguments[0].ToString(),
                    "--custom"
                }.JoinEscapeArguments());

            VerifyEnvironment(startInfo, selections);
        }
        public void TestGetStartInfoMainAbsolute()
        {
            var selections = SelectionsTest.CreateTestSelections();
            selections.Implementations.Insert(0, new ImplementationSelection {InterfaceUri = new FeedUri("http://0install.de/feeds/test/dummy.xml")}); // Should be ignored by Executor

            var executor = new Executor(GetMockStore(selections)) {Main = "/main"};
            var startInfo = executor.GetStartInfo(selections, "--custom");
            startInfo.FileName.Should().Be(
                Path.Combine(Test2Path, FileUtils.UnifySlashes(selections.Implementations[2].Commands[0].Path)),
                because: "Should combine runner implementation directory with runner command path");
            startInfo.Arguments.Should().Be(
                new[]
                {
                    selections.Implementations[2].Commands[0].Arguments[0].ToString(),
                    selections.Implementations[1].Commands[0].Runner.Arguments[0].ToString(),
                    Path.Combine(Test1Path, "main"),
                    "--custom"
                }.JoinEscapeArguments(),
                because: "Should combine core and additional runner arguments with application implementation directory and main binary override");

            VerifyEnvironment(startInfo, selections);
        }
        public void TestGetStartInfoWrapper()
        {
            if (!WindowsUtils.IsWindows) Assert.Ignore("Wrapper command-line parsing relies on a Win32 API and therefore will not work on non-Windows platforms");

            var selections = SelectionsTest.CreateTestSelections();
            selections.Implementations.Insert(0, new ImplementationSelection {InterfaceUri = new FeedUri("http://0install.de/feeds/test/dummy.xml")}); // Should be ignored by Executor

            var executor = new Executor(GetMockStore(selections)) {Wrapper = "wrapper --wrapper"};
            var startInfo = executor.GetStartInfo(selections, "--custom");
            startInfo.FileName.Should().Be("wrapper");
            startInfo.Arguments.Should().Be(
                new[]
                {
                    "--wrapper",
                    Path.Combine(Test2Path, FileUtils.UnifySlashes(selections.Implementations[2].Commands[0].Path)),
                    selections.Implementations[2].Commands[0].Arguments[0].ToString(),
                    selections.Implementations[1].Commands[0].Runner.Arguments[0].ToString(),
                    Path.Combine(Test1Path, FileUtils.UnifySlashes(selections.Implementations[1].Commands[0].Path)),
                    selections.Implementations[1].Commands[0].Arguments[0].ToString(),
                    "--custom"
                }.JoinEscapeArguments(),
                because: "Should combine wrapper arguments, runner and application");

            VerifyEnvironment(startInfo, selections);
        }