Beispiel #1
0
        public void WhenHelpOptionIsPassedItPrintsUsage(string helpArg)
        {
            var cmd = new AddP2PCommand().Execute(helpArg);

            cmd.Should().Pass();
            cmd.StdOut.Should().Contain("Usage");
        }
Beispiel #2
0
        public void WhenRefWithNoCondAlreadyExistsItDoesntDuplicate()
        {
            var lib   = NewLibWithFrameworks();
            var setup = Setup();

            new AddP2PCommand()
            .WithWorkingDirectory(setup.TestRoot)
            .WithProject(lib.CsProjPath)
            .Execute($"\"{setup.ValidRefCsprojPath}\"")
            .Should().Pass();

            int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
            var cmd          = new AddP2PCommand()
                               .WithWorkingDirectory(lib.Path)
                               .WithProject(lib.CsProjName)
                               .Execute($"\"{setup.ValidRefCsprojPath}\"");

            cmd.Should().Pass();
            cmd.StdOut.Should().Contain("already has a reference");

            var csproj = lib.CsProj();

            csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore);
            csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1);
        }
Beispiel #3
0
        public void WhenTooManyArgumentsArePassedItPrintsError()
        {
            var cmd = new AddP2PCommand()
                      .WithProject("one two three")
                      .Execute("proj.csproj");

            cmd.ExitCode.Should().NotBe(0);
            cmd.StdErr.Should().Contain("Unrecognized command or argument");
        }
Beispiel #4
0
        public void WhenTooManyArgumentsArePassedItPrintsError()
        {
            var cmd = new AddP2PCommand()
                      .WithProject("one two three")
                      .Execute("proj.csproj");

            cmd.ExitCode.Should().NotBe(0);
            cmd.StdErr.Should().Be("Unrecognized command or argument 'two'");
            cmd.StdOut.Should().Be("Specify --help for a list of available options and commands.");
        }
Beispiel #5
0
        public void WhenNoProjectsExistsInTheDirectoryItPrintsErrorAndUsage()
        {
            var setup = Setup();

            var cmd = new AddP2PCommand()
                      .WithWorkingDirectory(setup.TestRoot)
                      .Execute($"\"{setup.ValidRefCsprojPath}\"");

            cmd.ExitCode.Should().NotBe(0);
            cmd.StdErr.Should().Contain("not find any");
            cmd.StdOut.Should().Contain("Usage");
        }
Beispiel #6
0
        public void WhenNoProjectsExistsInTheDirectoryItPrintsErrorAndUsage()
        {
            var setup = Setup();

            var cmd = new AddP2PCommand()
                      .WithWorkingDirectory(setup.TestRoot)
                      .Execute($"\"{setup.ValidRefCsprojPath}\"");

            cmd.ExitCode.Should().NotBe(0);
            cmd.StdErr.Should().Be($"Could not find any project in `{setup.TestRoot + Path.DirectorySeparatorChar}`.");
            cmd.StdOut.Should().Be(HelpText);
        }
Beispiel #7
0
        public void WhenMoreThanOneProjectExistsInTheDirectoryItPrintsErrorAndUsage()
        {
            var setup = Setup();

            var cmd = new AddP2PCommand()
                      .WithWorkingDirectory(Path.Combine(setup.TestRoot, "MoreThanOne"))
                      .Execute($"\"{setup.ValidRefCsprojRelToOtherProjPath}\"");

            cmd.ExitCode.Should().NotBe(0);
            cmd.StdErr.Should().Contain("more than one");
            cmd.StdOut.Should().Contain("Usage");
        }
Beispiel #8
0
        public void WhenMoreThanOneProjectExistsInTheDirectoryItPrintsErrorAndUsage()
        {
            var setup = Setup();

            var workingDir = Path.Combine(setup.TestRoot, "MoreThanOne");
            var cmd        = new AddP2PCommand()
                             .WithWorkingDirectory(workingDir)
                             .Execute($"\"{setup.ValidRefCsprojRelToOtherProjPath}\"");

            cmd.ExitCode.Should().NotBe(0);
            cmd.StdErr.Should().Be($"Found more than one project in `{workingDir + Path.DirectorySeparatorChar}`. Please specify which one to use.");
            cmd.StdOut.Should().Be(HelpText);
        }
