Ejemplo n.º 1
0
    /// <inheritdoc/>
    public ExternalImplementation?Lookup(ImplementationSelection selection)
    {
        #region Sanity checks
        if (selection == null)
        {
            throw new ArgumentNullException(nameof(selection));
        }
        #endregion

        try
        {
            var referenceImpl = ExternalImplementation.FromID(selection.ID);

            // Reference implementation from ID does not contain all required information.
            // Therefore, find the original implementation.
            var implementation = GetImplementations(referenceImpl.Package)
                                 .FirstOrDefault(x => x.Version == referenceImpl.Version &&
                                                 x.Architecture == referenceImpl.Architecture);

            if (implementation != null)
            {
                CopyValues(from: selection, to: implementation);
            }

            return(implementation);
        }
        catch (FormatException)
        {
            return(null);
        }
    }
Ejemplo n.º 2
0
    /// <inheritdoc/>
    public ExternalImplementation Lookup(ImplementationSelection selection)
    {
        #region Sanity checks
        if (selection == null)
        {
            throw new ArgumentNullException(nameof(selection));
        }
        #endregion

        try
        {
            var referenceImpl = ExternalImplementation.FromID(selection.ID);

            // Reference implementation from ID does not contain all required information.
            // Therefore, find the original implementation.
            var implementation = GetImplementations(referenceImpl.Package)
                                 .First(x => x.Version == referenceImpl.Version &&
                                        x.Architecture == referenceImpl.Architecture);

            CopyValues(from: selection, to: implementation);
            return(implementation);
        }
        #region Error handling
        catch (FormatException)
        {
            throw new ImplementationNotFoundException(string.Format(Resources.UnknownPackageID, selection.ID, DistributionName));
        }
        catch (InvalidOperationException)
        {
            throw new ImplementationNotFoundException(string.Format(Resources.UnknownPackageID, selection.ID, DistributionName));
        }
        #endregion
    }
Ejemplo n.º 3
0
        public void TestGetUncachedSelectionsPackageManager()
        {
            using (var tempFile = new TemporaryFile("0install-unit-tests"))
            {
                var impl1 = new ExternalImplementation("RPM", "firefox", new ImplementationVersion("1.0"))
                {
                    IsInstalled = false
                };
                var impl2 = new ExternalImplementation("RPM", "thunderbird", new ImplementationVersion("1.0"))
                {
                    IsInstalled = true
                };
                var impl3 = new ExternalImplementation("RPM", "vlc", new ImplementationVersion("1.0"))
                {
                    IsInstalled = true, QuickTestFile = tempFile
                };

                var selections = new Selections
                {
                    InterfaceUri    = FeedTest.Test1Uri,
                    Command         = Command.NameRun,
                    Implementations =
                    {
                        new ImplementationSelection {
                            InterfaceUri = FeedTest.Test1Uri, FromFeed = new FeedUri(FeedUri.FromDistributionPrefix + FeedTest.Test1Uri), ID = impl1.ID, QuickTestFile = impl1.QuickTestFile
                        },
                        new ImplementationSelection {
                            InterfaceUri = FeedTest.Test1Uri, FromFeed = new FeedUri(FeedUri.FromDistributionPrefix + FeedTest.Test1Uri), ID = impl2.ID, QuickTestFile = impl2.QuickTestFile
                        },
                        new ImplementationSelection {
                            InterfaceUri = FeedTest.Test1Uri, FromFeed = new FeedUri(FeedUri.FromDistributionPrefix + FeedTest.Test1Uri), ID = impl3.ID, QuickTestFile = impl3.QuickTestFile
                        }
                    }
                };

                PackageManagerMock.Setup(x => x.Lookup(selections.Implementations[0])).Returns(impl1);
                PackageManagerMock.Setup(x => x.Lookup(selections.Implementations[1])).Returns(impl2);

                var implementationSelections = Target.GetUncachedSelections(selections);

                // Only the first implementation should be listed as uncached
                implementationSelections.Should().BeEquivalentTo(new[] { selections.Implementations[0] }, because: "Only the first implementation should be listed as uncached");
            }
        }
Ejemplo n.º 4
0
        public void TestPackageManager()
        {
            var mainFeed = FeedTest.CreateTestFeed();

            mainFeed.Feeds.Clear();
            FeedManagerMock.Setup(x => x[FeedTest.Test1Uri]).Returns(mainFeed);

            var nativeImplementation = new ExternalImplementation("rpm", "firefox", new ImplementationVersion("1.0"))
            {
                Languages = { "en-US" }
            };

            PackageManagerMock.Setup(x => x.Query((PackageImplementation)mainFeed.Elements[1])).Returns(new[] { nativeImplementation });

            var requirements = new Requirements(FeedTest.Test1Uri, Command.NameRun);

            Target.GetSortedCandidates(requirements).Should().Equal(
                new SelectionCandidate(new FeedUri(FeedUri.FromDistributionPrefix + FeedTest.Test1Uri), new FeedPreferences(), nativeImplementation, requirements),
                new SelectionCandidate(FeedTest.Test1Uri, new FeedPreferences(), (Implementation)mainFeed.Elements[0], requirements));
        }
Ejemplo n.º 5
0
        public void TestGetImplementations()
        {
            var impl1 = new Implementation {
                ID = "test123"
            };
            var impl2 = new Implementation {
                ID = "test456"
            };
            var impl3 = new ExternalImplementation("RPM", "firefox", new ImplementationVersion("1.0"))
            {
                RetrievalMethods = { new ExternalRetrievalMethod {
                                         PackageID = "test"
                                     } }
            };
            var implementationSelections = new[]
            {
                new ImplementationSelection {
                    ID = impl1.ID, InterfaceUri = FeedTest.Test1Uri
                },
                new ImplementationSelection {
                    ID = impl2.ID, InterfaceUri = FeedTest.Test2Uri, FromFeed = FeedTest.Sub2Uri
                },
                new ImplementationSelection {
                    ID = impl3.ID, InterfaceUri = FeedTest.Test1Uri, FromFeed = new FeedUri(FeedUri.FromDistributionPrefix + FeedTest.Test1Uri)
                }
            };

            _feedCacheMock.Setup(x => x.GetFeed(FeedTest.Test1Uri)).Returns(new Feed {
                Elements = { impl1 }
            });
            _feedCacheMock.Setup(x => x.GetFeed(FeedTest.Sub2Uri)).Returns(new Feed {
                Elements = { impl2 }
            });
            _packageManagerMock.Setup(x => x.Lookup(implementationSelections[2])).Returns(impl3);

            var implementations = Target.GetImplementations(implementationSelections);

            CollectionAssert.AreEquivalent(new[] { impl1, impl2, impl3 }, implementations);
        }
Ejemplo n.º 6
0
 private static void CopyValues(Element from, ExternalImplementation to)
 {
     to.Commands.Add(from.Commands);
     to.Bindings.Add(from.Bindings);
 }
Ejemplo n.º 7
0
 private static void CopyValues(Element from, ExternalImplementation to)
 {
     to.Commands.AddRange(from.Commands);
     to.Bindings.AddRange(from.Bindings);
 }