|
| 1 | +using DotnetAffected.Testing.Utils; |
| 2 | +using System.IO; |
| 3 | +using System.Linq; |
| 4 | +using System.Threading.Tasks; |
| 5 | +using Xunit; |
| 6 | + |
| 7 | +namespace DotnetAffected.Core.Tests |
| 8 | +{ |
| 9 | + /// <summary> |
| 10 | + /// Tests for detecting changed projects when using a SolutionFile to filter. |
| 11 | + /// This should cover all tests where filtering should be applied |
| 12 | + /// </summary> |
| 13 | + public class ChangeDetectionUsingXmlSolutionTests |
| 14 | + : BaseDotnetAffectedTest |
| 15 | + { |
| 16 | + private readonly string _solutionPath = "test-solution.slnx"; |
| 17 | + |
| 18 | + protected override AffectedOptions Options => new AffectedOptions( |
| 19 | + this.Repository.Path, |
| 20 | + Path.Combine(this.Repository.Path, this._solutionPath)); |
| 21 | + |
| 22 | + [Fact] |
| 23 | + public async Task When_project_inside_solution_has_changes_project_should_have_changed() |
| 24 | + { |
| 25 | + // Create a project |
| 26 | + var projectName = "InventoryManagement"; |
| 27 | + var msBuildProject = this.Repository.CreateCsProject(projectName); |
| 28 | + |
| 29 | + // Create a solution which includes the project |
| 30 | + await this.Repository.CreateXmlSolutionAsync(_solutionPath, msBuildProject.FullPath); |
| 31 | + |
| 32 | + Assert.Single(AffectedSummary.ProjectsWithChangedFiles); |
| 33 | + Assert.Empty(AffectedSummary.AffectedProjects); |
| 34 | + |
| 35 | + var projectInfo = AffectedSummary.ProjectsWithChangedFiles.Single(); |
| 36 | + Assert.Equal(projectName, projectInfo.GetProjectName()); |
| 37 | + Assert.Equal(msBuildProject.FullPath, projectInfo.GetFullPath()); |
| 38 | + } |
| 39 | + |
| 40 | + [Fact] |
| 41 | + public async Task When_project_inside_solution_should_ignore_changes_outside_solution() |
| 42 | + { |
| 43 | + // Create a project |
| 44 | + var projectName = "InventoryManagement"; |
| 45 | + var msBuildProject = this.Repository.CreateCsProject(projectName); |
| 46 | + |
| 47 | + // Create a solution which includes the project |
| 48 | + await this.Repository.CreateXmlSolutionAsync(_solutionPath, msBuildProject.FullPath); |
| 49 | + |
| 50 | + // Create a project that is outside the solution |
| 51 | + var outsiderproject = "OutsiderProject"; |
| 52 | + this.Repository.CreateCsProject(outsiderproject); |
| 53 | + |
| 54 | + Assert.Single(AffectedSummary.ProjectsWithChangedFiles); |
| 55 | + Assert.Empty(AffectedSummary.AffectedProjects); |
| 56 | + |
| 57 | + var projectInfo = AffectedSummary.ProjectsWithChangedFiles.Single(); |
| 58 | + Assert.Equal(projectName, projectInfo.GetProjectName()); |
| 59 | + Assert.Equal(msBuildProject.FullPath, projectInfo.GetFullPath()); |
| 60 | + } |
| 61 | + |
| 62 | + [Fact] |
| 63 | + public async Task When_project_outside_solution_has_changed_nothing_should_be_affected() |
| 64 | + { |
| 65 | + // Create a project |
| 66 | + var projectName = "InventoryManagement"; |
| 67 | + var msBuildProject = this.Repository.CreateCsProject(projectName); |
| 68 | + |
| 69 | + // Create a solution which includes the project |
| 70 | + await this.Repository.CreateXmlSolutionAsync(_solutionPath, msBuildProject.FullPath); |
| 71 | + |
| 72 | + // Commit so there are no changes |
| 73 | + this.Repository.StageAndCommit(); |
| 74 | + |
| 75 | + // Create a project that is outside the solution |
| 76 | + var outsiderName = "OutsiderProject"; |
| 77 | + this.Repository.CreateCsProject(outsiderName); |
| 78 | + |
| 79 | + Assert.Empty(AffectedSummary.AffectedProjects); |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments