Exemplo n.º 1
0
        public void TestNormal()
        {
            var requirements  = RequirementsTest.CreateTestRequirements();
            var selectionsOld = SelectionsTest.CreateTestSelections();
            var selectionsNew = SelectionsTest.CreateTestSelections();

            selectionsNew.Implementations[1].Version = new ImplementationVersion("2.0");
            selectionsNew.Implementations.Add(new ImplementationSelection {
                InterfaceUri = FeedTest.Sub3Uri, ID = "id3", Version = new ImplementationVersion("0.1")
            });

            GetMock <ISolver>().SetupSequence(x => x.Solve(requirements))
            .Returns(selectionsOld)
            .Returns(selectionsNew);

            // Download uncached implementations
            ExpectFetchUncached(selectionsNew,
                                new Implementation {
                ID = "id1"
            },
                                new Implementation {
                ID = "id2"
            },
                                new Implementation {
                ID = "id3"
            });

            // Check for <replaced-by>
            GetMock <IFeedCache>().Setup(x => x.GetFeed(FeedTest.Test1Uri)).Returns(FeedTest.CreateTestFeed());

            RunAndAssert("http://0install.de/feeds/test/test2.xml: 1.0 -> 2.0" + Environment.NewLine + "http://0install.de/feeds/test/sub3.xml: new -> 0.1" + Environment.NewLine, 0, selectionsNew,
                         "http://0install.de/feeds/test/test1.xml", "--command=command", "--os=Windows", "--cpu=i586", "--not-before=1.0", "--before=2.0", "--version-for=http://0install.de/feeds/test/test2.xml", "2.0..!3.0");
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public override void TestImportSelections()
        {
            var testFeed1 = FeedTest.CreateTestFeed();

            testFeed1.Uri  = FeedTest.Sub1Uri;
            testFeed1.Name = "Sub 1";
            FeedCacheMock.Setup(x => x.GetFeed(FeedTest.Sub1Uri)).Returns(testFeed1);
            var testImplementation1 = (Implementation)testFeed1.Elements[0];

            var testImplementation2 = new Implementation {
                ID = "id2", ManifestDigest = new ManifestDigest(sha256: "abc"), Version = new ImplementationVersion("1.0")
            };
            var testFeed2 = new Feed
            {
                Uri      = FeedTest.Sub2Uri,
                Name     = "Sub 2",
                Elements = { testImplementation2 }
            };

            FeedCacheMock.Setup(x => x.GetFeed(FeedTest.Sub2Uri)).Returns(testFeed2);

            var selections = SelectionsTest.CreateTestSelections();

            // Download uncached implementations
            StoreMock.Setup(x => x.Contains(It.IsAny <ManifestDigest>())).Returns(false);
            FetcherMock.Setup(x => x.Fetch(new[] { testImplementation1, testImplementation2 }));

            using (var tempFile = new TemporaryFile("0install-unit-tests"))
            {
                selections.SaveXml(tempFile);
                RunAndAssert(Resources.AllComponentsDownloaded, 0, selections, tempFile);
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
    public void ExceptionMissingEnvironmentBindingName()
    {
        var selections = SelectionsTest.CreateTestSelections();

        selections.Implementations[1].Commands[0].Bindings.Add(new EnvironmentBinding());
        ExpectCommandException(selections);
    }
Exemplo n.º 7
0
    public void ExceptionMissingExecutableInPathBindingName()
    {
        var selections = SelectionsTest.CreateTestSelections();

        selections.Implementations[1].Commands[0].Bindings.Add(new ExecutableInPath());
        ExpectCommandException(selections);
    }
Exemplo n.º 8
0
        public override void TestNormal()
        {
            var requirements = RequirementsTest.CreateTestRequirements();
            var selections   = SelectionsTest.CreateTestSelections();

            var testFeed1 = FeedTest.CreateTestFeed();

            testFeed1.Uri  = FeedTest.Sub1Uri;
            testFeed1.Name = "Sub 1";
            var testImplementation1 = testFeed1[selections.Implementations[0].ID];

            FeedCacheMock.Setup(x => x.GetFeed(FeedTest.Sub1Uri)).Returns(testFeed1);

            var testImplementation2 = new Implementation {
                ID = "id2", ManifestDigest = new ManifestDigest(sha256: "abc"), Version = new ImplementationVersion("1.0")
            };
            var testFeed2 = new Feed
            {
                Uri      = FeedTest.Sub2Uri,
                Name     = "Sub 2",
                Elements = { testImplementation2 }
            };

            FeedCacheMock.Setup(x => x.GetFeed(FeedTest.Sub2Uri)).Returns(testFeed2);

            SolverMock.Setup(x => x.Solve(requirements)).Returns(selections);

            // Download uncached implementations
            StoreMock.Setup(x => x.Contains(It.IsAny <ManifestDigest>())).Returns(false);
            FetcherMock.Setup(x => x.Fetch(new[] { testImplementation1, testImplementation2 }));

            RunAndAssert(Resources.AllComponentsDownloaded, 0, selections,
                         "http://0install.de/feeds/test/test1.xml", "--command=command", "--os=Windows", "--cpu=i586", "--not-before=1.0", "--before=2.0", "--version-for=http://0install.de/feeds/test/test2.xml", "2.0..!3.0");
        }
Exemplo n.º 9
0
    public void ExceptionMultipleWorkingDirs()
    {
        var selections = SelectionsTest.CreateTestSelections();

        selections.Implementations[1].Commands[0].WorkingDir = new WorkingDir();
        ExpectCommandException(selections);
    }
Exemplo n.º 10
0
    public void ExceptionConflictingEnvironmentInsertAndValue()
    {
        var selections = SelectionsTest.CreateTestSelections();

        selections.Implementations[1].Commands[0].Bindings.Add(new EnvironmentBinding {
            Name = "test", Insert = "test1", Value = "test2"
        });
        ExpectCommandException(selections);
    }
Exemplo n.º 11
0
        public override void SetUp()
        {
            base.SetUp();

            _destination = new TemporaryDirectory("0install-unit-test");
            var selections = SelectionsTest.CreateTestSelections();

            _target = new Exporter(selections, new Architecture(), _destination);
        }
Exemplo n.º 12
0
        public virtual void TestNormal()
        {
            var requirements = RequirementsTest.CreateTestRequirements();
            var selections   = SelectionsTest.CreateTestSelections();

            SolverMock.Setup(x => x.Solve(requirements)).Returns(selections);
            RunAndAssert(selections.ToXmlString(), 0, selections,
                         "--xml", "http://0install.de/feeds/test/test1.xml", "--command=command", "--os=Windows", "--cpu=i586", "--not-before=1.0", "--before=2.0", "--version-for=http://0install.de/feeds/test/test2.xml", "2.0..!3.0");
        }
Exemplo n.º 13
0
        public void TestRejectImportSelections()
        {
            var selections = SelectionsTest.CreateTestSelections();

            using (var tempFile = new TemporaryFile("0install-unit-tests"))
            {
                selections.SaveXml(tempFile);
                Target.Parse(new string[] { tempFile });
                Target.Invoking(x => x.Execute()).ShouldThrow <NotSupportedException>();
            }
        }
Exemplo n.º 14
0
        public override void TestImportSelections()
        {
            var selections = SelectionsTest.CreateTestSelections();

            using (var tempFile = new TemporaryFile("0install-unit-tests"))
            {
                selections.SaveXml(tempFile);
                Target.Parse(new string[] { tempFile });
                Assert.Throws <NotSupportedException>(() => Target.Execute());
            }
        }
Exemplo n.º 15
0
    public async Task Select()
    {
        var selections = SelectionsTest.CreateTestSelections();

        _launcherMock.Setup(x => x.RunAndCapture(null, "select", "--batch", "--xml", FeedTest.Test1Uri.ToStringRfc()))
        .Returns(selections.ToXmlString());

        var result = await _client.SelectAsync(FeedTest.Test1Uri);

        result.Should().Be(selections);
    }
Exemplo n.º 16
0
    public async Task Download()
    {
        var selections = SelectionsTest.CreateTestSelections();

        _launcherMock.Setup(x => x.RunAndCapture(null, "download", "--batch", "--refresh", FeedTest.Test1Uri.ToStringRfc(), "--xml"))
        .Returns(selections.ToXmlString());

        var result = await _client.DownloadAsync(FeedTest.Test1Uri, refresh : true);

        result.Should().Be(selections);
    }
    public void GetUncachedSelections()
    {
        var selections = SelectionsTest.CreateTestSelections();

        _storeMock.Setup(x => x.Contains(selections.Implementations[0].ManifestDigest)).Returns(false);
        _storeMock.Setup(x => x.Contains(selections.Implementations[1].ManifestDigest)).Returns(true);

        var implementationSelections = _selectionsManager.GetUncachedSelections(selections);

        implementationSelections.Should().BeEquivalentTo(new[] { selections.Implementations[0] }, because: "Only the first implementation should be listed as uncached");
    }
Exemplo n.º 18
0
        public virtual void TestImportSelections()
        {
            var selections = SelectionsTest.CreateTestSelections();

            using (var tempFile = new TemporaryFile("0install-unit-tests"))
            {
                selections.SaveXml(tempFile);
                RunAndAssert(selections.ToXmlString(), 0, selections,
                             "--xml", tempFile);
            }
        }
Exemplo n.º 19
0
        public void TestGetUncachedSelections()
        {
            var selections = SelectionsTest.CreateTestSelections();

            _storeMock.Setup(x => x.Contains(selections.Implementations[0].ManifestDigest)).Returns(false);
            _storeMock.Setup(x => x.Contains(selections.Implementations[1].ManifestDigest)).Returns(true);

            var implementationSelections = Target.GetUncachedSelections(selections);

            // Only the first implementation should be listed as uncached
            CollectionAssert.AreEquivalent(new[] { selections.Implementations[0] }, implementationSelections);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Configures the <see cref="ISolver"/> mock to expect a call with <see cref="RequirementsTest.CreateTestRequirements"/>.
        /// </summary>
        /// <returns>The selections returned by the mock; <see cref="SelectionsTest.CreateTestSelections"/>.</returns>
        protected Selections ExpectSolve()
        {
            var requirements = RequirementsTest.CreateTestRequirements();
            var selections   = SelectionsTest.CreateTestSelections();

            GetMock <ISolver>().Setup(x => x.Solve(requirements)).Returns(selections);

            var feed = FeedTest.CreateTestFeed();

            GetMock <IFeedCache>().Setup(x => x.GetFeed(FeedTest.Test1Uri)).Returns(feed);

            selections.Name = feed.Name;
            return(selections);
        }
Exemplo n.º 21
0
        public override void TestNormal()
        {
            var requirements  = RequirementsTest.CreateTestRequirements();
            var selectionsOld = SelectionsTest.CreateTestSelections();
            var selectionsNew = SelectionsTest.CreateTestSelections();

            selectionsNew.Implementations[1].Version = new ImplementationVersion("2.0");
            selectionsNew.Implementations.Add(new ImplementationSelection {
                InterfaceUri = FeedTest.Sub3Uri, ID = "id3", Version = new ImplementationVersion("0.1")
            });

            SolverMock.SetupSequence(x => x.Solve(requirements)).Returns(selectionsOld).Returns(selectionsNew);

            var impl1 = new Implementation {
                ID = "id1"
            };
            var impl2 = new Implementation {
                ID = "id2"
            };
            var impl3 = new Implementation {
                ID = "id3"
            };

            FeedCacheMock.Setup(x => x.GetFeed(FeedTest.Sub1Uri)).Returns(new Feed {
                Uri = FeedTest.Sub1Uri, Elements = { impl1 }
            });
            FeedCacheMock.Setup(x => x.GetFeed(FeedTest.Sub2Uri)).Returns(new Feed {
                Uri = FeedTest.Sub2Uri, Elements = { impl2 }
            });
            FeedCacheMock.Setup(x => x.GetFeed(FeedTest.Sub3Uri)).Returns(new Feed {
                Uri = FeedTest.Sub3Uri, Elements = { impl3 }
            });

            // Download uncached implementations
            StoreMock.Setup(x => x.Contains(It.IsAny <ManifestDigest>())).Returns(false);
            FetcherMock.Setup(x => x.Fetch(new[] { impl1, impl2, impl3 }.IsEquivalent()));

            // Check for <replaced-by>
            FeedCacheMock.Setup(x => x.GetFeed(FeedTest.Test1Uri)).Returns(FeedTest.CreateTestFeed());

            RunAndAssert("http://0install.de/feeds/test/test2.xml: 1.0 -> 2.0" + Environment.NewLine + "http://0install.de/feeds/test/sub3.xml: new -> 0.1", 0, selectionsNew,
                         "http://0install.de/feeds/test/test1.xml", "--command=command", "--os=Windows", "--cpu=i586", "--not-before=1.0", "--before=2.0", "--version-for=http://0install.de/feeds/test/test2.xml", "2.0..!3.0");
        }
Exemplo n.º 22
0
        public void TestImportSelections()
        {
            var selections = SelectionsTest.CreateTestSelections();

            ExpectFetchUncached(selections,
                                new Implementation {
                ID = "id1", ManifestDigest = new ManifestDigest(sha256: "abc"), Version = new ImplementationVersion("1.0")
            },
                                new Implementation {
                ID = "id2", ManifestDigest = new ManifestDigest(sha256: "xyz"), Version = new ImplementationVersion("1.0")
            });

            using (var tempFile = new TemporaryFile("0install-unit-tests"))
            {
                selections.SaveXml(tempFile);

                selections.Normalize();
                RunAndAssert(Resources.AllComponentsDownloaded, 0, selections, tempFile);
            }
        }
Exemplo n.º 23
0
    public void ExceptionMultipleInvalidBindings()
    {
        var selections = SelectionsTest.CreateTestSelections();

        selections.Implementations[1].Commands[0].Bindings.Add(new EnvironmentBinding()); // Missing name
        ExpectCommandException(selections);

        selections = SelectionsTest.CreateTestSelections();
        selections.Implementations[1].Commands[0].Bindings.Add(new EnvironmentBinding {
            Name = "test", Insert = "test1", Value = "test2"
        });                                                                                                                                // Conflicting insert and value
        ExpectCommandException(selections);

        selections = SelectionsTest.CreateTestSelections();
        selections.Implementations[1].Commands[0].Bindings.Add(new ExecutableInVar()); // Missing name
        ExpectCommandException(selections);

        selections = SelectionsTest.CreateTestSelections();
        selections.Implementations[1].Commands[0].Bindings.Add(new ExecutableInPath()); // Missing name
        ExpectCommandException(selections);
    }
Exemplo n.º 24
0
        public void TestImportSelections()
        {
            var selections = SelectionsTest.CreateTestSelections();

            ExpectFetchUncached(selections,
                                new Implementation {
                ID = "id1", ManifestDigest = new ManifestDigest(sha256: "abc"), Version = new ImplementationVersion("1.0")
            },
                                new Implementation {
                ID = "id2", ManifestDigest = new ManifestDigest(sha256: "xyz"), Version = new ImplementationVersion("1.0")
            });

            ExecutorMock.Setup(x => x.Start(It.IsAny <Selections>(), "--arg1", "--arg2")).Returns <Process>(null);
            using (var tempFile = new TemporaryFile("0install-unit-tests"))
            {
                selections.SaveXml(tempFile);

                selections.Normalize();
                RunAndAssert(null, 0, selections, tempFile, "--arg1", "--arg2");
            }
        }
Exemplo n.º 25
0
        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);
        }