public void CanReadProjectAssemblyFilename(string relativeCsProjPath, string assemblyName) { var csProjPath = TestPaths.GetVerifiedFileRelativeToProjectDir(relativeCsProjPath); var service = DIRegistrar.GetInstance <IProjectReader>(); Assert.AreEqual(assemblyName, service.ExtractAssemblyName(new DotNetXMLDoc(csProjPath))); }
public void CanRenderProblemsToHTMLFile(string relativeSlnPath) { var slnPath = TestPaths.GetVerifiedFileRelativeToProjectDir(relativeSlnPath); var solution = DIRegistrar.GetInstance <ISolutionReader>().ReadSolution(slnPath); var problemDetector = DIRegistrar.GetInstance <ProblemDetectorService>(); var problems = problemDetector.DetectAllSolutionProblems(solution); var outFile = new FileInfo("testout.html"); if (outFile.Exists) { outFile.Delete(); } var renderer = new HTMLProblemRenderer(outFile); var output = new CommandOutput(); output.DetectedProblems.AddRange(problems); renderer.RenderOutput(output); var fileText = File.ReadAllText(outFile.FullName); Assert.That(fileText.Contains(@"<span class='Highlighted'>Newtonsoft.Json</span>")); }
public void CanBuildProjectGraphFromSolution(string relativeSlnPath, int expectedProjects) { var slnFile = TestPaths.GetVerifiedFileRelativeToProjectDir(relativeSlnPath); var solution = DIRegistrar.GetInstance <ISolutionReader>().ReadSolution(slnFile); var graph = DIRegistrar.GetInstance <IProjectGraphBuilder>().BuildGraph(solution); Assert.AreEqual(expectedProjects, graph.SolutionProjects.Count); }
public void CanReadDotNetVersionOfProject(string relativeCsProjPath, string expectedVersion) { var csProjPath = TestPaths.GetVerifiedFileRelativeToProjectDir(relativeCsProjPath); var service = DIRegistrar.GetInstance <IProjectReader>(); var proj = service.ReadProject(csProjPath); Assert.AreEqual(expectedVersion, proj.DotNetVersion.ToString()); }
public void CanReadProjectReferences(string relativeCsProjPath, string expectedReference) { var csProjPath = TestPaths.GetVerifiedFileRelativeToProjectDir(relativeCsProjPath); var service = DIRegistrar.GetInstance <IProjectReader>(); var proj = service.ReadProject(csProjPath); var reference = proj.ProjectReferences.FirstOrDefault(rf => rf.RelativePath == expectedReference); Assert.IsNotNull(reference); }
public void CanAdjustPackesConfigPaths(string packagesFolder, string projectDirectory, string text, string expectedModifiedText) { var packagesDir = TestPaths.GetFolderRelativeToProjectDir(packagesFolder); var projectDir = TestPaths.GetFolderRelativeToProjectDir(projectDirectory); var modifier = DIRegistrar.GetInstance <NugetPackageModifier>(); var modifiedText = modifier.CorrectPackagesPath(projectDir, packagesDir, text); Assert.AreEqual(expectedModifiedText, modifiedText); }
public void CanReadNumberOfProjectsInSolution(string relativeSlnPath, int expectedProjects) { var slnPath = TestPaths.GetVerifiedFileRelativeToProjectDir(relativeSlnPath); var service = new SolutionReader(new EmptyProjectReader()); var sln = service.ReadSolution(slnPath); Assert.AreEqual(expectedProjects, sln.Projects.Length); }
public void CanReadNugetReference(string relativePackagesConfigPath, string expectedReference) { var projectFolder = TestPaths.GetFolderRelativeToProjectDir(relativePackagesConfigPath); var service = DIRegistrar.GetInstance <INugetReferenceReader>(); var packagesConfigFile = service.TryReadPackagesConfig(projectFolder); var dependency = packagesConfigFile.Packages.FirstOrDefault(pk => pk.ID == expectedReference); Assert.IsNotNull(dependency); }
public void CanReadFileReferences(string relativeCsProjPath, string expectedReference) { var csProjPath = TestPaths.GetVerifiedFileRelativeToProjectDir(relativeCsProjPath); var service = DIRegistrar.GetInstance <IProjectReader>(); var proj = service.ReadProject(csProjPath); var dependency = proj.FileReferences.FirstOrDefault(fr => fr.RelativePath.EndsWith(expectedReference)); Assert.IsNotNull(dependency); }
public void CanFindAllProblemsWithSolution(string relativeSlnPath, int expectedNumberOfProblems) { var slnPath = TestPaths.GetVerifiedFileRelativeToProjectDir(relativeSlnPath); var solution = DIRegistrar.GetInstance <ISolutionReader>().ReadSolution(slnPath); var problemDetector = DIRegistrar.GetInstance <ProblemDetectorService>(); var problems = problemDetector.DetectAllSolutionProblems(solution); Assert.AreEqual(expectedNumberOfProblems, problems.Length); }
public void CanDetectVersionOfFileReferenceFromPath(string relativeCsProjPath, string reference, string expectedFileVersion) { var csProjPath = TestPaths.GetVerifiedFileRelativeToProjectDir(relativeCsProjPath); var service = DIRegistrar.GetInstance <IProjectReader>(); var proj = service.ReadProject(csProjPath); var fileRef = proj.FileReferences.FirstOrDefault(r => r.Include.ID == reference); Assert.AreEqual(expectedFileVersion, fileRef.Version.ToString()); }
public void CanIdentifyMissingProjectFiles(string relativeSlnPath, string missingProjectName) { var slnPath = TestPaths.GetVerifiedFileRelativeToProjectDir(relativeSlnPath); var service = new SolutionReader(new EmptyProjectReader()); var sln = service.ReadSolution(slnPath); var missingProjectDetector = new MissingProjectDetector(); var problem = missingProjectDetector.DetectProblems(sln).FirstOrDefault() as MissingProject; Assert.AreEqual(missingProjectName, problem.Project.Name); }
public void CanDetectSameDLLReferencedInDifferentPaths(string relativeSlnPath) { var slnPath = TestPaths.GetVerifiedFileRelativeToProjectDir(relativeSlnPath); var solution = DIRegistrar.GetInstance <ISolutionReader>().ReadSolution(slnPath); var graphBuilder = DIRegistrar.GetInstance <IProjectGraphBuilder>(); var graph = graphBuilder.BuildGraph(solution); var detector = new FileReferencedInMultipleWaysDetector(); var problem = detector.DetectProblems(graph).First(); Assert.That(problem.Description.ToString().StartsWith("The file Newtonsoft.Json is referenced in multiple paths")); }
public void AllFileReferencesHavePaths(string relativeCsProjPath) { var csProjPath = TestPaths.GetVerifiedFileRelativeToProjectDir(relativeCsProjPath); var service = DIRegistrar.GetInstance <IProjectReader>(); var proj = service.ReadProject(csProjPath); foreach (var file in proj.FileReferences) { Assert.IsNotNull(file.GetFile()); } }
public void CanDetectFileReferenceWhereProjectReferenceIsMoreAppropriate(string relativeSlnPath, string project) { var slnPath = TestPaths.GetVerifiedFileRelativeToProjectDir(relativeSlnPath); var solution = DIRegistrar.GetInstance <ISolutionReader>().ReadSolution(slnPath); var graphBuilder = DIRegistrar.GetInstance <IProjectGraphBuilder>(); var graph = graphBuilder.BuildGraph(solution); var projectNode = graph.AllNodes.Values.Single(p => p.Project.Name == project); var detector = new FileReferenceInsteadOfProjectReferenceDetector(); var problem = detector.DetectProblems(projectNode).First(); Assert.AreEqual("Project FirstProject has a file reference instead of a project reference to AnotherProject", problem.Description.ToString()); }
public void CanDetectProjectDependingOnHigherDotNetVersion(string relativeSlnPath, string project) { var slnPath = TestPaths.GetVerifiedFileRelativeToProjectDir(relativeSlnPath); var solution = DIRegistrar.GetInstance <ISolutionReader>().ReadSolution(slnPath); var graphBuilder = DIRegistrar.GetInstance <IProjectGraphBuilder>(); var graph = graphBuilder.BuildGraph(solution); var projectNode = graph.AllNodes.Values.Single(p => p.Project.Name == project); var dependsOnHigherFrameworkDetector = new DependsOnIncompatibleFrameworkDetector(); var problem = dependsOnHigherFrameworkDetector.DetectProblems(projectNode).First(); Assert.AreEqual(typeof(DependsOnIncompatibleFramework), problem.GetType()); }
public void CorrectProblemsFromCommandLine(string slnPath) { var sln = TestPaths.GetFileRelativeToProjectDir(slnPath); var args = new CommandLineArgs ( command: "correct", solutionFile: sln.FullName, outputPath: string.Empty ); var handler = DIRegistrar.GetInstance <CommandLineHandler>(); var result = handler.ExecuteCommand(args); Assert.That(result.CorrectedProblems.Any()); }
public void DetectProblemsFromCommandLine(string slnPath, int expectedProblems) { var sln = TestPaths.GetFileRelativeToProjectDir(slnPath); var args = new CommandLineArgs ( command: "detect", solutionFile: sln.FullName, outputPath: string.Empty ); var handler = DIRegistrar.GetInstance <CommandLineHandler>(); var result = handler.ExecuteCommand(args); Assert.AreEqual(expectedProblems, result.DetectedProblems.Count); }
public void CheckFileEquality(string filePath1, string filePath2, bool shouldBeEqual) { var file1 = TestPaths.GetVerifiedFileRelativeToProjectDir(filePath1); var file2 = TestPaths.GetVerifiedFileRelativeToProjectDir(filePath2); if (shouldBeEqual) { Assert.AreEqual(file1, file2); Assert.That(file1 == file2); } else { Assert.AreNotEqual(file1, file2); Assert.That(file1 != file2); } }
public void CanModifyNugetPackage(string slnPath, string projectPath, string packagesConfigPath, string nugetPackage, string expectedVersion) { var packagesConfigFile = TestPaths.GetFileRelativeToProjectDir(packagesConfigPath); var sln = TestHelpers.GetSolutionGraph(slnPath); var nugetService = DIRegistrar.GetInstance <NugetPackageModifier>(); var package = nugetService.GetLatestNugetReference(nugetPackage, false, sln); var project = sln.FindProject(p => p.Project.FullPath.EndsWith(projectPath)).First().Project; nugetService.AddOrModifyNugetReference(package, project, sln.Solution.PackagesDirectory); sln = TestHelpers.GetSolutionGraph(slnPath); var reloadedProject = sln.FindProject(p => p.Project.FullPath.EndsWith(projectPath)).First(); package = reloadedProject.NugetPackageRequirements.FirstOrDefault(p => p.Package.ID == nugetPackage); Assert.AreEqual(expectedVersion, package.Version.ToString()); }
public void CanRenderProblemsToConsole(string relativeSlnPath) { var slnPath = TestPaths.GetVerifiedFileRelativeToProjectDir(relativeSlnPath); var solution = DIRegistrar.GetInstance <ISolutionReader>().ReadSolution(slnPath); var problemDetector = DIRegistrar.GetInstance <ProblemDetectorService>(); var problems = problemDetector.DetectAllSolutionProblems(solution); var renderer = new ConsoleProblemRenderer(); var stringBuilder = new StringBuilder(); var output = new CommandOutput(); output.DetectedProblems.AddRange(problems); using (var writer = new StringWriter(stringBuilder)) { Console.SetOut(writer); renderer.RenderOutput(output); Assert.That(stringBuilder.ToString().Contains("Multiple versions of Newtonsoft.Json exist")); } }
public void TestSetup() { TestPaths.RevertAllCsProjAndPackagesConfigFiles(); }
public void TestTeardown() { TestPaths.RevertAllCsProjAndPackagesConfigFiles(); }