private static void SetTargetFrameworks(ProjDir proj, string[] frameworks) { var csproj = proj.CsProj(); csproj.AddProperty("TargetFrameworks", string.Join(";", frameworks)); csproj.Save(); }
public void WhenRefWithCondAlreadyExistsInNonUniformItemGroupItDoesntDuplicate() { var setup = Setup(); var proj = new ProjDir(Path.Combine(setup.TestRoot, "WithRefCondNonUniform")); string contentBefore = proj.CsProjContent(); var cmd = new AddP2PCommand() .WithWorkingDirectory(proj.Path) .WithProject(proj.CsProjName) .Execute($"{FrameworkNet451Arg} \"{setup.LibCsprojRelPath}\""); cmd.Should().Pass(); cmd.StdOut.Should().Contain("already has a reference"); proj.CsProjContent().Should().BeEquivalentTo(contentBefore); }
public void WhenRefWithCondWithWhitespaceOnItemGroupExistsItDoesntDuplicate() { var setup = Setup(); var proj = new ProjDir(Path.Combine(setup.TestRoot, "WithExistingRefCondWhitespaces")); string contentBefore = proj.CsProjContent(); var cmd = new AddP2PCommand() .WithWorkingDirectory(proj.Path) .WithProject(proj.CsProjName) .Execute($"{FrameworkNet451Arg} \"{setup.LibCsprojRelPath}\""); cmd.Should().Pass(); cmd.StdOut.Should().Be("Project already has a reference to `..\\Lib\\Lib.csproj`."); proj.CsProjContent().Should().BeEquivalentTo(contentBefore); }
public void WhenIncompatibleFrameworkDetectedItPrintsError(string frameworkArg) { var setup = Setup(); var lib = new ProjDir(setup.LibDir); var net45lib = new ProjDir(Path.Combine(setup.TestRoot, "Net45Lib")); var csProjContent = net45lib.CsProjContent(); var cmd = new AddP2PCommand() .WithProject(net45lib.CsProjPath) .Execute($"{frameworkArg} \"{lib.CsProjPath}\""); cmd.Should().Fail(); cmd.StdErr.Should().MatchRegex(ProjectNotCompatibleErrorMessageRegEx); cmd.StdErr.Should().MatchRegex(" - net45(\n|\r)"); net45lib.CsProjContent().Should().BeEquivalentTo(csProjContent); }
public void WhenFrameworkSwitchIsNotMatchingAnyOfTargetedFrameworksItPrintsError(string framework) { var setup = Setup(); var lib = new ProjDir(setup.LibDir); var net45lib = new ProjDir(Path.Combine(setup.TestRoot, "Net45Lib")); var csProjContent = lib.CsProjContent(); var cmd = new AddP2PCommand() .WithProject(lib.CsProjPath) .Execute($"-f {framework} \"{net45lib.CsProjPath}\""); cmd.Should().Fail(); cmd.StdErr.Should().MatchRegex(ProjectDoesNotTargetFrameworkErrorMessageRegEx); cmd.StdErr.Should().Contain($"`{framework}`"); lib.CsProjContent().Should().BeEquivalentTo(csProjContent); }
public void WhenFrameworkSwitchIsNotMatchingAnyOfTargetedFrameworksItPrintsError(string framework) { var setup = Setup(); var lib = new ProjDir(setup.LibDir); var net45lib = new ProjDir(Path.Combine(setup.TestRoot, "Net45Lib")); var csProjContent = lib.CsProjContent(); var cmd = new AddP2PCommand() .WithProject(lib.CsProjPath) .Execute($"-f {framework} \"{net45lib.CsProjPath}\""); cmd.Should().Fail(); cmd.StdErr.Should().Be($"Project `{setup.LibCsprojPath}` does not target framework `{framework}`."); lib.CsProjContent().Should().BeEquivalentTo(csProjContent); }
public void ItCanAddRefWithoutCondAndTargetingSupersetOfFrameworksAndOneOfReferencesCompatible() { var setup = Setup(); var lib = new ProjDir(setup.LibDir); var net452netcoreapp10lib = new ProjDir(Path.Combine(setup.TestRoot, "Net452AndNetCoreApp10Lib")); int noCondBefore = net452netcoreapp10lib.CsProj().NumberOfItemGroupsWithoutCondition(); var cmd = new AddP2PCommand() .WithProject(net452netcoreapp10lib.CsProjPath) .Execute($"\"{lib.CsProjPath}\""); cmd.Should().Pass(); cmd.StdOut.Should().Contain("added to the project"); var csproj = net452netcoreapp10lib.CsProj(); csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1); csproj.NumberOfProjectReferencesWithIncludeContaining(lib.CsProjName).Should().Be(1); }
public void ItCanAddReferenceWithConditionOnCompatibleFramework() { var setup = Setup(); var lib = new ProjDir(setup.LibDir); var net45lib = new ProjDir(Path.Combine(setup.TestRoot, "Net45Lib")); int condBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451); var cmd = new AddP2PCommand() .WithProject(lib.CsProjPath) .Execute($"{FrameworkNet451Arg} \"{net45lib.CsProjPath}\""); cmd.Should().Pass(); cmd.StdOut.Should().Contain("added to the project"); var csproj = lib.CsProj(); csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore + 1); csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(net45lib.CsProjName, ConditionFrameworkNet451).Should().Be(1); }
public void WhenEmptyItemGroupPresentItAddsRefInIt() { var setup = Setup(); var proj = new ProjDir(Path.Combine(setup.TestRoot, "EmptyItemGroup")); int noCondBefore = proj.CsProj().NumberOfItemGroupsWithoutCondition(); var cmd = new AddP2PCommand() .WithWorkingDirectory(setup.TestRoot) .WithProject(proj.CsProjPath) .Execute($"\"{setup.ValidRefCsprojPath}\""); cmd.Should().Pass(); cmd.StdOut.Should().Contain("added to the project"); var csproj = proj.CsProj(); csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore); csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1); }
public void WhenRefWithCondAlreadyExistsInNonUniformItemGroupItAddsDifferentRefInDifferentGroup() { var setup = Setup(); var proj = new ProjDir(Path.Combine(setup.TestRoot, "WithRefCondNonUniform")); int condBefore = proj.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451); var cmd = new AddP2PCommand() .WithWorkingDirectory(setup.TestRoot) .WithProject(proj.CsProjPath) .Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\""); cmd.Should().Pass(); cmd.StdOut.Should().Contain("added to the project"); var csproj = proj.CsProj(); csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore + 1); csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(setup.ValidRefCsprojName, ConditionFrameworkNet451).Should().Be(1); }
public void WhenRefWithoutCondAlreadyExistsInNonUniformItemGroupItAddsDifferentRefInDifferentGroup() { var setup = Setup(); var proj = new ProjDir(Path.Combine(setup.TestRoot, "WithRefNoCondNonUniform")); int noCondBefore = proj.CsProj().NumberOfItemGroupsWithoutCondition(); var cmd = new AddP2PCommand() .WithWorkingDirectory(setup.TestRoot) .WithProject(proj.CsProjPath) .Execute($"\"{setup.ValidRefCsprojPath}\""); cmd.Should().Pass(); cmd.StdOut.Should().Be("Reference `..\\ValidRef\\ValidRef.csproj` added to the project."); var csproj = proj.CsProj(); csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1); csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1); }
public void WhenReferenceIsRelativeAndProjectIsNotInCurrentDirectoryAndForceSwitchIsPassedItDoesNotChangeIt() { var setup = Setup(); var proj = new ProjDir(setup.LibDir); int noCondBefore = proj.CsProj().NumberOfItemGroupsWithoutCondition(); var cmd = new AddP2PCommand() .WithWorkingDirectory(setup.TestRoot) .WithProject(setup.LibCsprojPath) .Execute($"--force \"{setup.ValidRefCsprojRelPath}\""); cmd.Should().Pass(); cmd.StdOut.Should().Contain("added to the project"); cmd.StdErr.Should().BeEmpty(); var csproj = proj.CsProj(); csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1); csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojRelPath.Replace('/', '\\')).Should().Be(1); }
public void WhenReferenceIsRelativeAndProjectIsNotInCurrentDirectoryReferencePathIsFixed() { var setup = Setup(); var proj = new ProjDir(setup.LibDir); int noCondBefore = proj.CsProj().NumberOfItemGroupsWithoutCondition(); var cmd = new AddP2PCommand() .WithWorkingDirectory(setup.TestRoot) .WithProject(setup.LibCsprojPath) .Execute($"\"{setup.ValidRefCsprojRelPath}\""); cmd.Should().Pass(); cmd.StdOut.Should().Be("Reference `..\\ValidRef\\ValidRef.csproj` added to the project."); cmd.StdErr.Should().BeEmpty(); var csproj = proj.CsProj(); csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1); csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojRelToOtherProjPath.Replace('/', '\\')).Should().Be(1); }