Permalink
Browse files

Add logging to SharpDevelopProjectSystem.

  • Loading branch information...
1 parent 28ce7f2 commit cc85f6564a3528f3d8a1a14fcbadb34cf8bfcb51 @mrward mrward committed Feb 24, 2011
View
89 src/AddIns/Misc/PackageManagement/Project/Src/SharpDevelopProjectSystem.cs
@@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.IO;
using System.Runtime.Versioning;
+using ICSharpCode.Core;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Project;
using NuGet;
@@ -60,6 +61,7 @@ public void AddReference(string referencePath, Stream stream)
ReferenceProjectItem assemblyReference = CreateReference(referencePath);
ProjectService.AddProjectItem(project, assemblyReference);
project.Save();
+ LogAddedReferenceToProject(assemblyReference);
}
ReferenceProjectItem CreateReference(string referencePath)
@@ -70,6 +72,21 @@ ReferenceProjectItem CreateReference(string referencePath)
return assemblyReference;
}
+ void LogAddedReferenceToProject(ReferenceProjectItem referenceProjectItem)
+ {
+ LogAddedReferenceToProject(referenceProjectItem.Include, ProjectName);
+ }
+
+ protected virtual void LogAddedReferenceToProject(string referenceName, string projectName)
+ {
+ DebugLogFormat("Added reference '{0}' to project '{1}'.", referenceName, projectName);
+ }
+
+ void DebugLogFormat(string format, params object[] args)
+ {
+ Logger.Log(MessageLevel.Debug, format, args);
+ }
+
public bool ReferenceExists(string name)
{
ReferenceProjectItem referenceProjectItem = FindReference(name);
@@ -101,9 +118,20 @@ public void RemoveReference(string name)
if (referenceProjectItem != null) {
ProjectService.RemoveProjectItem(project, referenceProjectItem);
project.Save();
+ LogRemovedReferenceFromProject(referenceProjectItem);
}
}
+ void LogRemovedReferenceFromProject(ReferenceProjectItem referenceProjectItem)
+ {
+ LogRemovedReferenceFromProject(referenceProjectItem.Include, ProjectName);
+ }
+
+ protected virtual void LogRemovedReferenceFromProject(string referenceName, string projectName)
+ {
+ DebugLogFormat("Removed reference '{0}' from project '{1}'.", referenceName, projectName);
+ }
+
public bool IsSupportedFile(string path)
{
return !IsAppConfigFile(path);
@@ -121,13 +149,31 @@ public override void AddFile(string path, Stream stream)
if (ShouldAddFileToProject(path)) {
AddFileToProject(path);
}
+ LogAddedFileToProject(path);
}
protected virtual void PhysicalFileSystemAddFile(string path, Stream stream)
{
base.AddFile(path, stream);
}
+ bool ShouldAddFileToProject(string path)
+ {
+ return !IsBinDirectory(path) && !FileExistsInProject(path);
+ }
+
+ bool IsBinDirectory(string path)
+ {
+ string directoryName = Path.GetDirectoryName(path);
+ return IsMatchIgnoringCase(directoryName, "bin");
+ }
+
+ bool FileExistsInProject(string path)
+ {
+ string fullPath = GetFullPath(path);
+ return project.IsFileInProject(fullPath);
+ }
+
void AddFileToProject(string path)
{
FileProjectItem fileItem = CreateFileProjectItem(path);
@@ -143,35 +189,56 @@ FileProjectItem CreateFileProjectItem(string path)
return fileItem;
}
- bool ShouldAddFileToProject(string path)
- {
- return !IsBinDirectory(path) && !FileExistsInProject(path);
- }
-
- bool IsBinDirectory(string path)
+ void LogAddedFileToProject(string fileName)
{
- string directoryName = Path.GetDirectoryName(path);
- return IsMatchIgnoringCase(directoryName, "bin");
+ LogAddedFileToProject(fileName, ProjectName);
}
- bool FileExistsInProject(string path)
+ protected virtual void LogAddedFileToProject(string fileName, string projectName)
{
- string fullPath = GetFullPath(path);
- return project.IsFileInProject(fullPath);
+ DebugLogFormat("Added file '{0}' to project '{1}'.", fileName, projectName);
}
public override void DeleteDirectory(string path, bool recursive)
{
string directory = GetFullPath(path);
fileService.RemoveDirectory(directory);
project.Save();
+ LogDeletedDirectory(path);
}
public override void DeleteFile(string path)
{
string fileName = GetFullPath(path);
fileService.RemoveFile(fileName);
project.Save();
+ LogDeletedFileInfo(path);
+ }
+
+ protected virtual void LogDeletedDirectory(string folder)
+ {
+ DebugLogFormat("Removed folder '{0}'.", folder);
+ }
+
+ void LogDeletedFileInfo(string path)
+ {
+ string fileName = Path.GetFileName(path);
+ string directory = Path.GetDirectoryName(path);
+ if (String.IsNullOrEmpty(directory)) {
+ LogDeletedFile(fileName);
+ } else {
+ LogDeletedFileFromDirectory(fileName, directory);
+ }
+ }
+
+ protected virtual void LogDeletedFile(string fileName)
+ {
+ DebugLogFormat("Removed file '{0}'.", fileName);
+ }
+
+ protected virtual void LogDeletedFileFromDirectory(string fileName, string directory)
+ {
+ DebugLogFormat("Removed file '{0}' from folder '{1}'.", fileName, directory);
}
}
}
View
3 src/AddIns/Misc/PackageManagement/Test/PackageManagement.Tests.csproj
@@ -81,10 +81,13 @@
<Compile Include="Src\Helpers\FakePackageTests.cs" />
<Compile Include="Src\Helpers\FakeTask.cs" />
<Compile Include="Src\Helpers\FakeTaskFactory.cs" />
+ <Compile Include="Src\Helpers\FileNameAndDirectory.cs" />
+ <Compile Include="Src\Helpers\FileNameAndProjectName.cs" />
<Compile Include="Src\Helpers\FileProjectItemAssert.cs" />
<Compile Include="Src\Helpers\PackageCollectionAssert.cs" />
<Compile Include="Src\Helpers\PackageSourceCollectionAssert.cs" />
<Compile Include="Src\Helpers\PageCollectionAssert.cs" />
+ <Compile Include="Src\Helpers\ReferenceAndProjectName.cs" />
<Compile Include="Src\Helpers\ReferenceProjectItemAssert.cs" />
<Compile Include="Src\Helpers\TestablePackagesViewModel.cs" />
<Compile Include="Src\Helpers\TestablePackageViewModel.cs" />
View
43 src/AddIns/Misc/PackageManagement/Test/Src/Helpers/FileNameAndDirectory.cs
@@ -0,0 +1,43 @@
+// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
+// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
+
+using System;
+
+namespace PackageManagement.Tests.Helpers
+{
+ public class FileNameAndDirectory
+ {
+ public FileNameAndDirectory()
+ {
+ }
+
+ public FileNameAndDirectory(string fileName, string folder)
+ {
+ this.FileName = fileName;
+ this.Folder = folder;
+ }
+
+ public string FileName;
+ public string Folder;
+
+ public override bool Equals(object obj)
+ {
+ FileNameAndDirectory rhs = obj as FileNameAndDirectory;
+ if (rhs != null) {
+ return (FileName == rhs.FileName) &&
+ (Folder == rhs.Folder);
+ }
+ return false;
+ }
+
+ public override int GetHashCode()
+ {
+ return base.GetHashCode();
+ }
+
+ public override string ToString()
+ {
+ return String.Format("[FileNameAndDirectory FileName={0}, Folder={1}]", FileName, Folder);
+ }
+ }
+}
View
43 src/AddIns/Misc/PackageManagement/Test/Src/Helpers/FileNameAndProjectName.cs
@@ -0,0 +1,43 @@
+// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
+// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
+
+using System;
+
+namespace PackageManagement.Tests.Helpers
+{
+ public class FileNameAndProjectName
+ {
+ public FileNameAndProjectName()
+ {
+ }
+
+ public FileNameAndProjectName(string fileName, string projectName)
+ {
+ this.FileName = fileName;
+ this.ProjectName = projectName;
+ }
+
+ public string FileName;
+ public string ProjectName;
+
+ public override bool Equals(object obj)
+ {
+ FileNameAndProjectName rhs = obj as FileNameAndProjectName;
+ if (rhs != null) {
+ return (rhs.FileName == FileName) &&
+ (rhs.ProjectName == ProjectName);
+ }
+ return false;
+ }
+
+ public override int GetHashCode()
+ {
+ return base.GetHashCode();
+ }
+
+ public override string ToString()
+ {
+ return String.Format("[FileNameAndProjectName FileName={0}, ProjectName={1}]", FileName, ProjectName);
+ }
+ }
+}
View
43 src/AddIns/Misc/PackageManagement/Test/Src/Helpers/ReferenceAndProjectName.cs
@@ -0,0 +1,43 @@
+// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
+// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
+
+using System;
+
+namespace PackageManagement.Tests.Helpers
+{
+ public class ReferenceAndProjectName
+ {
+ public ReferenceAndProjectName()
+ {
+ }
+
+ public ReferenceAndProjectName(string reference, string project)
+ {
+ this.Reference = reference;
+ this.Project = project;
+ }
+
+ public string Reference;
+ public string Project;
+
+ public override bool Equals(object obj)
+ {
+ ReferenceAndProjectName rhs = obj as ReferenceAndProjectName;
+ if (rhs != null) {
+ return (rhs.Project == Project) &&
+ (rhs.Reference == Reference);
+ }
+ return false;
+ }
+
+ public override int GetHashCode()
+ {
+ return base.GetHashCode();
+ }
+
+ public override string ToString()
+ {
+ return String.Format("[ReferenceAndProjectName Reference={0}, Project={1}]", Reference, Project);
+ }
+ }
+}
View
42 src/AddIns/Misc/PackageManagement/Test/Src/Helpers/TestableSharpDevelopProjectSystem.cs
@@ -4,6 +4,7 @@
using System;
using System.IO;
using ICSharpCode.PackageManagement;
+using ICSharpCode.PackageManagement.Design;
using ICSharpCode.SharpDevelop.Project;
namespace PackageManagement.Tests.Helpers
@@ -13,6 +14,13 @@ public class TestableSharpDevelopProjectSystem : SharpDevelopProjectSystem
public string PathPassedToPhysicalFileSystemAddFile;
public Stream StreamPassedToPhysicalFileSystemAddFile;
public FakeFileService FakeFileService;
+ public FakePackageManagementOutputMessagesView FakeOutputMessagesView;
+ public string FileNamePassedToLogDeletedFile;
+ public FileNameAndDirectory FileNameAndDirectoryPassedToLogDeletedFileFromDirectory;
+ public string DirectoryPassedToLogDeletedDirectory;
+ public ReferenceAndProjectName ReferenceAndProjectNamePassedToLogAddedReferenceToProject;
+ public ReferenceAndProjectName ReferenceAndProjectNamePassedToLogRemovedReferenceFromProject;
+ public FileNameAndProjectName FileNameAndProjectNamePassedToLogAddedFileToProject;
public TestableSharpDevelopProjectSystem(MSBuildBasedProject project)
: this(project, new FakeFileService(project))
@@ -23,12 +31,46 @@ public TestableSharpDevelopProjectSystem(MSBuildBasedProject project)
: base(project, fileService)
{
FakeFileService = (FakeFileService)fileService;
+ Logger = FakeOutputMessagesView;
}
protected override void PhysicalFileSystemAddFile(string path, Stream stream)
{
PathPassedToPhysicalFileSystemAddFile = path;
StreamPassedToPhysicalFileSystemAddFile = stream;
}
+
+ protected override void LogDeletedFile(string fileName)
+ {
+ FileNamePassedToLogDeletedFile = fileName;
+ }
+
+ protected override void LogDeletedFileFromDirectory(string fileName, string directory)
+ {
+ FileNameAndDirectoryPassedToLogDeletedFileFromDirectory = new FileNameAndDirectory(fileName, directory);
+ }
+
+ protected override void LogDeletedDirectory(string directory)
+ {
+ DirectoryPassedToLogDeletedDirectory = directory;
+ }
+
+ protected override void LogAddedReferenceToProject(string referenceName, string projectName)
+ {
+ ReferenceAndProjectNamePassedToLogAddedReferenceToProject =
+ new ReferenceAndProjectName(referenceName, projectName);
+ }
+
+ protected override void LogRemovedReferenceFromProject(string referenceName, string projectName)
+ {
+ ReferenceAndProjectNamePassedToLogRemovedReferenceFromProject =
+ new ReferenceAndProjectName(referenceName, projectName);
+ }
+
+ protected override void LogAddedFileToProject(string fileName, string projectName)
+ {
+ FileNameAndProjectNamePassedToLogAddedFileToProject =
+ new FileNameAndProjectName(fileName, projectName);
+ }
}
}
View
215 src/AddIns/Misc/PackageManagement/Test/Src/SharpDevelopProjectSystemTests.cs
@@ -28,11 +28,21 @@ void CreateTestProject()
project = ProjectHelper.CreateTestProject();
}
+ void CreateTestProject(string fileName)
+ {
+ CreateTestProject();
+ project.FileName = fileName;
+ }
+
+ void AddFileToProject(string fileName)
+ {
+ ProjectHelper.AddFile(project, fileName);
+ }
+
[Test]
public void Root_NewInstanceCreated_ReturnsProjectDirectory()
{
- CreateTestProject();
- project.FileName = @"d:\projects\MyProject\MyProject.csproj";
+ CreateTestProject(@"d:\projects\MyProject\MyProject.csproj");
CreateProjectSystem(project);
string expectedRoot = @"d:\projects\MyProject\";
@@ -232,6 +242,24 @@ public void AddReference_ReferenceFileNameIsRelativePath_ReferenceAddedToProject
}
[Test]
+ public void AddReference_AddReferenceToNUnitFramework_AddingReferenceIsLogged()
+ {
+ CreateTestProject();
+ CreateProjectSystem(project);
+ project.Name = "MyTestProject";
+
+ string fileName = @"d:\projects\packages\nunit\nunit.framework.dll";
+ projectSystem.AddReference(fileName, null);
+
+ var expectedReferenceAndProjectName = new ReferenceAndProjectName() {
+ Reference = "nunit.framework",
+ Project = "MyTestProject"
+ };
+
+ Assert.AreEqual(expectedReferenceAndProjectName, projectSystem.ReferenceAndProjectNamePassedToLogAddedReferenceToProject);
+ }
+
+ [Test]
public void RemoveReference_ReferenceBeingRemovedHasFileExtension_ReferenceRemovedFromProject()
{
CreateTestProject();
@@ -285,6 +313,25 @@ public void RemoveReference_ReferenceExistsInProject_ProjectIsSavedAfterReferenc
}
[Test]
+ public void RemoveReference_ReferenceBeingRemovedHasFileExtension_ReferenceRemovalIsLogged()
+ {
+ CreateTestProject();
+ project.Name = "MyTestProject";
+ ProjectHelper.AddReference(project, "nunit.framework");
+ CreateProjectSystem(project);
+
+ string fileName = @"d:\projects\packages\nunit\nunit.framework.dll";
+ projectSystem.RemoveReference(fileName);
+
+ var expectedReferenceAndProjectName = new ReferenceAndProjectName {
+ Reference = "nunit.framework",
+ Project = "MyTestProject"
+ };
+
+ Assert.AreEqual(expectedReferenceAndProjectName, projectSystem.ReferenceAndProjectNamePassedToLogRemovedReferenceFromProject);
+ }
+
+ [Test]
public void AddFile_NewFile_AddsFileToFileSystem()
{
CreateTestProject();
@@ -301,8 +348,7 @@ public void AddFile_NewFile_AddsFileToFileSystem()
[Test]
public void AddFile_NewFile_AddsFileToProject()
{
- CreateTestProject();
- project.FileName = @"d:\projects\MyProject\MyProject.csproj";
+ CreateTestProject(@"d:\projects\MyProject\MyProject.csproj");
project.ItemTypeToReturnFromGetDefaultItemType = ItemType.Compile;
CreateProjectSystem(project);
@@ -319,8 +365,7 @@ public void AddFile_NewFile_AddsFileToProject()
[Test]
public void AddFile_NewResxFile_AddsFileToProjectWithCorrectItemType()
{
- CreateTestProject();
- project.FileName = @"d:\projects\MyProject\MyProject.csproj";
+ CreateTestProject(@"d:\projects\MyProject\MyProject.csproj");
project.ItemTypeToReturnFromGetDefaultItemType = ItemType.EmbeddedResource;
CreateProjectSystem(project);
@@ -337,8 +382,7 @@ public void AddFile_NewResxFile_AddsFileToProjectWithCorrectItemType()
[Test]
public void AddFile_RelativeFileNameUsed_AddsFileToProject()
{
- CreateTestProject();
- project.FileName = @"d:\projects\MyProject\MyProject.csproj";
+ CreateTestProject(@"d:\projects\MyProject\MyProject.csproj");
project.ItemTypeToReturnFromGetDefaultItemType = ItemType.Compile;
CreateProjectSystem(project);
@@ -356,8 +400,7 @@ public void AddFile_RelativeFileNameUsed_AddsFileToProject()
[Test]
public void AddFile_RelativeFileNameWithNoPathUsed_AddsFileToProject()
{
- CreateTestProject();
- project.FileName = @"d:\projects\MyProject\MyProject.csproj";
+ CreateTestProject(@"d:\projects\MyProject\MyProject.csproj");
project.ItemTypeToReturnFromGetDefaultItemType = ItemType.Compile;
CreateProjectSystem(project);
@@ -375,9 +418,8 @@ public void AddFile_RelativeFileNameWithNoPathUsed_AddsFileToProject()
[Test]
public void AddFile_NewFile_ProjectIsSavedAfterFileAddedToProject()
{
- CreateTestProject();
+ CreateTestProject(@"d:\projects\MyProject\MyProject.csproj");
project.IsSaved = false;
- project.FileName = @"d:\projects\MyProject\MyProject.csproj";
CreateProjectSystem(project);
string fileName = @"d:\projects\MyProject\src\NewFile.cs";
@@ -389,8 +431,7 @@ public void AddFile_NewFile_ProjectIsSavedAfterFileAddedToProject()
[Test]
public void AddFile_NewFileToBeAddedInBinFolder_FileIsNotAddedToProject()
{
- CreateTestProject();
- project.FileName = @"d:\projects\MyProject\MyProject.csproj";
+ CreateTestProject(@"d:\projects\MyProject\MyProject.csproj");
CreateProjectSystem(project);
string fileName = @"bin\NewFile.dll";
@@ -404,8 +445,7 @@ public void AddFile_NewFileToBeAddedInBinFolder_FileIsNotAddedToProject()
[Test]
public void AddFile_NewFileToBeAddedInBinFolderWithBinFolderNameInUpperCase_FileIsNotAddedToProject()
{
- CreateTestProject();
- project.FileName = @"d:\projects\MyProject\MyProject.csproj";
+ CreateTestProject(@"d:\projects\MyProject\MyProject.csproj");
CreateProjectSystem(project);
string fileName = @"BIN\NewFile.dll";
@@ -419,43 +459,70 @@ public void AddFile_NewFileToBeAddedInBinFolderWithBinFolderNameInUpperCase_File
[Test]
public void AddFile_FileAlreadyExistsInProject_FileIsNotAddedToProject()
{
- CreateTestProject();
- project.FileName = @"d:\projects\MyProject\MyProject.csproj";
+ CreateTestProject(@"d:\projects\MyProject\MyProject.csproj");
project.ItemTypeToReturnFromGetDefaultItemType = ItemType.Compile;
- CreateProjectSystem(project);
+ CreateProjectSystem(project);
+ AddFileToProject(@"d:\projects\MyProject\src\NewFile.cs");
- string relativeFileName = @"src\NewFile.cs";
- string fileName = @"d:\projects\MyProject\src\NewFile.cs";
- ProjectHelper.AddFile(project, fileName);
-
- projectSystem.AddFile(relativeFileName, null);
+ projectSystem.AddFile(@"src\NewFile.cs", null);
int projectItemsCount = project.Items.Count;
Assert.AreEqual(1, projectItemsCount);
}
[Test]
+ public void AddFile_NewFile_FileAddedToProjectIsLogged()
+ {
+ CreateTestProject(@"d:\temp\MyProject.csproj");
+ project.Name = "MyTestProject";
+ CreateProjectSystem(project);
+
+ projectSystem.AddFile(@"src\files\abc.cs", null);
+
+ var expectedFileNameAndProjectName = new FileNameAndProjectName {
+ FileName = @"src\files\abc.cs",
+ ProjectName = "MyTestProject"
+ };
+
+ Assert.AreEqual(expectedFileNameAndProjectName, projectSystem.FileNameAndProjectNamePassedToLogAddedFileToProject);
+ }
+
+ [Test]
+ public void AddFile_NewFileAlreadyExistsInProject_FileIsStillLogged()
+ {
+ CreateTestProject(@"d:\temp\MyProject.csproj");
+ project.Name = "MyTestProject";
+ AddFileToProject(@"src\files\abc.cs");
+ CreateProjectSystem(project);
+
+ projectSystem.AddFile(@"src\files\abc.cs", null);
+
+ var expectedFileNameAndProjectName = new FileNameAndProjectName {
+ FileName = @"src\files\abc.cs",
+ ProjectName = "MyTestProject"
+ };
+
+ Assert.AreEqual(expectedFileNameAndProjectName, projectSystem.FileNameAndProjectNamePassedToLogAddedFileToProject);
+ }
+
+ [Test]
public void DeleteFile_DeletesFileFromFileSystem_CallsFileServiceRemoveFile()
{
- CreateTestProject();
- project.FileName = @"d:\temp\MyProject.csproj";
- string fileName = @"d:\temp\test.cs";
- ProjectHelper.AddFile(project, fileName);
+ CreateTestProject(@"d:\temp\MyProject.csproj");
+ AddFileToProject(@"d:\temp\test.cs");
CreateProjectSystem(project);
projectSystem.DeleteFile("test.cs");
- Assert.AreEqual(fileName, projectSystem.FakeFileService.PathPassedToRemoveFile);
+ Assert.AreEqual(@"d:\temp\test.cs", projectSystem.FakeFileService.PathPassedToRemoveFile);
}
[Test]
public void DeleteFile_DeletesFileFromFileSystem_ProjectIsSavedAfterFileRemoved()
{
- CreateTestProject();
- project.FileName = @"d:\temp\MyProject.csproj";
+ CreateTestProject(@"d:\temp\MyProject.csproj");
project.IsSaved = false;
- string fileName = @"d:\temp\test.cs";
- ProjectHelper.AddFile(project, fileName);
+ AddFileToProject(@"d:\temp\test.cs");
CreateProjectSystem(project);
projectSystem.DeleteFile("test.cs");
@@ -464,33 +531,97 @@ public void DeleteFile_DeletesFileFromFileSystem_ProjectIsSavedAfterFileRemoved(
}
[Test]
+ public void DeleteFile_DeletesFileFromFileSystem_FileDeletionLogged()
+ {
+ CreateTestProject(@"d:\temp\MyProject.csproj");
+ AddFileToProject(@"d:\temp\test.cs");
+ CreateProjectSystem(project);
+
+ projectSystem.DeleteFile("test.cs");
+
+ Assert.AreEqual("test.cs", projectSystem.FileNamePassedToLogDeletedFile);
+ }
+
+ [Test]
+ public void DeleteFile_DeletesFileFromFileSystem_FolderInformationNotLogged()
+ {
+ CreateTestProject(@"d:\temp\MyProject.csproj");
+ AddFileToProject(@"d:\temp\test.cs");
+ CreateProjectSystem(project);
+
+ projectSystem.DeleteFile("test.cs");
+
+ Assert.IsNull(projectSystem.FileNameAndDirectoryPassedToLogDeletedFileFromDirectory);
+ }
+
+ [Test]
+ public void DeleteFile_DeletesFileFromSubFolder_FileDeletionLogged()
+ {
+ CreateTestProject(@"d:\temp\MyProject.csproj");
+ AddFileToProject(@"d:\temp\src\Files\test.cs");
+ CreateProjectSystem(project);
+
+ projectSystem.DeleteFile(@"src\Files\test.cs");
+
+ var expectedFileNameAndFolder = new FileNameAndDirectory() {
+ FileName = "test.cs",
+ Folder = @"src\Files"
+ };
+
+ var actualFileNameAndFolder = projectSystem.FileNameAndDirectoryPassedToLogDeletedFileFromDirectory;
+
+ Assert.AreEqual(expectedFileNameAndFolder, actualFileNameAndFolder);
+ }
+
+ [Test]
+ public void DeleteFile_DeletesFileFromSubFolder_FileDeletionWithoutFolderInformationIsNotLogged()
+ {
+ CreateTestProject(@"d:\temp\MyProject.csproj");
+ AddFileToProject(@"d:\temp\src\Files\test.cs");
+ CreateProjectSystem(project);
+
+ projectSystem.DeleteFile(@"src\Files\test.cs");
+
+ Assert.IsNull(projectSystem.FileNamePassedToLogDeletedFile);
+ }
+
+ [Test]
public void DeleteDirectory_DeletesDirectoryFromFileSystem_CallsFileServiceRemoveDirectory()
{
- CreateTestProject();
- project.FileName = @"d:\temp\MyProject.csproj";
- string fileName = @"d:\temp\test\test.cs";
- ProjectHelper.AddFile(project, fileName);
+ CreateTestProject(@"d:\temp\MyProject.csproj");
+ AddFileToProject(@"d:\temp\test\test.cs");
CreateProjectSystem(project);
- string path = @"d:\temp\test";
projectSystem.DeleteDirectory("test");
+ string path = @"d:\temp\test";
Assert.AreEqual(path, projectSystem.FakeFileService.PathPassedToRemoveDirectory);
}
[Test]
public void DeleteDirectory_DeletesDirectoryFromFileSystem_ProjectIsSavedAfterDirectoryDeleted()
{
- CreateTestProject();
- project.FileName = @"d:\temp\MyProject.csproj";
- string fileName = @"d:\temp\test\test.cs";
- ProjectHelper.AddFile(project, fileName);
+ CreateTestProject(@"d:\temp\MyProject.csproj");
project.IsSaved = false;
+ AddFileToProject(@"d:\temp\test\test.cs");
CreateProjectSystem(project);
projectSystem.DeleteDirectory("test");
Assert.AreEqual(0, project.ItemsWhenSaved.Count);
}
+
+ [Test]
+ public void DeleteDirectory_DeletesDirectoryFromFileSystem_DirectoryIsLogged()
+ {
+ CreateTestProject(@"d:\temp\MyProject.csproj");
+ project.IsSaved = false;
+ AddFileToProject(@"d:\temp\test\test.cs");
+ CreateProjectSystem(project);
+
+ projectSystem.DeleteDirectory("test");
+
+ Assert.AreEqual("test", projectSystem.DirectoryPassedToLogDeletedDirectory);
+ }
}
}

0 comments on commit cc85f65

Please sign in to comment.