Ejemplo n.º 1
0
 private void AddValidRef(string path, ProjDir proj)
 {
     new AddReferenceCommand()
     .WithProject(proj.CsProjPath)
     .Execute($"\"{path}\"")
     .Should().Pass();
 }
Ejemplo n.º 2
0
 private void AddFakeRef(string path, ProjDir proj)
 {
     new AddP2PCommand()
     .WithProject(proj.CsProjPath)
     .Execute($"--force \"{path}\"")
     .Should().Pass();
 }
Ejemplo n.º 3
0
        private static void SetTargetFrameworks(ProjDir proj, string[] frameworks)
        {
            var csproj = proj.CsProj();

            csproj.AddProperty("TargetFrameworks", string.Join(";", frameworks));
            csproj.Save();
        }
Ejemplo n.º 4
0
        private ProjDir AddLibRef(TestSetup setup, ProjDir proj, string additionalArgs = "")
        {
            var ret = GetLibRef(setup);
            new AddReferenceCommand()
                .WithWorkingDirectory(setup.TestRoot)
                .WithProject(proj.CsProjPath)
                .Execute($"{additionalArgs} \"{ret.CsProjPath}\"")
                .Should().Pass();

            return ret;
        }
Ejemplo n.º 5
0
        private ProjDir AddValidRef(TestSetup setup, ProjDir proj, string frameworkArg = "")
        {
            var ret = new ProjDir(setup.ValidRefDir);
            new AddReferenceCommand()
                .WithWorkingDirectory(setup.TestRoot)
                .WithProject(proj.CsProjPath)
                .Execute($"{frameworkArg} \"{ret.CsProjPath}\"")
                .Should().Pass();

            return ret;
        }
Ejemplo n.º 6
0
        private ProjDir AddValidRef(TestSetup setup, ProjDir proj, params string [] frameworkArgs)
        {
            var ret = new ProjDir(setup.ValidRefDir);

            new AddReferenceCommand(Log)
            .WithProject(proj.CsProjPath)
            .WithWorkingDirectory(setup.TestRoot)
            .Execute(frameworkArgs.Concat(new[] { ret.CsProjPath }))
            .Should().Pass();

            return(ret);
        }
Ejemplo n.º 7
0
        private ProjDir AddLibRef(TestSetup setup, ProjDir proj, params string[] additionalArgs)
        {
            var ret = GetLibRef(setup);

            new AddReferenceCommand(Log)
            .WithProject(proj.CsProjPath)
            .WithWorkingDirectory(setup.TestRoot)
            .Execute(additionalArgs.Concat(new[] { ret.CsProjPath }))
            .Should().Pass();

            return(ret);
        }
Ejemplo n.º 8
0
        public void WhenRefWithCondAlreadyExistsInNonUniformItemGroupItDoesntDuplicate()
        {
            var setup = Setup();
            var proj  = new ProjDir(Path.Combine(setup.TestRoot, "WithRefCondNonUniform"));

            string contentBefore = proj.CsProjContent();
            var    cmd           = new DotnetCommand(Log, "add", proj.CsProjName, "reference")
                                   .WithWorkingDirectory(proj.Path)
                                   .Execute("-f", FrameworkNet451, setup.LibCsprojRelPath);

            cmd.Should().Pass();
            cmd.StdOut.Should().Be(string.Format(CommonLocalizableStrings.ProjectAlreadyHasAreference, @"..\Lib\Lib.csproj"));
            proj.CsProjContent().Should().BeEquivalentTo(contentBefore);
        }
Ejemplo n.º 9
0
        public void WhenFrameworkSwitchIsNotMatchingAnyOfTargetedFrameworksItPrintsError(string framework)
        {
            var setup    = Setup(framework);
            var lib      = new ProjDir(setup.LibDir);
            var net45lib = new ProjDir(Path.Combine(setup.TestRoot, "Net45Lib"));

            var csProjContent = lib.CsProjContent();
            var cmd           = new DotnetCommand(Log, "add", lib.CsProjPath, "reference")
                                .Execute($"-f", framework, net45lib.CsProjPath);

            cmd.Should().Fail();
            cmd.StdErr.Should().Be(string.Format(CommonLocalizableStrings.ProjectDoesNotTargetFramework, setup.LibCsprojPath, framework));

            lib.CsProjContent().Should().BeEquivalentTo(csProjContent);
        }
