public void VisitProject_ShouldCallNugetRestoreBeforeCallingNuGetUpdate() { var fileSystem = RegisterMockFileSystem(); var nuget = Container.Resolve <INuget>(); var instance = new BuildAndUpdateDependenciesVisitor(new List <string>()); EnsureFiles(fileSystem, Lib1PackagesDirectory, Lib1Packages); EnsureFiles(fileSystem, Lib2Directory, Lib2Solutions); bool nugetRestoreCalled = false; nuget.Arrange(n => n.Restore(Arg.AnyString)) .Returns((string solution) => { nugetRestoreCalled = true; return(ReturnCode.Success); }); nuget.Arrange(n => n.Update(Arg.AnyString, Arg.AnyString, Arg.AnyString, Arg.AnyString)) .Returns((string solution, string id, string version, string sourceDirectory) => { Assert.IsTrue(nugetRestoreCalled, "NuGet.exe restore should have been called before Update"); return(ReturnCode.Success); }); fileSystem.Directory.CreateDirectory(Lib2Directory); var code = instance.VisitProject(Lib2Directory, Lib2Config); Assert.AreEqual(ReturnCode.Success, code, "Invalid Return Code"); Assert.AreEqual(ReturnCode.Success, instance.ReturnCode, "Invalid Return Code"); }
public void VisitProject_ShouldReturn_DirectoryDoesNotExist_WhenDirectoryDoesNotExist() { var instance = new BuildAndUpdateDependenciesVisitor(new List <string>()); var code = instance.VisitProject(Lib2Directory, Lib2Config); Assert.AreEqual(ReturnCode.DirectoryDoesNotExist, code, "Invalid Return Code"); }
public void VisitProject_ShouldReturn_Success_WhenConfigIsNull() { var instance = new BuildAndUpdateDependenciesVisitor(new List <string>()); var code = instance.VisitProject(Lib2Directory, null); Assert.AreEqual(ReturnCode.Success, code, "Invalid Return Code"); Assert.AreEqual(ReturnCode.Success, instance.ReturnCode, "Invalid Return Code"); }
public void VisitProject_ShouldCallNugetUpdate_ForEachNugetPackageInDependencyArtifactsFolder() { var fileSystem = RegisterMockFileSystem(); var nuget = Container.Resolve <INuget>(); var instance = new BuildAndUpdateDependenciesVisitor(new List <string>()); EnsureFiles(fileSystem, Lib1PackagesDirectory, Lib1Packages); EnsureFiles(fileSystem, Lib1PackagesDirectory, new List <string> { ".nupkg", "bad.input.nupkg" }); EnsureFiles(fileSystem, Lib2Directory, Lib2Solutions); Dictionary <string, List <string> > updatedPackages = new Dictionary <string, List <string> >(); nuget.Arrange(n => n.Update(Arg.AnyString, Arg.AnyString, Arg.AnyString, Arg.AnyString)) .Returns((string solution, string id, string version, string sourceDirectory) => { Assert.AreEqual(Lib2Directory, nuget.WorkingDirectory, "Invalid working directory for Nuget.exe"); var key = $"{id}.{version}"; if (updatedPackages.ContainsKey(key)) { var list = updatedPackages[key]; Assert.IsFalse(list.Contains(solution)); list.Add(solution); } else { updatedPackages.Add(key, new List <string> { solution }); } return(ReturnCode.Success); }); fileSystem.Directory.CreateDirectory(Lib2Directory); var code = instance.VisitProject(Lib2Directory, Lib2Config); Assert.AreEqual(ReturnCode.Success, code, "Invalid Return Code"); Assert.AreEqual(ReturnCode.Success, instance.ReturnCode, "Invalid Return Code"); Assert.AreEqual(Lib1Packages.Count, updatedPackages.Keys.Count, "Invalid number of updated packages"); foreach (var kvp in updatedPackages) { Assert.IsTrue(Lib1Packages.Any(p => fileSystem.Path.GetFileNameWithoutExtension(p) == kvp.Key)); foreach (var solution in kvp.Value) { Assert.IsTrue(Lib2Solutions.Any(s => s == fileSystem.Path.GetFileName(solution)), $"{solution} was not found in Lib2Solutions"); } } }
public void VisitProject_ShouldReturn_CouldNotCreateCacheDirectory_WhenCacheDirectoryFailsToInitialize() { var fileSystem = Container.Resolve <IFileSystem>(); fileSystem.Directory.Arrange(d => d.Exists(Arg.AnyString)).Returns(true); fileSystem.Directory.Arrange(d => d.GetFiles(Arg.AnyString, "*.nupkg")) .Returns(Lib1Packages.ToArray()); fileSystem.Directory.Arrange(d => d.GetFiles(Arg.AnyString, "*.sln", Arg.IsAny <SearchOption>())) .Returns(Lib2Solutions.Select(s => Lib2Directory + "\\" + s).ToArray()); fileSystem.Path.Arrange(p => p.GetFileNameWithoutExtension(Arg.AnyString)) .Returns(Path.GetFileNameWithoutExtension); fileSystem.Directory.Arrange(d => d.CreateDirectory(Arg.AnyString)) .Throws <IOException>("Access Denied"); var instance = new BuildAndUpdateDependenciesVisitor(new List <string>()); var code = instance.VisitProject(Lib2Directory, Lib2Config); Assert.AreEqual(ReturnCode.CouldNotCreateCacheDirectory, code, "Invalid Return Code"); Assert.AreEqual(ReturnCode.CouldNotCreateCacheDirectory, instance.ReturnCode, "Invalid Return Code"); }