Beispiel #9
0
        public void WhenNonExistingProjectIsPassedItPrintsErrorAndUsage(string projName)
        {
            var setup = Setup();

            var cmd = new AddP2PCommand()
                      .WithWorkingDirectory(setup.TestRoot)
                      .WithProject(projName)
                      .Execute($"\"{setup.ValidRefCsprojPath}\"");

            cmd.ExitCode.Should().NotBe(0);
            cmd.StdErr.Should().Contain("Could not find");
            cmd.StdOut.Should().Contain("Usage");
        }
Beispiel #10
0
        public void WhenPassedReferenceDoesNotExistItShowsAnError()
        {
            var lib = NewLibWithFrameworks();

            var contentBefore = lib.CsProjContent();
            var cmd           = new AddP2PCommand()
                                .WithWorkingDirectory(lib.Path)
                                .WithProject(lib.CsProjName)
                                .Execute("\"IDoNotExist.csproj\"");

            cmd.Should().Fail();
            cmd.StdErr.Should().Contain("does not exist");
            lib.CsProjContent().Should().BeEquivalentTo(contentBefore);
        }
Beispiel #11
0
        public void WhenBrokenProjectIsPassedItPrintsErrorAndUsage()
        {
            string projName = "Broken/Broken.csproj";
            var    setup    = Setup();

            var cmd = new AddP2PCommand()
                      .WithWorkingDirectory(setup.TestRoot)
                      .WithProject(projName)
                      .Execute($"\"{setup.ValidRefCsprojPath}\"");

            cmd.ExitCode.Should().NotBe(0);
            cmd.StdErr.Should().Contain(" is invalid.");
            cmd.StdOut.Should().Contain("Usage");
        }
Beispiel #12
0
        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);
        }
Beispiel #13
0
        public void WhenPassedMultipleRefsAndOneOfthemDoesNotExistItCancelsWholeOperation()
        {
            var lib   = NewLibWithFrameworks();
            var setup = Setup();

            var contentBefore = lib.CsProjContent();
            var cmd           = new AddP2PCommand()
                                .WithWorkingDirectory(setup.TestRoot)
                                .WithProject(lib.CsProjPath)
                                .Execute($"\"{setup.ValidRefCsprojPath}\" \"IDoNotExist.csproj\"");

            cmd.Should().Fail();
            cmd.StdErr.Should().Be("Reference IDoNotExist.csproj does not exist.");
            lib.CsProjContent().Should().BeEquivalentTo(contentBefore);
        }
Beispiel #14
0
        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);
        }
Beispiel #15
0
        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);
        }
Beispiel #16
0
        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);
        }
Beispiel #17
0
        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);
        }
Beispiel #18
0
        public void ItAddsRefBetweenImports()
        {
            var lib   = NewLibWithFrameworks();
            var setup = Setup();

            var cmd = new AddP2PCommand()
                      .WithWorkingDirectory(lib.Path)
                      .WithProject(lib.CsProjName)
                      .Execute($"\"{setup.ValidRefCsprojPath}\"");

            cmd.Should().Pass();
            cmd.StdOut.Should().Contain("added to the project");
            cmd.StdErr.Should().BeEmpty();

            int state = 0;

            foreach (var el in lib.CsProj().AllChildren)
            {
                var import  = el as ProjectImportElement;
                var projRef = el as ProjectItemElement;
                switch (state)
                {
                case 0:
                    if (import != null && import.Project.EndsWith(".props"))
                    {
                        state++;
                    }
                    break;

                case 1:
                    if (projRef != null && projRef.ItemType == "ProjectReference" && projRef.Include.Contains(setup.ValidRefCsprojName))
                    {
                        state++;
                    }
                    break;

                case 2:
                    if (import != null && import.Project.EndsWith(".targets"))
                    {
                        state++;
                    }
                    break;
                }
            }

            state.Should().Be(3);
        }
