// 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 NUnit.Framework;
using Rauchy.Regionerate.Shared.Components.Rendering;
namespace Rauchy.Regionerate.Shared.Components.Tests
{
///
/// Tests the class.
///
[ TestFixture ]
public class HiddenDragonTests
{
#region Data Members (2)
private static readonly char HiddenDragonCharacter = Convert.ToChar( 160 );
private const string SampleText = " This is a sample text.";
#endregion Data Members
#region Tests (3)
[ Test ]
public void DoesNotRecognizeWrongEmbeddedValue()
{
bool isEmbedded = IsEmbedded( "My Region" ); // Contains a space, not a hidden dragon.
Assert.IsFalse( isEmbedded );
}
[ Test ]
public void EmbedsHiddenDragon()
{
HiddenDragon hiddenDragon = new HiddenDragon();
string symbolizedText = hiddenDragon.Embed( SampleText );
// All spaces should be replaced with hidden dragons.
bool containsSpaces = symbolizedText.Contains( " " );
Assert.IsFalse( containsSpaces );
// Verify that the length of the symbolized text is 2 characters longer than the original text.
Assert.AreEqual( SampleText.Length + 2, symbolizedText.Length );
// Verify that a hidden dragon was inserted at the beginning of the symbolized text.
int i = 0;
Assert.AreEqual( HiddenDragonCharacter, symbolizedText[ i ] );
i++;
// Iterate through all space characters in SampleText and
// check that the symbolized version contains hidden dragons in their position.
foreach ( char c in SampleText )
{
if ( c == ' ' )
{
Assert.AreEqual( HiddenDragonCharacter, symbolizedText[ i ] );
}
i++;
}
// Verify that a hidden dragon was inserted at the end of the symbolized text.
Assert.AreEqual( HiddenDragonCharacter, symbolizedText[ i ] );
}
[ Test ]
public void RecognizesEmbeddedHiddenDragon()
{
string text = "#region" + SampleText.Replace( ' ', Convert.ToChar( 160 ) );
bool isEmbedded = IsEmbedded( text );
Assert.IsTrue( isEmbedded );
}
#endregion Tests
#region Helper Methods (1)
private static bool IsEmbedded( string text )
{
HiddenDragon hiddenDragon = new HiddenDragon();
bool isEmbedded = hiddenDragon.IsEmbeddedIn( text );
return isEmbedded;
}
#endregion Helper Methods
}
}