예제 #1
0
        public void CanAddFileReferenceWhenNoReferencesExist()
        {
            var project = CreateDefaultProject();

            Solution.Projects.Add(project);

            var request = new AddReferenceRequest
            {
                Reference = @"c:\test\packages\SomeTest\lib\net40\Some.Test.dll",
                FileName = @"c:\test\one\test.cs"
            };

            var expectedXml = XDocument.Parse(@"
                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Test.cs""/>
                    </ItemGroup>
                    <ItemGroup>
                        <Reference Include=""Some.Test"">
                            <HintPath>..\packages\SomeTest\lib\net40\Some.Test.dll</HintPath>
                        </Reference>
                    </ItemGroup>
                </Project>");

            var handler = new AddReferenceHandler(Solution, new AddReferenceProcessorFactory(Solution, new IReferenceProcessor[] { new AddFileReferenceProcessor() }, new FakeFileSystem()));
            handler.AddReference(request);

            project.AsXml().ToString().ShouldEqual(expectedXml.ToString());
			((FakeAssembly)project.References.First(r => r.GetType() == typeof(FakeAssembly))).AssemblyPath.ForceWindowsPathSeparator().ShouldEqual(@"c:\test\packages\SomeTest\lib\net40\Some.Test.dll");
        }
예제 #2
0
        public AddReferenceResponse AddReference(AddReferenceRequest request)
        {
            var project   = _solution.ProjectContainingFile(request.FileName);
            var processor = _addReferenceProcessorFactory.CreateProcessorFor(request);

            return(processor.AddReference(project, request.Reference));
        }
예제 #3
0
        public void WillNotAddDuplicateGacAssemblyReference()
        {
            var project = CreateDefaultProjectWithGacReference();
            Solution.Projects.Add(project);

            var expectedXml = XDocument.Parse(@"
                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Test.cs""/>
                    </ItemGroup>
                    <ItemGroup>
                        <Reference Include=""System.Web.Mvc"" />
                    </ItemGroup>
                </Project>");

            var request = new AddReferenceRequest
            {
                Reference = @"System.Web.Mvc",
                FileName = @"c:\test\one\test.cs"
            };

            var handler = new AddReferenceHandler(Solution, new AddReferenceProcessorFactory(Solution, new IReferenceProcessor[] { new AddGacReferenceProcessor() }, new FileSystem()));
            handler.AddReference(request);

            project.AsXml().ToString().ShouldEqual(expectedXml.ToString());
        }
         public void CanAddGacAssemblyReference()
         {
            var project = GetProject(
                @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Test.cs""/>
                    </ItemGroup>
                </Project>");
             Solution.Projects.Add(project);

            var path = 
                _fs.Path.Combine(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5", "System.Web.Mvc.dll");
            _fs.File.WriteAllText(path, "");
             const string expectedXml = @"
                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Test.cs""/>
                    </ItemGroup>
                    <ItemGroup>
                        <Reference Include=""System.Web.Mvc"" />
                    </ItemGroup>
                </Project>";

             var request = new AddReferenceRequest
             {
                 Reference = @"System.Web.Mvc",
                 FileName = @"c:\test\one\test.cs"
             };

             var handler = new AddReferenceHandler(Solution, new AddReferenceProcessorFactory(Solution, new IReferenceProcessor[]{new AddGacReferenceProcessor() }, new NativeFileSystem()));
             var response = handler.AddReference(request);
            response.Message.ShouldEqual("Reference to System.Web.Mvc added successfully");
            _fs.File.ReadAllText(project.FileName).ShouldEqualXml(expectedXml);
         }
예제 #5
0
        public AddReferenceResponse AddReference(AddReferenceRequest request)
        {
            var project = _solution.ProjectContainingFile(request.FileName);
           
            var processor = _addReferenceProcessorFactory.CreateProcessorFor(request);

            return processor.AddReference(project, request.Reference);
           
        }
        public void ShouldReturnAddGacReferenceProcessorWhenReferencingGac()
        {
            var request = new AddReferenceRequest
            {
                Reference = "System.Web.Mvc"
            };

            var processor = _factory.CreateProcessorFor(request);

            processor.ShouldBeType<AddGacReferenceProcessor>();
        }
        public void ShouldReturnAddProjectReferenceProcessorWhenReferencingProject()
        {
            var request = new AddReferenceRequest
                              {
                                  Reference = "fake"
                              };

            var processor = _factory.CreateProcessorFor(request);

            processor.ShouldBeType<AddProjectReferenceProcessor>();
        }
        public void ShouldReturnAddFileReferenceProcessorWhenReferencingFile()
        {
            var request = new AddReferenceRequest
                              {
                                  Reference = "Nancy.dll"
                              };

            var processor = _factory.CreateProcessorFor(request);

            processor.ShouldBeType<AddFileReferenceProcessor>();
        }
        public void ShouldReturnAddGacReferenceProcessorWhenFileReferenceNotFound()
        {
            var fs = new FakeFileSystem();
            fs.FileExists(false);
            _factory = new AddReferenceProcessorFactory(_solution, _processors, fs);
            var request = new AddReferenceRequest
            {
                Reference = "Nancy.dll"
            };

            var processor = _factory.CreateProcessorFor(request);
            processor.ShouldBeType<AddGacReferenceProcessor>();
        }
예제 #10
0
        public IReferenceProcessor CreateProcessorFor(AddReferenceRequest request)
        {
            if (IsProjectReference(request.Reference))
            {
                return(_processors[typeof(AddProjectReferenceProcessor)]);
            }

            if (IsFileReference(request.Reference))
            {
                return(_processors[typeof(AddFileReferenceProcessor)]);
            }

            return(_processors[typeof(AddGacReferenceProcessor)]);
        }
        public IReferenceProcessor CreateProcessorFor(AddReferenceRequest request)
        {
            if (IsProjectReference(request.Reference))
            {
                return _processors[typeof (AddProjectReferenceProcessor)];
            }

            if (IsFileReference(request.Reference))
            {
                return _processors[typeof (AddFileReferenceProcessor)];
            }

            return _processors[typeof (AddGacReferenceProcessor)];
        }
        public void CanAddFileReference()
        {
            var project = GetProject(
                @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Test.cs""/>
                    </ItemGroup>
                    <ItemGroup>
                        <Reference Include=""Hello.World"">
                            <HintPath>..\packages\HelloWorld\lib\net40\Does.Not.Exist.dll</HintPath>
                        </Reference>
                    </ItemGroup>
                </Project>");

            Solution.Projects.Add(project);

            var request = new AddReferenceRequest
            {
                Reference = @"c:\test\packages\SomeTest\lib\net40\Some.Test.dll",
                FileName = @"c:\test\one\test.cs"
            };

            const string expectedXml = @"
                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Test.cs""/>
                    </ItemGroup>
                    <ItemGroup>
                        <Reference Include=""Hello.World"">
                            <HintPath>..\packages\HelloWorld\lib\net40\Does.Not.Exist.dll</HintPath>
                        </Reference>
                        <Reference Include=""Some.Test"">
                            <HintPath>..\packages\SomeTest\lib\net40\Some.Test.dll</HintPath>
                        </Reference>
                    </ItemGroup>
                </Project>";

            var handler = new AddReferenceHandler(Solution, new AddReferenceProcessorFactory(Solution, new IReferenceProcessor[] { new AddFileReferenceProcessor() }, new FakeWindowsFileSystem()));
            handler.AddReference(request);

            _fs.File.ReadAllText(project.FileName).ShouldEqualXml(expectedXml);

            project.References.Select(r => ((DefaultUnresolvedAssembly)r).AssemblyName)
                .ShouldContain(@"c:\test\packages\SomeTest\lib\net40\Some.Test.dll");
        }
예제 #13
0
        public void CanAddProjectReferenceWhenNoProjectReferencesExist()
        {
            var projectOne = GetProject(
                                 @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Test.cs""/>
                    </ItemGroup>
                </Project>");
            projectOne.Title = "Project One";
            projectOne.ProjectId = Guid.NewGuid();
                
            var projectTwo = GetProject(
                                 @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Test.cs""/>
                    </ItemGroup>
                </Project>", @"c:\test\two\fake2.csproj");

            _solution.Projects.Add(projectOne);
            _solution.Projects.Add(projectTwo);

            projectTwo.Files.Add(new CSharpFile(projectTwo, @"c:\test\two\test.cs", "some c# code"));
            var request = new AddReferenceRequest
            {
                Reference = @"fake1",
                FileName = @"c:\test\two\test.cs"
            };

            var handler = new AddReferenceHandler(_solution, new AddReferenceProcessorFactory(_solution, new IReferenceProcessor[] { new AddProjectReferenceProcessor(_solution) }, new NativeFileSystem()));
            handler.AddReference(request);

            var expectedXml = string.Format(@"
                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Test.cs""/>
                    </ItemGroup>
                    <ItemGroup>
                        <ProjectReference Include=""..\one\fake1.csproj"">
                            <Project>{{{0}}}</Project>
                            <Name>Project One</Name>
                        </ProjectReference>
                    </ItemGroup>
                </Project>", projectOne.ProjectId.ToString().ToUpperInvariant());
            _fs.File.ReadAllText(projectTwo.FileName).ShouldEqualXml(expectedXml);
        }
예제 #14
0
        public void CanAddProjectReferenceWhenNoProjectReferencesExist()
        {
            var projectOne = CreateDefaultProject();

            var projectTwoId = Guid.NewGuid();
            var projectTwo = new FakeProject("faketwo", @"c:\test\two\fake2.csproj", projectTwoId);
            projectTwo.Title = "Project Two";
            projectTwo.AddFile("some content", @"c:\test\two\test.cs");
            projectTwo.XmlRepresentation = XDocument.Parse(@"
                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Test.cs""/>
                    </ItemGroup>
                </Project>");

            var expectedXml = XDocument.Parse(string.Format(@"
                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Test.cs""/>
                    </ItemGroup>
                    <ItemGroup>
                        <ProjectReference Include=""..\one\fake1.csproj"">
                            <Project>{0}</Project>
                            <Name>Project One</Name>
                        </ProjectReference>
                    </ItemGroup>
                </Project>", string.Concat("{", projectOne.ProjectId.ToString().ToUpperInvariant(), "}")));

            Solution.Projects.Add(projectOne);
            Solution.Projects.Add(projectTwo);

            var request = new AddReferenceRequest
                {
                    Reference = @"fake1",
                    FileName = @"c:\test\two\test.cs"
                };

            var handler = new AddReferenceHandler(Solution, new AddReferenceProcessorFactory(Solution, new IReferenceProcessor[] { new AddProjectReferenceProcessor(Solution) }, new NativeFileSystem()));
            handler.AddReference(request);

            projectTwo.AsXml().ToString().ShouldEqual(expectedXml.ToString());
        }
        public void ShouldNotAddGacReferenceThatDoesNotExist()
        {
            const string xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Test.cs""/>
                    </ItemGroup>
                </Project>";

            var project = GetProject(xml);
            Solution.Projects.Add(project);

            var request = new AddReferenceRequest
            {
                Reference = @"System.Web.Mvc",
                FileName = @"c:\test\one\test.cs"
             };

            var handler = new AddReferenceHandler(Solution, new AddReferenceProcessorFactory(Solution, new IReferenceProcessor[]{new AddGacReferenceProcessor() }, new NativeFileSystem()));
            var response = handler.AddReference(request);
            response.Message.ShouldEqual("Did not find System.Web.Mvc");
            _fs.File.ReadAllText(project.FileName).ShouldEqualXml(xml);
        }
        public void ShouldNotAddDuplicateFileReference()
        {
            var project = GetProject(
                @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Test.cs""/>
                    </ItemGroup>
                    <ItemGroup>
                        <Reference Include=""Hello.World"">
                            <HintPath>..\packages\HelloWorld\lib\net40\Hello.World.dll</HintPath>
                        </Reference>
                    </ItemGroup>
                </Project>");

            Solution.Projects.Add(project);

            var request = new AddReferenceRequest
            {
                Reference = @"c:\test\packages\HelloWorld\lib\net40\Hello.World.dll",
                FileName = @"c:\test\one\test.cs"
            };

            const string expectedXml = @"
                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Test.cs""/>
                    </ItemGroup>
                    <ItemGroup>
                        <Reference Include=""Hello.World"">
                            <HintPath>..\packages\HelloWorld\lib\net40\Hello.World.dll</HintPath>
                        </Reference>
                    </ItemGroup>
                </Project>";

            var handler = new AddReferenceHandler(Solution, new AddReferenceProcessorFactory(Solution, new IReferenceProcessor[] { new AddFileReferenceProcessor() }, new FakeFileSystem()));
            handler.AddReference(request);
            _fs.File.ReadAllText(project.FileName).ShouldEqualXml(expectedXml);
        }
예제 #17
0
        public void ShouldNotAddCircularReference()
        {
            var projectOne = GetProject(
                                 @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                                     <ItemGroup>
                                         <Compile Include=""Test.cs""/>
                                     </ItemGroup>
                                 </Project>");
            var xml = string.Format(@"
                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Test.cs""/>
                    </ItemGroup>
                    <ItemGroup>
                        <ProjectReference Include=""..\one\fake1.csproj"">
                            <Project>{0}</Project>
                            <Name>Project One</Name>
                        </ProjectReference>
                    </ItemGroup>
                </Project>", string.Concat("{", projectOne.ProjectId.ToString().ToUpperInvariant(), "}"));
            var projectTwo = GetProject(xml, @"c:\test\two\fake2.csproj");
            projectTwo.Title = "Project Two";
            projectTwo.Files.Add(new CSharpFile(projectTwo, @"c:\test\two\test.cs", "some c# code"));
            projectTwo.AddReference(new ProjectReference(_solution, "Project One", projectOne.ProjectId));


            var expectedXml = XDocument.Parse(xml);
            
            _solution.Projects.Add(projectOne);
            _solution.Projects.Add(projectTwo);

            var request = new AddReferenceRequest
            {
                Reference = @"fake2",
                FileName = @"c:\test\one\test.cs"
            };

            var handler = new AddReferenceHandler(_solution, new AddReferenceProcessorFactory(_solution, new IReferenceProcessor[] { new AddProjectReferenceProcessor(_solution) }, new NativeFileSystem()));
            var response = handler.AddReference(request);

            projectTwo.AsXml().ToString().ShouldEqual(expectedXml.ToString());
            response.Message.ShouldEqual("Reference will create circular dependency");
        }
        public void WillNotAddDuplicateGacAssemblyReference()
        {
            var project = GetProject(
                @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Test.cs""/>
                    </ItemGroup>
                    <ItemGroup>
                        <Reference Include=""System.Web.Mvc"" />
                    </ItemGroup>
                </Project>");

            Solution.Projects.Add(project);

            const string expectedXml = @"
                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Test.cs""/>
                    </ItemGroup>
                    <ItemGroup>
                        <Reference Include=""System.Web.Mvc"" />
                    </ItemGroup>
                </Project>";

            var request = new AddReferenceRequest
            {
                Reference = @"System.Web.Mvc",
                FileName = @"c:\test\one\test.cs"
            };

            var handler = new AddReferenceHandler(Solution, new AddReferenceProcessorFactory(Solution, new IReferenceProcessor[] { new AddGacReferenceProcessor() }, new NativeFileSystem()));
            handler.AddReference(request);
            _fs.File.ReadAllText(project.FileName).ShouldEqualXml(expectedXml);
        }
예제 #19
0
        public void ShouldNotAddDuplicateFileReference()
        {
            var project = CreateDefaultProjectWithFileReference();

            Solution.Projects.Add(project);

            var request = new AddReferenceRequest
            {
                Reference = @"c:\test\packages\HelloWorld\lib\net40\Hello.World.dll",
                FileName = @"c:\test\one\test.cs"
            };

            var expectedXml = XDocument.Parse(@"
                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Test.cs""/>
                    </ItemGroup>
                    <ItemGroup>
                        <Reference Include=""Hello.World"">
                            <HintPath>..\packages\HelloWorld\lib\net40\Hello.World.dll</HintPath>
                        </Reference>
                    </ItemGroup>
                </Project>");

            var handler = new AddReferenceHandler(Solution, new AddReferenceProcessorFactory(Solution, new IReferenceProcessor[] { new AddFileReferenceProcessor() }, new FakeFileSystem()));
            handler.AddReference(request);

            project.AsXml().ToString().ShouldEqual(expectedXml.ToString());
            project.References.FirstOrDefault(r => r.GetType() == typeof(FakeAssembly)).ShouldBeNull();
        }