public void MirrorCommandForPackageReferenceFileWarnsIfThereIsNoPackageToMirror() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"x:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> </packages>".AsStream()); MessageLevel? level = null; string message = null; var console = new Mock<IConsole>(); console.Setup(c => c.Log(It.IsAny<MessageLevel>(), It.IsAny<string>(), It.IsAny<object[]>())).Callback((MessageLevel a, string b, object[] c) => { if (a == MessageLevel.Warning) { level = a; message = b; } }); var mirrorCommand = new TestMirrorCommand(@"x:\test\packages.config", fileSystem: fileSystem) { Console = console.Object }; // Act mirrorCommand.ExecuteCommand(); // Assert Assert.Equal(level, MessageLevel.Warning); Assert.Equal(message, "No packages found to check for mirroring."); }
public void MirrorCommandUsesLocalCacheIfNoCacheIsFalse() { // Arrange var localCache = new Mock <IPackageRepository>(MockBehavior.Strict); localCache.Setup(c => c.GetPackages()).Returns(new[] { PackageUtility.CreatePackage("Gamma") }.AsQueryable()).Verifiable(); var mirrorCommand = new TestMirrorCommand("Gamma", machineCacheRepository: localCache.Object) { NoCache = false, }; mirrorCommand.Source.Add("Some Source name"); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Gamma", "1.0"); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'Gamma 1.0' to 'destinationurlpull'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Mirrored 1 package(s).") }); localCache.Verify(); }
public void MirrorCommandMirrorsPackagesConfigWithoutVersionPrerelease() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"x:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> <package id=""Foo"" /> <package id=""Baz"" /> </packages>".AsStream()); var mirrorCommand = new TestMirrorCommand(@"x:\test\packages.config", fileSystem: fileSystem) { Prerelease = true }; mirrorCommand.Source.Add("Some Source name"); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertTwoPackages(mirrorCommand, "Foo", "1.0", "Baz", "0.8.1-alpha"); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'Foo 1.0' to 'destinationurlpull'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'Baz 0.8.1-alpha' to 'destinationurlpull'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Mirrored 2 package(s).") }); }
public void MirrorCommandMirrorsDependenciesByDefaultWhenUsingConfigFile() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"x:\test\mirroring.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> <package id=""PackageWithDependencies"" /> </packages>".AsStream()); var mirrorCommand = new TestMirrorCommand(@"x:\test\mirroring.config", fileSystem: fileSystem); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertTwoPackages(mirrorCommand, "ChildPackage", "3.0", "PackageWithDependencies", "2.0"); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Attempting to resolve dependency 'ChildPackage (> 2.0 && < 5.0)'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'ChildPackage 3.0' to 'destinationurlpull'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'PackageWithDependencies 2.0' to 'destinationurlpull'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Mirrored 2 package(s).") }); }
private static void AssertSinglePackage(TestMirrorCommand mirrorCommand, string id, string version) { var pack = mirrorCommand.DestinationRepository.GetPackages().Single(); Assert.Equal(id, pack.Id); Assert.Equal(version, pack.Version.ToString()); }
public void MirrorCommandSupportsMultipleEntriesSamePackageAndDownloadsDependents() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"x:\test\mirroring.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> <package id=""PackageWithDependencies"" version=""1.0"" /> <package id=""PackageWithDependencies"" /> </packages>".AsStream()); var mirrorCommand = new TestMirrorCommand(@"x:\test\mirroring.config", fileSystem: fileSystem); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Attempting to resolve dependency 'ChildPackage (≥ 1.0 && < 2.0)'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'ChildPackage 1.4' to 'destinationurlpull'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'PackageWithDependencies 1.0' to 'destinationurlpull'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Attempting to resolve dependency 'ChildPackage (> 2.0 && < 5.0)'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'ChildPackage 3.0' to 'destinationurlpull'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'PackageWithDependencies 2.0' to 'destinationurlpull'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Mirrored 4 package(s).") }); }
public void MirrorCommandForPackageReferenceFileWarnsIfThereIsNoPackageToMirror() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"x:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> </packages>".AsStream()); MessageLevel?level = null; string message = null; var console = new Mock <IConsole>(); console.Setup(c => c.Log(It.IsAny <MessageLevel>(), It.IsAny <string>(), It.IsAny <object[]>())).Callback((MessageLevel a, string b, object[] c) => { if (a == MessageLevel.Warning) { level = a; message = b; } }); var mirrorCommand = new TestMirrorCommand(@"x:\test\packages.config", fileSystem: fileSystem) { Console = console.Object }; // Act mirrorCommand.ExecuteCommand(); // Assert Assert.Equal(level, MessageLevel.Warning); Assert.Equal(message, "No packages found to check for mirroring."); }
public void MirrorCommandLogsWarningsForFailingRepositoriesIfNoSourcesAreSpecified() { // Arrange var repositoryA = new MockPackageRepository(); repositoryA.AddPackage(PackageUtility.CreatePackage("Foo")); var repositoryB = new Mock <IPackageRepository>(); repositoryB.Setup(c => c.GetPackages()).Returns(GetPackagesWithException().AsQueryable()); var sourceProvider = GetSourceProvider(new[] { new PackageSource("A"), new PackageSource("B") }); var factory = new Mock <IPackageRepositoryFactory>(); factory.Setup(c => c.CreateRepository("A")).Returns(repositoryA); factory.Setup(c => c.CreateRepository("B")).Returns(repositoryB.Object); var mirrorCommand = new TestMirrorCommand("Foo", factory.Object, sourceProvider); // Act mirrorCommand.ExecuteCommand(); // Assert AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair <MessageLevel, string>(MessageLevel.Warning, "Boom"), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'Foo 1.0' to 'destinationurlpull'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Mirrored 1 package(s).") }); }
public void MirrorCommandThrowsIfConfigFileDoesNotExist() { // Arrange var mirrorCommand = new TestMirrorCommand(@"x:\test\packages.config"); // Act and Assert ExceptionAssert.Throws <FileNotFoundException>(() => mirrorCommand.ExecuteCommand(), @"x:\test\packages.config not found."); }
private static void AssertOutputEquals(TestMirrorCommand mirrorCommand, IEnumerable <KeyValuePair <MessageLevel, string> > lines) { int line = 0; foreach (var kvp in lines) { mirrorCommand.AssertOutputContains(line, kvp.Key, kvp.Value); line++; } }
public void MirrorCommandMirrorsPackageSuccessfullyIfCacheRepositoryIsNotSet() { // Arrange var mirrorCommand = new TestMirrorCommand("Foo"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Foo", "1.0"); }
public void MirrorCommandMirrorsPackageIfArgumentIsNotPackageReferenceFile() { // Arrange var mirrorCommand = new TestMirrorCommand("Foo"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Foo", "1.0"); }
public void MirrorCommandMirrorsPackageSuccessfullyIfCacheRepositoryIsNotSet() { // Arrange var mirrorCommand = new TestMirrorCommand("Foo"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Foo", "1.0"); }
public void MirrorCommandMirrorsPackageIfArgumentIsNotPackageReferenceFile() { // Arrange var mirrorCommand = new TestMirrorCommand("Foo"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Foo", "1.0"); }
public void MirrorCommandResolvesSourceName() { // Arrange var mirrorCommand = new TestMirrorCommand("Foo"); mirrorCommand.Source.Add("Some source name"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Foo", "1.0"); }
public void MirrorCommandUsesMultipleSourcesIfSpecified() { // Arrange var mirrorCommand = new TestMirrorCommand("Baz"); mirrorCommand.Source.Add("Some Source name"); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Baz", "0.7"); }
public void MirrorCommandUsesMirrorOperation() { // Arrange var mockRepo = new MockPackageRepository() { PackageUtility.CreatePackage("Foo") }; var mockFactory = new Mock<IPackageRepositoryFactory>(); mockFactory.Setup(r => r.CreateRepository(It.IsAny<string>())).Returns(mockRepo); var mirrorCommand = new TestMirrorCommand("Foo", mockFactory.Object); // Act mirrorCommand.ExecuteCommand(); // Assert Assert.Equal(RepositoryOperationNames.Mirror, mockRepo.LastOperation); }
public void MirrorCommandFailWhenDependentsMissingAndDependentsModeIsFail() { // Arrange var mirrorCommand = new TestMirrorCommand("PackageWithDependencies") { Version = "2.0", DependenciesMode = MirrorDependenciesMode.Fail }; mirrorCommand.Source.Add("Some other Source"); // Act and Assert ExceptionAssert.Throws <InvalidOperationException>(mirrorCommand.ExecuteCommand, "Unable to resolve dependency 'ChildPackage (> 2.0 && < 5.0)'."); }
private static void AssertTwoPackages(TestMirrorCommand mirrorCommand, string id, string version, string id2, string version2) { var pack = mirrorCommand.DestinationRepository.GetPackages(); Assert.Equal(2, pack.Count()); var first = pack.First(); var last = pack.Last(); Assert.Equal(id, first.Id); Assert.Equal(version, first.Version.ToString()); Assert.Equal(id2, last.Id); Assert.Equal(version2, last.Version.ToString()); }
public void MirrorCommandMirrorsPackageSuccessfullyIfCacheRepositoryIsNotSet() { // Arrange var mirrorCommand = new TestMirrorCommand("Foo"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Foo", "1.0"); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'Foo 1.0' to 'destinationurlpull'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Mirrored 1 package(s).") }); }
public void MirrorCommandMirrorsPackageSuccessfullyIfCacheRepositoryIsNotSet() { // Arrange var mirrorCommand = new TestMirrorCommand("Foo"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Foo", "1.0"); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'Foo 1.0' to 'destinationurlpull'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Mirrored 1 package(s).") }); }
public void MirrorCommandThrowsIfVersionAndPackageConfigBothSpecified() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"x:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> </packages>".AsStream()); var mirrorCommand = new TestMirrorCommand(@"x:\test\packages.config", fileSystem: fileSystem) { Version = "1.0" }; // Act and Assert ExceptionAssert.Throws <ArgumentException>(() => mirrorCommand.ExecuteCommand(), "Version should be specified in packages.config file instead."); }
public void MirrorCommandMirrorsPrereleasePackageIfFlagIsSpecified() { // Arrange var mirrorCommand = new TestMirrorCommand("Baz") { Prerelease = true }; mirrorCommand.Source.Add("Some Source name"); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Baz", "0.8.1-alpha"); }
public void MirrorCommandUsesMirrorOperation() { // Arrange var mockRepo = new MockPackageRepository() { PackageUtility.CreatePackage("Foo") }; var mockFactory = new Mock <IPackageRepositoryFactory>(); mockFactory.Setup(r => r.CreateRepository(It.IsAny <string>())).Returns(mockRepo); var mirrorCommand = new TestMirrorCommand("Foo", mockFactory.Object); // Act mirrorCommand.ExecuteCommand(); // Assert Assert.Equal(RepositoryOperationNames.Mirror, mockRepo.LastOperation); }
public void MirrorCommandForPackageReferenceFileReportsZeroIfThereIsNoPackageToMirror() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"x:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> </packages>".AsStream()); var mirrorCommand = new TestMirrorCommand(@"x:\test\packages.config", fileSystem: fileSystem); // Act mirrorCommand.ExecuteCommand(); // Assert AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Mirrored 0 package(s).") }); }
public void MirrorCommandResolvesSourceName() { // Arrange var mirrorCommand = new TestMirrorCommand("Foo"); mirrorCommand.Source.Add("Some source name"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Foo", "1.0"); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'Foo 1.0' to 'destinationurlpull'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Mirrored 1 package(s).") }); }
public void MirrorCommandUsesMirrorOperation() { // Arrange var mockRepo = new MockPackageRepository() { PackageUtility.CreatePackage("Foo") }; var mockFactory = new Mock<IPackageRepositoryFactory>(); mockFactory.Setup(r => r.CreateRepository(It.IsAny<string>())).Returns(mockRepo); var mirrorCommand = new TestMirrorCommand("Foo", mockFactory.Object); // Act mirrorCommand.ExecuteCommand(); // Assert Assert.Equal(RepositoryOperationNames.Mirror, mockRepo.LastOperation); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'Foo 1.0' to 'destinationurlpull'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Mirrored 1 package(s).") }); }
public void MirrorCommandUsesMultipleSourcesIfSpecified() { // Arrange var mirrorCommand = new TestMirrorCommand("Baz"); mirrorCommand.Source.Add("Some Source name"); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Baz", "0.7"); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'Baz 0.7' to 'destinationurlpull'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Mirrored 1 package(s).") }); }
public void MirrorCommandForPackageReferenceFileReportsZeroIfThereIsNoPackageToMirror() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"x:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> </packages>".AsStream()); var mirrorCommand = new TestMirrorCommand(@"x:\test\packages.config", fileSystem: fileSystem); // Act mirrorCommand.ExecuteCommand(); // Assert AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Mirrored 0 package(s).") }); }
public void MirrorCommandDoesNotUseLocalCacheIfNoCacheIsTrue() { // Arrange var localCache = new Mock <IPackageRepository>(MockBehavior.Strict); var mirrorCommand = new TestMirrorCommand("Baz", machineCacheRepository: localCache.Object) { NoCache = true }; mirrorCommand.Source.Add("Some Source name"); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Baz", "0.7"); localCache.Verify(c => c.GetPackages(), Times.Never()); }
public void MirrorCommandMirrorsPackagesConfigWithoutVersion() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"x:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> <package id=""Foo"" /> <package id=""Baz"" /> </packages>".AsStream()); var mirrorCommand = new TestMirrorCommand(@"x:\test\packages.config", fileSystem: fileSystem); mirrorCommand.Source.Add("Some Source name"); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertTwoPackages(mirrorCommand, "Foo", "1.0", "Baz", "0.7"); }
public void MirrorCommandUsesLocalCacheIfNoCacheIsFalse() { // Arrange var localCache = new Mock <IPackageRepository>(MockBehavior.Strict); localCache.Setup(c => c.GetPackages()).Returns(new[] { PackageUtility.CreatePackage("Gamma") }.AsQueryable()).Verifiable(); var mirrorCommand = new TestMirrorCommand("Gamma", machineCacheRepository: localCache.Object) { NoCache = false }; mirrorCommand.Source.Add("Some Source name"); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Gamma", "1.0"); localCache.Verify(); }
public void MirrorCommandMirrorsPrereleasePackageIfFlagIsSpecified() { // Arrange var mirrorCommand = new TestMirrorCommand("Baz") { Prerelease = true }; mirrorCommand.Source.Add("Some Source name"); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Baz", "0.8.1-alpha"); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'Baz 0.8.1-alpha' to 'destinationurlpull'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Mirrored 1 package(s).") }); }
public void MirrorCommandSkipDependentsWhenDependentsModeIsSkip() { // Arrange var mirrorCommand = new TestMirrorCommand("PackageWithDependencies") { Version = "2.0", DependenciesMode = MirrorDependenciesMode.Ignore }; mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "PackageWithDependencies", "2.0"); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'PackageWithDependencies 2.0' to 'destinationurlpull'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Mirrored 1 package(s).") }); }
public void MirrorCommandLogsWarningsForFailingRepositoriesIfNoSourcesAreSpecified() { // Arrange MessageLevel?level = null; string message = null; var repositoryA = new MockPackageRepository(); repositoryA.AddPackage(PackageUtility.CreatePackage("Foo")); var repositoryB = new Mock <IPackageRepository>(); repositoryB.Setup(c => c.GetPackages()).Returns(GetPackagesWithException().AsQueryable()); var console = new Mock <IConsole>(); console.Setup(c => c.Log(It.IsAny <MessageLevel>(), It.IsAny <string>(), It.IsAny <object[]>())).Callback((MessageLevel a, string b, object[] c) => { if (a == MessageLevel.Warning) { level = a; message = b; } }); var sourceProvider = GetSourceProvider(new[] { new PackageSource("A"), new PackageSource("B") }); var factory = new Mock <IPackageRepositoryFactory>(); factory.Setup(c => c.CreateRepository("A")).Returns(repositoryA); factory.Setup(c => c.CreateRepository("B")).Returns(repositoryB.Object); var mirrorCommand = new TestMirrorCommand("Foo", factory.Object, sourceProvider) { Console = console.Object }; // Act mirrorCommand.ExecuteCommand(); // Assert Assert.Equal("Boom", message); Assert.Equal(MessageLevel.Warning, level.Value); }
public void MirrorCommandMirrorsDependenciesByDefault() { // Arrange var mirrorCommand = new TestMirrorCommand("PackageWithDependencies") { Version = "2.0" }; mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertTwoPackages(mirrorCommand, "ChildPackage", "3.0", "PackageWithDependencies", "2.0"); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Attempting to resolve dependency 'ChildPackage (> 2.0 && < 5.0)'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'ChildPackage 3.0' to 'destinationurlpull'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'PackageWithDependencies 2.0' to 'destinationurlpull'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Mirrored 2 package(s).") }); }
public void MirrorCommandSkipsAlreadyInstalledDependents() { // Arrange var mirrorCommand = new TestMirrorCommand("PackageWithDependencies") { Version = "2.0" }; mirrorCommand.Source.Add("Some other Source"); mirrorCommand.DestinationRepository.AddPackage(PackageUtility.CreatePackage("ChildPackage", "3.0")); // Act mirrorCommand.ExecuteCommand(); // Assert AssertTwoPackages(mirrorCommand, "ChildPackage", "3.0", "PackageWithDependencies", "2.0"); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Attempting to resolve dependency 'ChildPackage (> 2.0 && < 5.0)'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'PackageWithDependencies 2.0' to 'destinationurlpull'."), new KeyValuePair <MessageLevel, string>(MessageLevel.Info, "Mirrored 1 package(s).") }); }
public void MirrorCommandUsesLocalCacheIfNoCacheIsFalse() { // Arrange var localCache = new Mock<IPackageRepository>(MockBehavior.Strict); localCache.Setup(c => c.GetPackages()).Returns(new[] { PackageUtility.CreatePackage("Gamma") }.AsQueryable()).Verifiable(); var mirrorCommand = new TestMirrorCommand("Gamma", machineCacheRepository: localCache.Object) { NoCache = false }; mirrorCommand.Source.Add("Some Source name"); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Gamma", "1.0"); localCache.Verify(); }
public void MirrorCommandDoesNotUseLocalCacheIfNoCacheIsTrue() { // Arrange var localCache = new Mock<IPackageRepository>(MockBehavior.Strict); var mirrorCommand = new TestMirrorCommand("Baz", machineCacheRepository: localCache.Object) { NoCache = true }; mirrorCommand.Source.Add("Some Source name"); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Baz", "0.7"); localCache.Verify(c => c.GetPackages(), Times.Never()); }
public void MirrorCommandMirrorsPrereleasePackageIfFlagIsSpecified() { // Arrange var mirrorCommand = new TestMirrorCommand("Baz") { Prerelease = true }; mirrorCommand.Source.Add("Some Source name"); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Baz", "0.8.1-alpha"); }
public void MirrorCommandMirrorsPackagesConfigWithoutVersionPrerelease() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"x:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> <package id=""Foo"" /> <package id=""Baz"" /> </packages>".AsStream()); var mirrorCommand = new TestMirrorCommand(@"x:\test\packages.config", fileSystem: fileSystem) { Prerelease = true }; mirrorCommand.Source.Add("Some Source name"); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertTwoPackages(mirrorCommand, "Foo", "1.0", "Baz", "0.8.1-alpha"); }
public void MirrorCommandMirrorsPackagesConfigWithoutVersionPrerelease() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"x:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> <package id=""Foo"" /> <package id=""Baz"" /> </packages>".AsStream()); var mirrorCommand = new TestMirrorCommand(@"x:\test\packages.config", fileSystem: fileSystem) { Prerelease = true }; mirrorCommand.Source.Add("Some Source name"); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertTwoPackages(mirrorCommand, "Foo", "1.0", "Baz", "0.8.1-alpha"); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'Foo 1.0' to 'destinationurlpull'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'Baz 0.8.1-alpha' to 'destinationurlpull'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Mirrored 2 package(s).") }); }
public void MirrorCommandThrowsIfConfigFileDoesNotExist() { // Arrange var mirrorCommand = new TestMirrorCommand(@"x:\test\packages.config"); // Act and Assert ExceptionAssert.Throws<FileNotFoundException>(() => mirrorCommand.ExecuteCommand(), @"x:\test\packages.config not found."); }
public void MirrorCommandResolvesSourceName() { // Arrange var mirrorCommand = new TestMirrorCommand("Foo"); mirrorCommand.Source.Add("Some source name"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Foo", "1.0"); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'Foo 1.0' to 'destinationurlpull'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Mirrored 1 package(s).") }); }
private static void AssertTwoPackages(TestMirrorCommand mirrorCommand, string id, string version, string id2, string version2) { var pack = mirrorCommand.DestinationRepository.GetPackages(); Assert.Equal(2, pack.Count()); var first = pack.First(); var last = pack.Last(); Assert.Equal(id, first.Id); Assert.Equal(version, first.Version.ToString()); Assert.Equal(id2, last.Id); Assert.Equal(version2, last.Version.ToString()); }
private static void AssertOutputEquals(TestMirrorCommand mirrorCommand, IEnumerable<KeyValuePair<MessageLevel, string>> lines) { int line = 0; foreach (var kvp in lines) { mirrorCommand.AssertOutputContains(line, kvp.Key, kvp.Value); line++; } }
public void MirrorCommandSupportsMultipleEntriesSamePackageAndDownloadsDependents() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"x:\test\mirroring.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> <package id=""PackageWithDependencies"" version=""1.0"" /> <package id=""PackageWithDependencies"" /> </packages>".AsStream()); var mirrorCommand = new TestMirrorCommand(@"x:\test\mirroring.config", fileSystem: fileSystem); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Attempting to resolve dependency 'ChildPackage (≥ 1.0 && < 2.0)'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'ChildPackage 1.4' to 'destinationurlpull'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'PackageWithDependencies 1.0' to 'destinationurlpull'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Attempting to resolve dependency 'ChildPackage (> 2.0 && < 5.0)'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'ChildPackage 3.0' to 'destinationurlpull'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'PackageWithDependencies 2.0' to 'destinationurlpull'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Mirrored 4 package(s).") }); }
public void MirrorCommandResolvesSourceName() { // Arrange var mirrorCommand = new TestMirrorCommand("Foo"); mirrorCommand.Source.Add("Some source name"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Foo", "1.0"); }
public void MirrorCommandDoesNotUseLocalCacheIfNoCacheIsTrue() { // Arrange var localCache = new Mock<IPackageRepository>(MockBehavior.Strict); var mirrorCommand = new TestMirrorCommand("Baz", machineCacheRepository: localCache.Object) { NoCache = true }; mirrorCommand.Source.Add("Some Source name"); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Baz", "0.7"); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'Baz 0.7' to 'destinationurlpull'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Mirrored 1 package(s).") }); localCache.Verify(c => c.GetPackages(), Times.Never()); }
public void MirrorCommandSucceedsWhenDependentsPresentInTargetAndDependentsModeIsFail() { // Arrange var mirrorCommand = new TestMirrorCommand("PackageWithDependencies") { Version = "2.0", DependenciesMode = MirrorDependenciesMode.Fail }; mirrorCommand.Source.Add("Some other Source"); mirrorCommand.DestinationRepository.AddPackage(PackageUtility.CreatePackage("ChildPackage", "3.0")); // Act mirrorCommand.ExecuteCommand(); // Assert AssertTwoPackages(mirrorCommand, "ChildPackage", "3.0", "PackageWithDependencies", "2.0"); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Attempting to resolve dependency 'ChildPackage (> 2.0 && < 5.0)'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'PackageWithDependencies 2.0' to 'destinationurlpull'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Mirrored 1 package(s).") }); }
public void MirrorCommandUsesMultipleSourcesIfSpecified() { // Arrange var mirrorCommand = new TestMirrorCommand("Baz"); mirrorCommand.Source.Add("Some Source name"); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Baz", "0.7"); }
private static void AssertSinglePackage(TestMirrorCommand mirrorCommand, string id, string version) { var pack = mirrorCommand.DestinationRepository.GetPackages().Single(); Assert.Equal(id, pack.Id); Assert.Equal(version, pack.Version.ToString()); }
public void MirrorCommandThrowsIfVersionAndPackageConfigBothSpecified() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"x:\test\packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> </packages>".AsStream()); var mirrorCommand = new TestMirrorCommand(@"x:\test\packages.config", fileSystem: fileSystem) { Version = "1.0" }; // Act and Assert ExceptionAssert.Throws<ArgumentException>(() => mirrorCommand.ExecuteCommand(), "Version should be specified in packages.config file instead."); }
public void MirrorCommandMirrorsDependenciesByDefault() { // Arrange var mirrorCommand = new TestMirrorCommand("PackageWithDependencies") { Version = "2.0" }; mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertTwoPackages(mirrorCommand, "ChildPackage", "3.0", "PackageWithDependencies", "2.0"); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Attempting to resolve dependency 'ChildPackage (> 2.0 && < 5.0)'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'ChildPackage 3.0' to 'destinationurlpull'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'PackageWithDependencies 2.0' to 'destinationurlpull'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Mirrored 2 package(s).") }); }
public void MirrorCommandFailWhenDependentsMissingAndDependentsModeIsFail() { // Arrange var mirrorCommand = new TestMirrorCommand("PackageWithDependencies") { Version = "2.0", DependenciesMode = MirrorDependenciesMode.Fail }; mirrorCommand.Source.Add("Some other Source"); // Act and Assert ExceptionAssert.Throws<InvalidOperationException>(mirrorCommand.ExecuteCommand, "Unable to resolve dependency 'ChildPackage (> 2.0 && < 5.0)'."); }
public void MirrorCommandMirrorsPrereleasePackageIfFlagIsSpecified() { // Arrange var mirrorCommand = new TestMirrorCommand("Baz") { Prerelease = true }; mirrorCommand.Source.Add("Some Source name"); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Baz", "0.8.1-alpha"); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'Baz 0.8.1-alpha' to 'destinationurlpull'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Mirrored 1 package(s).") }); }
public void MirrorCommandMirrorsDependenciesByDefaultWhenUsingConfigFile() { // Arrange var fileSystem = new MockFileSystem(); fileSystem.AddFile(@"x:\test\mirroring.config", @"<?xml version=""1.0"" encoding=""utf-8""?> <packages> <package id=""PackageWithDependencies"" /> </packages>".AsStream()); var mirrorCommand = new TestMirrorCommand(@"x:\test\mirroring.config", fileSystem: fileSystem); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertTwoPackages(mirrorCommand, "ChildPackage", "3.0", "PackageWithDependencies", "2.0"); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Attempting to resolve dependency 'ChildPackage (> 2.0 && < 5.0)'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'ChildPackage 3.0' to 'destinationurlpull'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'PackageWithDependencies 2.0' to 'destinationurlpull'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Mirrored 2 package(s).") }); }
public void MirrorCommandSkipDependentsWhenDependentsModeIsSkip() { // Arrange var mirrorCommand = new TestMirrorCommand("PackageWithDependencies") { Version = "2.0", DependenciesMode = MirrorDependenciesMode.Ignore }; mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "PackageWithDependencies", "2.0"); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'PackageWithDependencies 2.0' to 'destinationurlpull'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Mirrored 1 package(s).") }); }
public void MirrorCommandUsesLocalCacheIfNoCacheIsFalse() { // Arrange var localCache = new Mock<IPackageRepository>(MockBehavior.Strict); localCache.Setup(c => c.GetPackages()).Returns(new[] { PackageUtility.CreatePackage("Gamma") }.AsQueryable()).Verifiable(); var mirrorCommand = new TestMirrorCommand("Gamma", machineCacheRepository: localCache.Object) { NoCache = false, }; mirrorCommand.Source.Add("Some Source name"); mirrorCommand.Source.Add("Some other Source"); // Act mirrorCommand.ExecuteCommand(); // Assert AssertSinglePackage(mirrorCommand, "Gamma", "1.0"); AssertOutputEquals(mirrorCommand, new[] { new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Successfully mirrored 'Gamma 1.0' to 'destinationurlpull'."), new KeyValuePair<MessageLevel, string>(MessageLevel.Info, "Mirrored 1 package(s).") }); localCache.Verify(); }
public void MirrorCommandLogsWarningsForFailingRepositoriesIfNoSourcesAreSpecified() { // Arrange MessageLevel? level = null; string message = null; var repositoryA = new MockPackageRepository(); repositoryA.AddPackage(PackageUtility.CreatePackage("Foo")); var repositoryB = new Mock<IPackageRepository>(); repositoryB.Setup(c => c.GetPackages()).Returns(GetPackagesWithException().AsQueryable()); var console = new Mock<IConsole>(); console.Setup(c => c.Log(It.IsAny<MessageLevel>(), It.IsAny<string>(), It.IsAny<object[]>())).Callback((MessageLevel a, string b, object[] c) => { if (a == MessageLevel.Warning) { level = a; message = b; } }); var sourceProvider = GetSourceProvider(new[] { new PackageSource("A"), new PackageSource("B") }); var factory = new Mock<IPackageRepositoryFactory>(); factory.Setup(c => c.CreateRepository("A")).Returns(repositoryA); factory.Setup(c => c.CreateRepository("B")).Returns(repositoryB.Object); var mirrorCommand = new TestMirrorCommand("Foo", factory.Object, sourceProvider) { Console = console.Object }; // Act mirrorCommand.ExecuteCommand(); // Assert Assert.Equal("Boom", message); Assert.Equal(MessageLevel.Warning, level.Value); }