public void OpenRepositoryUsesRepositoryFactory()
        {
            // Arrange
            Mock<IPackageRepositoryFactory> mockFactory = new Mock<IPackageRepositoryFactory>();
            PackageManagementCommand cmdlet = new Mock<PackageManagementCommand>() { CallBase = true }.Object;
            cmdlet.RepositoryFactory = mockFactory.Object;
            cmdlet.Source = "foo";
            IPackageRepository expected = new Mock<IPackageRepository>().Object;
            mockFactory.Setup(f => f.CreateRepository("foo")).Returns(expected);

            // Act
            IPackageRepository actual = cmdlet.OpenRepository();

            // Assert
            Assert.Same(expected, actual);
        }
        public void SourceIsAggregateFromPackageSourceServiceWhenNotSpecified()
        {
            // Arrange
            PackageManagementCommand cmd = new Mock<PackageManagementCommand>() { CallBase = true }.Object.AutoConfigure();
            Mock<IPackageRepositoryFactory> mockFactory = new Mock<IPackageRepositoryFactory>();
            Mock<PackageSourceService> mockService = new Mock<PackageSourceService>();
            mockService.Setup(s => s.AllSources).Returns(new[] {
                new PackageSource("http://foo.bar", "Foo"),
                new PackageSource("http://bar.baz", "Bar")
            });
            cmd.SourceService = mockService.Object;

            mockFactory.Setup(f => f.CreateRepository(It.IsAny<string>()))
                       .Returns<string>(src =>
                       {
                           Mock<IPackageRepository> mockRepo = new Mock<IPackageRepository>();
                           mockRepo.Setup(r => r.Source).Returns(src);
                           return mockRepo.Object;
                       });
            cmd.RepositoryFactory = mockFactory.Object;

            // Act
            IPackageRepository repo = cmd.OpenRepository();

            // Assert
            AggregateRepository aggrepo = Assert.IsType<AggregateRepository>(repo);
            Assert.Equal(new[] {
                "http://foo.bar",
                "http://bar.baz"
            }, aggrepo.Repositories.Select(r => r.Source).ToArray());
        }