// 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 NUnit.Framework;
using Rauchy.Regionerate.Shared.Components.Rendering;
namespace Rauchy.Regionerate.Shared.Components.Tests
{
///
/// Tests the class.
///
[ TestFixture ]
public class WrapperTests
{
#region Data Members (1)
private const string SampleText = "This is a sample text.";
#endregion Data Members
#region Tests (7)
///
/// Driven by Bug #91 - Attributes are mistaken as wrappers.
///
///
/// If the string starts with the prefix, it isn't a real region declaration,
/// for example:
/// [MyAttribute()] might be mistakenly recognized as a wrapper,
/// so the class does not recognize these cases as embedded wrappers.
///
[ Test ]
public void DoesNotRecognizeWhenStringStartsWithPrefix()
{
bool isEmbedded = IsEmbedded( "[", "]", "[SerializableAttribute()]" );
Assert.IsFalse( isEmbedded );
}
[ Test ]
public void DoesNotRecognizeWhenSuffixIsBeforePrefix()
{
bool isEmbedded = IsEmbedded( "[", "]", "#region ] My Region [" );
Assert.IsFalse( isEmbedded );
}
[ Test ]
public void DoesNotRecognizeWrongEmbeddedValue()
{
bool isEmbedded = IsEmbedded( "[", "]", "#region * My Region *" );
Assert.IsFalse( isEmbedded );
}
[Test]
public void DoesNotRecognizeIndexers()
{
bool isEmbedded = IsEmbedded("[", "]", "private string IDataErrorInfo.this[string propertyName]");
Assert.IsFalse(isEmbedded);
}
[ Test ]
public void EmbedsAsteriskWrapper()
{
EmbedsWrapper( "*", "*" );
}
[ Test ]
public void EmbedsSquareBracketsWrapper()
{
EmbedsWrapper( "[", "]" );
}
[ Test ]
public void RecognizesEmbeddedAsteriskWrapper()
{
RecognizesEmbeddedWrapper( "*", "*" );
}
[ Test ]
public void RecognizesEmbeddedSquareBracketsWrapper()
{
RecognizesEmbeddedWrapper( "[", "]" );
}
#endregion Tests
#region Helper Methods (4)
private static void EmbedsWrapper( string prefix, string suffix )
{
string symbolizedText = EmbedWrapper( prefix, suffix, SampleText );
string expected = string.Format( " {0} {1} {2}", prefix, SampleText, suffix );
Assert.AreEqual( expected, symbolizedText );
}
private static string EmbedWrapper( string prefix, string suffix, string text )
{
Wrapper wrapper = new Wrapper( prefix, suffix );
string symbolizedText = wrapper.Embed( text );
return symbolizedText;
}
private static bool IsEmbedded( string prefix, string suffix, string text )
{
Wrapper wrapper = new Wrapper( prefix, suffix );
bool isEmbedded = wrapper.IsEmbeddedIn( text );
return isEmbedded;
}
public void RecognizesEmbeddedWrapper( string prefix, string suffix )
{
string text = "#region " + prefix + " " + SampleText + " " + suffix;
bool isEmbedded = IsEmbedded( prefix, suffix, text );
Assert.IsTrue( isEmbedded );
}
#endregion Helper Methods
}
}