Ejemplo n.º 10
0
        public void WhenRefWithCondAlreadyExistsInNonUniformItemGroupItDoesntDuplicate()
        {
            var setup = Setup();
            var proj  = new ProjDir(Path.Combine(setup.TestRoot, "WithRefCondNonUniform"));

            string contentBefore = proj.CsProjContent();
            var    cmd           = new AddReferenceCommand()
                                   .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 WhenRefWithoutCondAlreadyExistsInNonUniformItemGroupItDoesntDuplicate()
        {
            var setup = Setup();
            var proj  = new ProjDir(Path.Combine(setup.TestRoot, "WithRefNoCondNonUniform"));

            string contentBefore = proj.CsProjContent();
            var    cmd           = new AddReferenceCommand()
                                   .WithWorkingDirectory(proj.Path)
                                   .WithProject(proj.CsProjName)
                                   .Execute($"\"{setup.LibCsprojRelPath}\"");

            cmd.Should().Pass();
            cmd.StdOut.Should().Be(string.Format(CommonLocalizableStrings.ProjectAlreadyHasAreference, @"..\Lib\Lib.csproj"));
            proj.CsProjContent().Should().BeEquivalentTo(contentBefore);
        }
Ejemplo n.º 12
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 AddReferenceCommand()
                                .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);
        }
Ejemplo n.º 13
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 AddReferenceCommand()
                                .WithProject(net45lib.CsProjPath)
                                .Execute($"{frameworkArg} \"{lib.CsProjPath}\"");

            cmd.Should().Fail();
            cmd.StdErr.Should().MatchRegex(ProjectNotCompatibleErrorMessageRegEx);
            cmd.StdErr.Should().MatchRegex(" - net45");
            net45lib.CsProjContent().Should().BeEquivalentTo(csProjContent);
        }
Ejemplo n.º 14
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 DotnetCommand(Log, "add", proj.CsProjPath, "reference")
                             .WithWorkingDirectory(setup.TestRoot)
                             .Execute("-f", FrameworkNet451, setup.ValidRefCsprojPath);

            cmd.Should().Pass();
            cmd.StdOut.Should().Be(string.Format(CommonLocalizableStrings.ReferenceAddedToTheProject, "..\\ValidRef\\ValidRef.csproj"));
            var csproj = proj.CsProj();

            csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore + 1);
            csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(setup.ValidRefCsprojName, ConditionFrameworkNet451).Should().Be(1);
        }
Ejemplo n.º 15
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 DotnetCommand(Log, "add", lib.CsProjPath, "reference")
                             .Execute("-f", FrameworkNet451, net45lib.CsProjPath);

            cmd.Should().Pass();
            cmd.StdOut.Should().Be(string.Format(CommonLocalizableStrings.ReferenceAddedToTheProject, @"..\Net45Lib\Net45Lib.csproj"));
            var csproj = lib.CsProj();

            csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore + 1);
            csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(net45lib.CsProjName, ConditionFrameworkNet451).Should().Be(1);
        }
Ejemplo n.º 16
0
        public void WhenEmptyItemGroupPresentItAddsRefInIt()
        {
            var setup = Setup();
            var proj  = new ProjDir(Path.Combine(setup.TestRoot, "EmptyItemGroup"));

            int noCondBefore = proj.CsProj().NumberOfItemGroupsWithoutCondition();
            var cmd          = new DotnetCommand(Log, "add", proj.CsProjPath, "reference")
                               .WithWorkingDirectory(setup.TestRoot)
                               .Execute(setup.ValidRefCsprojPath);

            cmd.Should().Pass();
            cmd.StdOut.Should().Be(string.Format(CommonLocalizableStrings.ReferenceAddedToTheProject, @"..\ValidRef\ValidRef.csproj"));
            var csproj = proj.CsProj();

            csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore);
            csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1);
        }
