public void ShouldRemoveFileFromProjectXml()
        {
            var project = new FakeProject(fileName: @"c:\test\code\fake.csproj");
            project.AddFile("some content", @"c:\test\code\test.cs");

            var xml = @"
                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Hello.cs""/>
                        <Compile Include=""Test.cs""/>
                    </ItemGroup>
                </Project>";

            project.XmlRepresentation = XDocument.Parse(xml);
            var expectedXml = XDocument.Parse(@"
                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Hello.cs""/>
                    </ItemGroup>
                </Project>");

            var solution = new FakeSolution(@"c:\test\fake.sln");
            solution.Projects.Add(project);

            var request = new RemoveFromProjectRequest
            {
                FileName = @"c:\test\code\test.cs"
            };

            var handler = new RemoveFromProjectHandler(solution);
            handler.RemoveFromProject(request);

            project.AsXml().ToString().ShouldEqual(expectedXml.ToString());
        }
 public RemoveFromProjectModule(RemoveFromProjectHandler handler)
 {
     Post["RemoveFromProject", "/removefromproject"] = x =>
     {
         var req = this.Bind <RemoveFromProjectRequest>();
         handler.RemoveFromProject(req);
         return(Response.AsJson(true));
     };
 }
 public RemoveFromProjectModule(RemoveFromProjectHandler handler)
 {
     Post["/removefromproject"] = x =>
         {
             var req = this.Bind<RemoveFromProjectRequest>();
             handler.RemoveFromProject(req);
             return Response.AsJson(true);
         };
 }
        public void ShouldThrowProjectNotFoundExceptionWhenProjectNotFound()
        {
            var project = new FakeProject(fileName: @"/test/code/fake.csproj");
            var solution = new FakeSolution(@"/test/fake.sln");
            solution.Projects.Add(project);

            var request = new RemoveFromProjectRequest
            {
                FileName = @"/test/folder/Test.cs"
            };

            var handler = new RemoveFromProjectHandler(solution);
            handler.RemoveFromProject(request);
        }
        public void ShouldRemoveItemGroupWhenRemovingLastFile()
        {
			XNamespace ns = "http://schemas.microsoft.com/developer/msbuild/2003";
            var project = new FakeProject(fileName: @"c:\test\code\fake.csproj");
            project.AddFile("some content", @"c:\test\code\test.cs");

            var xml = @"
                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                    <ItemGroup>
                        <Compile Include=""Test.cs""/>
                    </ItemGroup>
                </Project>";

            project.XmlRepresentation = XDocument.Parse(xml);

            var solution = new FakeSolution(@"c:\test\fake.sln");
            solution.Projects.Add(project);

            var request = new RemoveFromProjectRequest
            {
                FileName = @"c:\test\code\test.cs"
            };

            var handler = new RemoveFromProjectHandler(solution);
            handler.RemoveFromProject(request);

			project.AsXml().Descendants(ns + "ItemGroup").Count().ShouldEqual(0);
        }
        public void ShouldRemoveFileFromProject()
        {
            var xml = @"
               <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                   <ItemGroup>
                       <Compile Include=""Test.cs""/>
                   </ItemGroup>
               </Project>";

            var project = GetProject(xml);

            var solution = new FakeSolution(@"c:\test\fake.sln");
            solution.Projects.Add(project);

            var request = new RemoveFromProjectRequest
            {
                FileName = @"c:\test\code\test.cs"
            };

            var handler = new RemoveFromProjectHandler(solution);
            handler.RemoveFromProject(request);

            project.Files.ShouldBeEmpty();
        }