// 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.Collections.Generic;
using System.IO;
using BestBrains.System;
using NUnit.Framework;
namespace Rauchy.Regionerate.Shared.Components.Tests
{
///
/// Tests the class.
///
[ TestFixture ]
public sealed class CodeLayoutTests
{
#region Data Members (1)
private IList _temporaryFiles;
#endregion Data Members
#region Initialization (1)
[ SetUp ]
public void SetUp()
{
_temporaryFiles = new List();
}
#endregion Initialization
#region Finalization (1)
[ TearDown ]
public void TearDown()
{
foreach ( string temporaryFile in _temporaryFiles )
{
if ( File.Exists( temporaryFile ) )
{
File.Delete( temporaryFile );
}
}
}
#endregion Finalization
#region Tests (8)
// [rgn] Public Methods (10)
///
///
///
///
///
[ Test ]
public void Loads()
{
string input = CommentReader.GetElement( "layout" );
// write input to a temporary file
string temporaryFilePath = WriteToTemporaryFile( input );
// load the temporary file
CodeLayout codeLayout = CodeLayout.Load( temporaryFilePath );
Assert.AreEqual( input, codeLayout.OuterXml );
}
[ Test ]
public void LoadsDefaultLayout()
{
CodeLayout codeLayout = CodeLayout.DefaultLayout;
Assert.AreEqual( Templates.DefaultCodeLayout, codeLayout.OuterXml );
}
///
///
///
///
///
[ Test ]
public void LoadsXml()
{
string input = CommentReader.GetElement( "layout" );
CodeLayout codeLayout = CodeLayout.LoadXml( input );
Assert.AreEqual( input, codeLayout.OuterXml );
}
///
///
///
///
///
///
///
///
///
[ Test ]
[ ExpectedException( typeof ( ArgumentException ) /* TODO: verify exception message, "layout" */ ) ]
public void LoadThrowsOnInvalidLayout()
{
string input = CommentReader.GetElement( "layout" );
// write input to a temporary file
string temporaryFilePath = WriteToTemporaryFile( input );
// attemp to load the temporary file
CodeLayout.Load( temporaryFilePath );
}
///
///
///
///
///
[ Test ]
[ ExpectedException( typeof ( ArgumentException ) /* TODO: verify exception message, "layout" */ ) ]
public void LoadThrowsOnInvalidNamespace()
{
string input = CommentReader.GetElement( "layout" );
// write input to a temporary file
string temporaryFilePath = WriteToTemporaryFile( input );
// attemp to load the temporary file
CodeLayout.Load( temporaryFilePath );
}
///
///
///
///
///
///
///
///
///
[ Test ]
[ ExpectedException( typeof ( ArgumentException ) /* TODO: verify exception message, "layout" */ ) ]
public void LoadXmlThrowsOnInvalidLayout()
{
string input = CommentReader.GetElement( "layout" );
CodeLayout.LoadXml( input );
}
///
///
///
///
///
[ Test ]
[ ExpectedException( typeof ( ArgumentException ) /* TODO: verify exception message, "layout" */ ) ]
public void LoadXmlThrowsOnInvalidNamespace()
{
string input = CommentReader.GetElement( "layout" );
CodeLayout.LoadXml( input );
}
///
/// Driven by Bug #45 - Well-formed Code Layout document fails on validation.
///
[ Test ]
public void ValidatesWellFormedDocument()
{
string layout =
"";
CodeLayout.LoadXml( layout );
}
#endregion Tests
#region Helper Methods (2)
// [rgn] Private Methods (2)
private void WriteToFile( string filePath, string text )
{
if ( File.Exists( filePath ) )
{
File.Delete( filePath );
}
_temporaryFiles.Add( filePath );
using ( Stream stream = File.Create( filePath ) )
{
StreamWriter writer = new StreamWriter( stream );
writer.Write( text );
writer.Flush();
}
}
private string WriteToTemporaryFile( string input )
{
string temporaryFilePath = Path.GetTempFileName();
WriteToFile( temporaryFilePath, input );
return temporaryFilePath;
}
#endregion Helper Methods
}
}