// Copyright (c) 2007 Omer Rauchwerger (a.k.a rauchy) (omer@rauchy.net)
// All rights reserved.
//
// This file is part of Regionerate.
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License,
// or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
using System;
using System.IO;
using NUnit.Framework;
using Rauchy.Regionerate.ServiceLayer.Components.Projects;
namespace Rauchy.Regionerate.ServiceLayer.Components.Tests
{
///
/// Tests the class.
///
[ TestFixture ]
public class CSharpProjectTests
{
#region Data Members (1)
private const string ResourcesDirectory = @"Resources";
#endregion Data Members
#region Tests (5)
// [rgn] Public Methods (5)
[ Test ]
[ ExpectedException( typeof ( FileNotFoundException ) ) ]
public void LoadNonExistingFile()
{
new CSharpProject( Guid.NewGuid().ToString() );
}
[ Test ]
public void LoadsA2005ProjectWithOneCompiledFile()
{
LoadsAProjectWithOneCompiledFile( "SingleFile2005Project.csproj" );
}
[ Test ]
public void LoadsAnOrcasProjectWithOneCompiledFile()
{
LoadsAProjectWithOneCompiledFile( "SingleFileOrcasProject.csproj" );
}
[ Test ]
public void LoadsEmpty2005Project()
{
LoadsAnEmptyProject( "Empty2005Project.csproj" );
}
[ Test ]
public void LoadsEmptyOrcasProject()
{
LoadsAnEmptyProject( "EmptyOrcasProject.csproj" );
}
#endregion Tests
#region Helper Methods (3)
// [rgn] Private Methods (3)
///
/// Gets the path to a resource.
///
/// Name of the file.
private static string GetResourcePath( string fileName )
{
return Path.Combine( ResourcesDirectory, fileName );
}
private static void LoadsAnEmptyProject( string projectPath )
{
string resourcePath = GetResourcePath( projectPath );
Project project = new CSharpProject( resourcePath );
Assert.IsNull( project.GetEnumerator().Current );
Assert.IsFalse( project.GetEnumerator().MoveNext() );
}
private static void LoadsAProjectWithOneCompiledFile( string projectPath )
{
string resourcePath = GetResourcePath( projectPath );
Project project = new CSharpProject( resourcePath );
int itemCount = 0;
foreach ( Document document in project )
{
Assert.AreEqual( "Class1.cs", document.Title );
itemCount++;
}
Assert.AreEqual( 1, itemCount );
}
#endregion Helper Methods
}
}