Beispiel #19
0
        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);
        }
Beispiel #20
0
        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);
        }
Beispiel #21
0
        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);
        }
Beispiel #22
0
        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);
        }
Beispiel #23
0
        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);
        }
Beispiel #24
0
        public void WhenProjectNameIsNotPassedItFindsItAndAddsReference()
        {
            var lib   = NewLibWithFrameworks();
            var setup = Setup();

            int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
            var cmd          = new AddP2PCommand()
                               .WithWorkingDirectory(lib.Path)
                               .Execute($"\"{setup.ValidRefCsprojPath}\"");

            cmd.Should().Pass();
            cmd.StdOut.Should().Contain("added to the project");
            cmd.StdErr.Should().BeEmpty();
            var csproj = lib.CsProj();

            csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
            csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1);
        }
Beispiel #25
0
        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);
        }
Beispiel #26
0
        public void ItAddsRefWithCondAndPrintsStatus()
        {
            var lib   = NewLibWithFrameworks();
            var setup = Setup();

            int condBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
            var cmd        = new AddP2PCommand()
                             .WithWorkingDirectory(setup.TestRoot)
                             .WithProject(lib.CsProjPath)
                             .Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\"");

            cmd.Should().Pass();
            cmd.StdOut.Should().Contain("added to the project");
            cmd.StdErr.Should().BeEmpty();
            var csproj = lib.CsProj();

            csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore + 1);
            csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(setup.ValidRefCsprojName, ConditionFrameworkNet451).Should().Be(1);
        }
Beispiel #27
0
        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);
        }
Beispiel #28
0
        public void WhenPassedReferenceIsUsingSlashesItNormalizesItToBackslashes()
        {
            var lib   = NewLibWithFrameworks();
            var setup = Setup();

            int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
            var cmd          = new AddP2PCommand()
                               .WithWorkingDirectory(lib.Path)
                               .WithProject(lib.CsProjName)
                               .Execute($"--force \"{setup.ValidRefCsprojPath.Replace('\\', '/')}\"");

            cmd.Should().Pass();
            cmd.StdOut.Should().Contain("added to the project");
            cmd.StdErr.Should().BeEmpty();
            var csproj = lib.CsProj();

            csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
            csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojPath.Replace('/', '\\')).Should().Be(1);
        }
Beispiel #29
0
        public void WhenPassedReferenceDoesNotExistAndForceSwitchIsPassedItAddsIt()
        {
            var          lib         = NewLibWithFrameworks();
            const string nonExisting = "IDoNotExist.csproj";

            int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
            var cmd          = new AddP2PCommand()
                               .WithWorkingDirectory(lib.Path)
                               .WithProject(lib.CsProjName)
                               .Execute($"--force \"{nonExisting}\"");

            cmd.Should().Pass();
            cmd.StdOut.Should().Contain("added to the project");
            cmd.StdErr.Should().BeEmpty();
            var csproj = lib.CsProj();

            csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
            csproj.NumberOfProjectReferencesWithIncludeContaining(nonExisting).Should().Be(1);
        }
Beispiel #30
0
        public void ItAddsMultipleRefsWithCondToTheSameItemGroup()
        {
            var lib   = NewLibWithFrameworks();
            var setup = Setup();

            int noCondBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
            var cmd          = new AddP2PCommand()
                               .WithWorkingDirectory(setup.TestRoot)
                               .WithProject(lib.CsProjPath)
                               .Execute($"{FrameworkNet451Arg}  \"{setup.LibCsprojPath}\" \"{setup.ValidRefCsprojPath}\"");

            cmd.Should().Pass();
            cmd.StdOut.Should().Contain("added to the project").And.NotContain("already has a reference");
            var csproj = lib.CsProj();

            csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(noCondBefore + 1);
            csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(setup.ValidRefCsprojName, ConditionFrameworkNet451).Should().Be(1);
            csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(setup.LibCsprojName, ConditionFrameworkNet451).Should().Be(1);
        }