// 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 BestBrains.System;
using NUnit.Framework;
namespace Rauchy.Regionerate.ServiceLayer.Components.Tests
{
///
/// Tests the class.
///
[ TestFixture ]
public class DocumentTests
{
#region Data Members (2)
private Document _document;
private const string ExpectedTitle = "Document's Title";
#endregion Data Members
#region Initialization (1)
[ SetUp ]
public void SetUp()
{
_document = null;
}
#endregion Initialization
#region Finalization (1)
[ TearDown ]
public void TearDown()
{
Assert.AreEqual( ExpectedTitle, _document.Title );
}
#endregion Finalization
#region Tests (13)
///
/// namespace MyNameSpace
/// {
/// public static class MyClass
/// {
/// }
/// }
///
///
/// public static class MyClass
/// {
/// }
///
[ Test ]
public void CanContainASingleClass()
{
string text = CommentReader.GetElement( "document" );
string @class = CommentReader.GetElement( "class" );
_document = new Document( ExpectedTitle, text );
// Make sure that only one class was found.
Assert.AreEqual( 1, _document.Classes.Count );
Assert.AreEqual( @class.Trim(), _document.Classes[ 0 ].Trim() );
}
///
/// namespace MyNameSpace
/// {
/// public interface MyInterface
/// {
/// }
/// }
///
///
/// public interface MyInterface
/// {
/// }
///
[ Test ]
public void CanContainASingleInterface()
{
string text = CommentReader.GetElement( "document" );
string @interface = CommentReader.GetElement( "interface" );
_document = new Document( ExpectedTitle, text );
// Make sure that only one interface was found.
Assert.AreEqual( 1, _document.Interfaces.Count );
Assert.AreEqual( @interface.Trim(), _document.Interfaces[ 0 ].Trim() );
}
///
/// namespace MyNameSpace
/// {
/// public static struct MyStruct
/// {
/// }
/// }
///
///
/// public static struct MyStruct
/// {
/// }
///
[ Test ]
public void CanContainASingleStruct()
{
string text = CommentReader.GetElement( "document" );
string @struct = CommentReader.GetElement( "struct" );
_document = new Document( ExpectedTitle, text );
// Make sure that only one struct was found.
Assert.AreEqual( 1, _document.Structs.Count );
Assert.AreEqual( @struct.Trim(), _document.Structs[ 0 ].Trim() );
}
///
/// namespace MyNameSpace
/// {
/// public static class MyClass
/// {
/// }
/// public static struct MyStruct
/// {
/// }
/// public interface MyInterface
/// {
/// }
/// }
///
///
/// public static class MyClass
/// {
/// }
///
///
/// public static struct MyStruct
/// {
/// }
///
///
/// public interface MyInterface
/// {
/// }
///
[ Test ]
public void CanContainDifferentTypes()
{
string text = CommentReader.GetElement( "document" );
string @class = CommentReader.GetElement( "class" );
string @struct = CommentReader.GetElement( "struct" );
string @interface = CommentReader.GetElement( "interface" );
_document = new Document( ExpectedTitle, text );
// Make sure that all types were found
Assert.AreEqual( 1, _document.Classes.Count );
Assert.AreEqual( 1, _document.Structs.Count );
Assert.AreEqual( 1, _document.Interfaces.Count );
Assert.AreEqual( @class.Trim(), _document.Classes[ 0 ].Trim() );
Assert.AreEqual( @struct.Trim(), _document.Structs[ 0 ].Trim() );
Assert.AreEqual( @interface.Trim(), _document.Interfaces[ 0 ].Trim() );
}
///
/// namespace MyNameSpace
/// {
/// public static class MyClass1
/// {
/// }
/// public static class MyClass2
/// {
/// }
/// }
///
///
/// public static class MyClass1
/// {
/// }
///
///
/// public static class MyClass2
/// {
/// }
///
[ Test ]
public void CanContainMultipleClasses()
{
string text = CommentReader.GetElement( "document" );
string class1 = CommentReader.GetElement( "class1" );
string class2 = CommentReader.GetElement( "class2" );
_document = new Document( ExpectedTitle, text );
// Make sure that both classes were found
Assert.AreEqual( 2, _document.Classes.Count );
Assert.AreEqual( class1.Trim(), _document.Classes[ 0 ] );
Assert.AreEqual( class2.Trim(), _document.Classes[ 1 ] );
}
///
/// namespace MyNameSpace
/// {
/// public interface MyInterface1
/// {
/// }
/// public interface MyInterface2
/// {
/// }
/// }
///
///
/// public interface MyInterface1
/// {
/// }
///
///
/// public interface MyInterface2
/// {
/// }
///
[ Test ]
public void CanContainMultipleInterfaces()
{
string text = CommentReader.GetElement( "document" );
string interface1 = CommentReader.GetElement( "interface1" );
string interface2 = CommentReader.GetElement( "interface2" );
_document = new Document( ExpectedTitle, text );
// Make sure that both interfaces were found
Assert.AreEqual( 2, _document.Interfaces.Count );
Assert.AreEqual( interface1.Trim(), _document.Interfaces[ 0 ].Trim() );
Assert.AreEqual( interface2.Trim(), _document.Interfaces[ 1 ].Trim() );
}
///
/// namespace MyNameSpace
/// {
/// public static struct MyStruct1
/// {
/// }
/// public static struct MyStruct2
/// {
/// }
/// }
///
///
/// public static struct MyStruct1
/// {
/// }
///
///
/// public static struct MyStruct2
/// {
/// }
///
[ Test ]
public void CanContainMultipleStructs()
{
string text = CommentReader.GetElement( "document" );
string struct1 = CommentReader.GetElement( "struct1" );
string struct2 = CommentReader.GetElement( "struct2" );
_document = new Document( ExpectedTitle, text );
// Make sure that both structs were found
Assert.AreEqual( 2, _document.Structs.Count );
Assert.AreEqual( struct1.Trim(), _document.Structs[ 0 ].Trim() );
Assert.AreEqual( struct2.Trim(), _document.Structs[ 1 ].Trim() );
}
[ Test ]
public void CanContainNoClasses()
{
string text = "no classes here!";
_document = new Document( ExpectedTitle, text );
Assert.AreEqual( 0, _document.Classes.Count );
}
[ Test ]
public void ConvertsToString()
{
string text = "Source text";
_document = new Document( ExpectedTitle, text );
Assert.AreEqual( text, _document.ToString() );
}
///
/// Driven by bug #76 - Generic Constraints stop Regionerate.
///
[ Test ]
public void RecognizesClassesWithGenericConstraints()
{
string text = "public class RegionerateTest where TGeneric : new() { }";
_document = new Document( ExpectedTitle, text );
// Make sure that the class was found.
Assert.AreEqual( 1, _document.Classes.Count );
Assert.AreEqual( text, _document.Classes[ 0 ] );
}
///
/// Driven by bug #28 - Classes with dots or commas in their declaration are not recognized.
///
///
/// namespace MyNameSpace
/// {
/// public class MyClass : System.Object, IDisposable
/// {
/// }
/// }
///
///
/// public class MyClass : System.Object, IDisposable
/// {
/// }
///
[ Test ]
public void RecognizesCommasInClassName()
{
string text = CommentReader.GetElement( "document" );
string @class = CommentReader.GetElement( "class" );
_document = new Document( ExpectedTitle, text );
// Make sure that only one class was found.
Assert.AreEqual( 1, _document.Classes.Count );
Assert.AreEqual( @class.Trim(), _document.Classes[ 0 ] );
}
///
/// Driven by bug #28 - Classes with dots or commas in their declaration are not recognized.
///
///
/// namespace MyNameSpace
/// {
/// public class MyClass : System.Object
/// {
/// }
/// }
///
///
/// public class MyClass : System.Object
/// {
/// }
///
[ Test ]
public void RecognizesDotsInClassName()
{
string text = CommentReader.GetElement( "document" );
string @class = CommentReader.GetElement( "class" );
_document = new Document( ExpectedTitle, text );
// Make sure that only one class was found.
Assert.AreEqual( 1, _document.Classes.Count );
Assert.AreEqual( @class.Trim(), _document.Classes[ 0 ] );
}
[ Test ]
public void ReplacesText()
{
string text = "this is just another text";
_document = new Document( ExpectedTitle, text );
_document.Replace( "just", "yet" );
Assert.AreEqual( text.Replace( "just", "yet" ), _document.ToString() );
}
#endregion Tests
}
}