Skip to content

Commit

Permalink
Added tests for the SolutionProjectFile #84
Browse files Browse the repository at this point in the history
  • Loading branch information
mtscout6 committed Mar 21, 2014
1 parent a0c8527 commit 804c521
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/FubuCsProjFile.Testing/FubuCsProjFile.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<Compile Include="NoneTester.cs" />
<Compile Include="ProjectReferenceTester.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SolutionFile\ProjectFile\SolutionProjectFileTester.cs" />
<Compile Include="SolutionTester.cs" />
<Compile Include="Solution_can_read_and_write_with_versions_Tester.cs" />
<Compile Include="StringExtensionsTester.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using FubuCsProjFile.ProjectFiles;
using FubuCsProjFile.SolutionFile.ProjectFiles;
using FubuTestingSupport;
using NUnit.Framework;
using Rhino.Mocks;

namespace FubuCsProjFile.Testing.SolutionFile.ProjectFile
{
public class SolutionProjectFileTester : InteractionContext<SolutionProjectFile>
{
[Test]
public void project_is_same_as_from_ctor()
{
var project = MockFor<IProjectFile>();
project.Stub(x => x.FileName).Return("projectfilename");
var solutionProjectFile = new SolutionProjectFile(project, "directory");
solutionProjectFile.Project.ShouldBeTheSameAs(project);
}

[Test]
public void project_type_comes_from_project_file_when_created_from_IProjectFile()
{
var type = Guid.NewGuid();
var project = MockFor<IProjectFile>();
project.Stub(x => x.Type).Return(type);
project.Stub(x => x.FileName).Return("projectfilename");

var solutionProjectFile = new SolutionProjectFile(project, "directory");

solutionProjectFile.Type.ShouldEqual(type);
}

[Test]
public void project_type_comes_from_solution_value_when_IProjectFile_has_not_been_loaded()
{
var type = Guid.NewGuid();
var solutionProjectFile = new SolutionProjectFile(type, Guid.NewGuid(), "projname", "relpath", () =>
{
throw new Exception("Should not attempt to create project in this test");
});
solutionProjectFile.Type.ShouldEqual(type);
}

[Test]
public void project_type_comes_from_project_file_when_loaded()
{
var type = Guid.NewGuid();
var project = MockFor<IProjectFile>();
project.Stub(x => x.Type).Return(type);

var solutionProjectFile = new SolutionProjectFile(Guid.NewGuid(), Guid.NewGuid(), "projname", "relpath", () => project);
solutionProjectFile.Project.ShouldBeTheSameAs(project);

solutionProjectFile.Type.ShouldEqual(type);
}

[Test]
public void does_not_save_project_if_not_loaded()
{
var project = MockFor<IProjectFile>();

var solutionProjectFile = new SolutionProjectFile(Guid.NewGuid(), Guid.NewGuid(), "projname", "relpath", () => project);
solutionProjectFile.Save();

project.AssertWasNotCalled(x => x.Save());
}

[Test]
public void saves_project_if_loaded()
{
var project = MockFor<IProjectFile>();

var solutionProjectFile = new SolutionProjectFile(Guid.NewGuid(), Guid.NewGuid(), "projname", "relpath", () => project);
solutionProjectFile.Project.ShouldBeTheSameAs(project);
solutionProjectFile.Save();

project.AssertWasCalled(x => x.Save());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@ public class SolutionProjectFile : SolutionProject, ISolutionProjectFile
private readonly Guid _projectTypeFromSolutionFile;
private readonly Lazy<IProjectFile> _projectFile;

public SolutionProjectFile(
Guid projectType,
Guid projectGuid,
string projectName,
string relativePath,
ISolution solution)
public SolutionProjectFile(Guid projectType, Guid projectGuid, string projectName, string relativePath, ISolution solution)
: this(projectType, projectGuid, projectName, relativePath, () =>
ProjectLoader.LoadOrCreateIfNotFound(projectGuid, projectName, relativePath, solution)) { }

public SolutionProjectFile(Guid projectType, Guid projectGuid, string projectName, string relativePath, Func<IProjectFile> projectFactory)
: base(projectGuid, projectName, relativePath)
{
_projectTypeFromSolutionFile = projectType;

_projectFile = new Lazy<IProjectFile>(() =>
ProjectLoader.LoadOrCreateIfNotFound(projectGuid, projectName, relativePath, solution));
_projectFile = new Lazy<IProjectFile>(projectFactory);
}

public SolutionProjectFile(IProjectFile project, string solutionDirectory)
Expand Down

0 comments on commit 804c521

Please sign in to comment.