Ejemplo n.º 17
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 AddReferenceCommand()
                             .WithProject(lib.CsProjPath)
                             .Execute($"{FrameworkNet451Arg} \"{net45lib.CsProjPath}\"");

            cmd.Should().Pass();
            cmd.StdOut.Should().Be("Reference `..\\Net45Lib\\Net45Lib.csproj` added to the project.");
            var csproj = lib.CsProj();

            csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore + 1);
            csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(net45lib.CsProjName, ConditionFrameworkNet451).Should().Be(1);
        }
Ejemplo n.º 18
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 AddReferenceCommand()
                               .WithProject(net452netcoreapp10lib.CsProjPath)
                               .Execute($"\"{lib.CsProjPath}\"");

            cmd.Should().Pass();
            cmd.StdOut.Should().Be("Reference `..\\Lib\\Lib.csproj` added to the project.");
            var csproj = net452netcoreapp10lib.CsProj();

            csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
            csproj.NumberOfProjectReferencesWithIncludeContaining(lib.CsProjName).Should().Be(1);
        }
Ejemplo n.º 19
0
        public void WhenEmptyItemGroupPresentItAddsRefInIt()
        {
            var setup = Setup();
            var proj  = new ProjDir(Path.Combine(setup.TestRoot, "EmptyItemGroup"));

            int noCondBefore = proj.CsProj().NumberOfItemGroupsWithoutCondition();
            var cmd          = new AddReferenceCommand()
                               .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);
            csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1);
        }
Ejemplo n.º 20
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 AddReferenceCommand()
                             .WithWorkingDirectory(setup.TestRoot)
                             .WithProject(proj.CsProjPath)
                             .Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\"");

            cmd.Should().Pass();
            cmd.StdOut.Should().Be("Reference `..\\ValidRef\\ValidRef.csproj` added to the project.");
            var csproj = proj.CsProj();

            csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore + 1);
            csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(setup.ValidRefCsprojName, ConditionFrameworkNet451).Should().Be(1);
        }
Ejemplo n.º 21
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 DotnetCommand(Log, "add", net452netcoreapp10lib.CsProjPath, "reference")
                               .Execute(lib.CsProjPath);

            cmd.Should().Pass();
            cmd.Should().Pass();
            cmd.StdOut.Should().Be(string.Format(CommonLocalizableStrings.ReferenceAddedToTheProject, @"..\Lib\Lib.csproj"));
            var csproj = net452netcoreapp10lib.CsProj();

            csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
            csproj.NumberOfProjectReferencesWithIncludeContaining(lib.CsProjName).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 AddReferenceCommand()
                               .WithWorkingDirectory(setup.TestRoot)
                               .WithProject(proj.CsProjPath)
                               .Execute($"\"{setup.ValidRefCsprojPath}\"");

            cmd.Should().Pass();
            cmd.StdOut.Should().Be(string.Format(CommonLocalizableStrings.ReferenceAddedToTheProject, @"..\ValidRef\ValidRef.csproj"));
            var csproj = proj.CsProj();

            csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
            csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1);
        }
Ejemplo n.º 23
0
        public void WhenReferenceIsRelativeAndProjectIsNotInCurrentDirectoryReferencePathIsFixed()
        {
            var setup = Setup();
            var proj  = new ProjDir(setup.LibDir);

            int noCondBefore = proj.CsProj().NumberOfItemGroupsWithoutCondition();
            var cmd          = new DotnetCommand(Log, "add", setup.LibCsprojPath, "reference")
                               .WithWorkingDirectory(setup.TestRoot)
                               .Execute(setup.ValidRefCsprojRelPath);

            cmd.Should().Pass();
            cmd.StdOut.Should().Be(string.Format(CommonLocalizableStrings.ReferenceAddedToTheProject, @"..\ValidRef\ValidRef.csproj"));
            cmd.StdErr.Should().BeEmpty();
            var csproj = proj.CsProj();

            csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
            csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojRelToOtherProjPath.Replace('/', '\\')).Should().Be(1);
        }
Ejemplo n.º 24
0
        public void WhenReferenceIsRelativeAndProjectIsNotInCurrentDirectoryReferencePathIsFixed()
        {
            var setup = Setup();
            var proj  = new ProjDir(setup.LibDir);

            int noCondBefore = proj.CsProj().NumberOfItemGroupsWithoutCondition();
            var cmd          = new AddReferenceCommand()
                               .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);
        }
Ejemplo n.º 25
0
        public void WhenDuplicateReferencesArePresentItRemovesThemAll()
        {
            var setup  = Setup();
            var proj   = new ProjDir(Path.Combine(setup.TestRoot, "WithDoubledRef"));
            var libref = GetLibRef(setup);

            int noCondBefore = proj.CsProj().NumberOfItemGroupsWithoutCondition();
            var cmd          = new RemoveP2PCommand()
                               .WithWorkingDirectory(setup.TestRoot)
                               .WithProject(proj.CsProjPath)
                               .Execute($"\"{libref.CsProjPath}\"");

            cmd.Should().Pass();
            cmd.StdOut.Should().MatchRegex("(^|[\r\n])Project reference[^\r\n]*removed.($|[\r\n])");

            var csproj = proj.CsProj();

            csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore - 1);
            csproj.NumberOfProjectReferencesWithIncludeContaining(libref.Name).Should().Be(0);
        }
Ejemplo n.º 26
0
        private ProjDir NewLib(string basePath, string testProjectName = "temp")
        {
            var dir = new ProjDir(Path.Combine(basePath, testProjectName));

            Directory.CreateDirectory(dir.Path);

            try
            {
                new DotnetCommand(Log, "new", "classlib", "-o", dir.Path, "--debug:ephemeral-hive", "--no-restore")
                .WithWorkingDirectory(dir.Path)
                .Execute()
                .Should().Pass();
            }
            catch (System.ComponentModel.Win32Exception e)
            {
                throw new Exception($"Intermittent error in `dotnet new` occurred when running it in dir `{dir.Path}`\nException:\n{e}");
            }

            return(dir);
        }
Ejemplo n.º 27
0
        public void WhenDuplicateReferencesArePresentItRemovesThemAll()
        {
            var setup = Setup();
            var proj = new ProjDir(Path.Combine(setup.TestRoot, "WithDoubledRef"));
            var libref = GetLibRef(setup);

            string removedText = $@"Project reference `{setup.LibCsprojRelPath}` removed.
Project reference `{setup.LibCsprojRelPath}` removed.";

            int noCondBefore = proj.CsProj().NumberOfItemGroupsWithoutCondition();
            var cmd = new RemoveReferenceCommand()
                .WithWorkingDirectory(setup.TestRoot)
                .WithProject(proj.CsProjPath)
                .Execute($"\"{libref.CsProjPath}\"");
            cmd.Should().Pass();
            cmd.StdOut.Should().BeVisuallyEquivalentTo(removedText);

            var csproj = proj.CsProj();
            csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore - 1);
            csproj.NumberOfProjectReferencesWithIncludeContaining(libref.Name).Should().Be(0);
        }
Ejemplo n.º 28
0
        public void WhenIncompatibleFrameworkDetectedItPrintsError(bool useFrameworkArg)
        {
            var setup    = Setup(useFrameworkArg.ToString());
            var lib      = new ProjDir(setup.LibDir);
            var net45lib = new ProjDir(Path.Combine(setup.TestRoot, "Net45Lib"));

            List <string> args = new List <string>();

            if (useFrameworkArg)
            {
                args.Add("-f");
                args.Add("net45");
            }
            args.Add(lib.CsProjPath);

            var csProjContent = net45lib.CsProjContent();
            var cmd           = new DotnetCommand(Log, "add", net45lib.CsProjPath, "reference")
                                .Execute(args);

            cmd.Should().Fail();
            cmd.StdErr.Should().MatchRegex(ProjectNotCompatibleErrorMessageRegEx);
            cmd.StdErr.Should().MatchRegex(" - net45");
            net45lib.CsProjContent().Should().BeEquivalentTo(csProjContent);
        }
Ejemplo n.º 29
0
 private void AddValidRef(string path, ProjDir proj)
 {
     new DotnetCommand(Log, "add", proj.CsProjPath, "reference")
     .Execute(path)
     .Should().Pass();
 }