+
Skip to content

Allow the assertEquals command to match "Yes/No" "True/False" "Y/N" with a Boolean returned from the system under test #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 7, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bin
obj
*.suo
*.VisualState.xml
TestResult.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Concordion.Integration.NUnit.Addin
{
[NUnitAddin(Name = "Concordion Test Runner", Description = "Runs Concordion Tests with NUnit", Type = ExtensionType.Core)]
[NUnitAddin(Name = "ConcordionNUnitAddin", Description = "Runs Concordion Tests with NUnit", Type = ExtensionType.Core)]
public class SuiteBuilderAddin : ISuiteBuilder, IAddin
{
#region Implementation of ISuiteBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<ProjectGuid>{FB522DBB-6F64-4834-9C87-029389AA0ABB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Concordion.Integration.NUnit</RootNamespace>
<AssemblyName>Concordion.Integration.NUnit</AssemblyName>
<RootNamespace>Concordion.NUnit</RootNamespace>
<AssemblyName>Concordion.NUnit</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
Expand Down
3 changes: 0 additions & 3 deletions Concordion.Spec/Concordion.Spec.config

This file was deleted.

14 changes: 8 additions & 6 deletions Concordion.Spec/Concordion.Spec.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Concordion.Spec</RootNamespace>
<AssemblyName>Concordion.Spec</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
Expand All @@ -31,6 +31,7 @@
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -69,6 +70,7 @@
<ItemGroup>
<Compile Include="Concordion\Command\AssertEquals\AssertEqualsTest.cs" />
<Compile Include="Concordion\Command\AssertEquals\ExceptionsTest.cs" />
<Compile Include="Concordion\Command\AssertEquals\NonString\BooleanTest.cs" />
<Compile Include="Concordion\Command\AssertEquals\Whitespace\LineContinuationsTest.cs" />
<Compile Include="Concordion\Command\AssertEquals\NestedActionsTest.cs" />
<Compile Include="Concordion\Command\AssertEquals\NestedHtmlElementsTest.cs" />
Expand Down Expand Up @@ -132,11 +134,6 @@
<Name>Concordion</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Concordion.Spec.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Examples\Demo.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down Expand Up @@ -325,6 +322,11 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Concordion\Command\AssertEquals\NonString\Boolean.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ <h2>Further Details</h2>
<li><a href="Exceptions.html">What if the evaluation throws an exception?</a></li>
<li><a href="NestedElements.html">Are nested HTML elements (e.g. &lt;strong&gt;) supported?</a></li>
<li><a href="SupportedElements.html">Can this tag be used on elements other than &lt;span&gt;?</a></li>
<li><a href="NonString/Boolean.html">Which strings can be used to match a bool?</a></li>
</ul>


Expand Down
138 changes: 138 additions & 0 deletions Concordion.Spec/Concordion/Command/AssertEquals/NonString/Boolean.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<html xmlns:concordion="http://www.concordion.org/2007/concordion">
<head>
<meta content="text/html; charset=windows-1252" http-equiv="content-type" />
<link href="../../../../concordion.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Boolean String Mapping</h1>
<p> Allow the assertEquals command to match "Yes/No" "True/False" "Y/N" "Yes/-" with a Boolean returned from the
system under test. </p>
<p>To indicate an expected value of "true" any of the following strings can be used:</p>
<ul>
<li>true</li>
<li>yes </li>
<li>y</li>
</ul>
<p>To indicate an expected value of "false" any of the following strings can be used:</p>
<ul>
<li>false</li>
<li>no</li>
<li>n</li>
<li>-</li>
</ul>
<p>The strings are compared in a non case sensitive way. Thus, all combination of upper and lower case are allowed
in the previous list of allowed stings (e.g. tRUe).</p>
<div class="example">
<h3>Example</h3>
<p>Given this instrumentation:</p>
<pre concordion:set="#snippet">&lt;span concordion:assertEquals="#GetBooleanValue()"&gt;<b><em>(some boolean string)</em></b>&lt;/span&gt;</pre>
<p>We get the following outcomes depending on the bool result of the method "GetBooleanValue" and the value
replaced instead of "Boolean String"<code></code>:</p>
<table concordion:execute="#outcome = OutcomeOfPerformingAssertEquals(#snippet, #boolValue, #boolString)">
<thead>
<tr>
<th concordion:set="#boolValue">GetBooleanValue()</th>
<th concordion:set="#boolString">Boolean String</th>
<th concordion:assertEquals="#outcome">Outcome ?</th>
</tr>
</thead>
<tbody>
<tr>
<td>true</td>
<td>true</td>
<td>SUCCESS</td>
</tr>
<tr>
<td>true</td>
<td>True</td>
<td>SUCCESS</td>
</tr>
<tr>
<td>true</td>
<td>TRUE</td>
<td>SUCCESS</td>
</tr>
<tr>
<td>true</td>
<td>tRuE</td>
<td>SUCCESS</td>
</tr>
<tr>
<td>true</td>
<td>Yes</td>
<td>SUCCESS</td>
</tr>
<tr>
<td>true</td>
<td>Y</td>
<td>SUCCESS</td>
</tr>
<tr>
<td>true</td>
<td>FALSE</td>
<td>FAILURE</td>
</tr>
<tr>
<td>true</td>
<td>no</td>
<td>FAILURE</td>
</tr>
<tr>
<td>true</td>
<td>-</td>
<td>FAILURE</td>
</tr>
<tr>
<td>true</td>
<td>SomeString</td>
<td>FAILURE</td>
</tr>
<tr>
<td>false</td>
<td>False</td>
<td>SUCCESS</td>
</tr>
<tr>
<td>false</td>
<td>No</td>
<td>SUCCESS</td>
</tr>
<tr>
<td>false</td>
<td>N</td>
<td>SUCCESS</td>
</tr>
<tr>
<td>false</td>
<td>-</td>
<td>SUCCESS</td>
</tr>
<tr>
<td>false</td>
<td>_</td>
<td>FAILURE</td>
</tr>
<tr>
<td>false</td>
<td>True</td>
<td>FAILURE</td>
</tr>
<tr>
<td>false</td>
<td>OtherString</td>
<td>FAILURE</td>
</tr>
<tr>
<td>false</td>
<td>StringContainingFalse</td>
<td>FAILURE</td>
</tr>
</tbody>
</table>
</div>
<h2>Further Details</h2>
<ul>
<li><a href="../Whitespace/LineContinuations.html">Line continuations</a></li>
</ul>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Concordion.Integration;

namespace Concordion.Spec.Concordion.Command.AssertEquals.NonString
{
[ConcordionTest]
public class BooleanTest
{
public string OutcomeOfPerformingAssertEquals(string fragment, bool boolValue, string boolString)
{
return new TestRig()
.WithStubbedEvaluationResult(boolValue)
.ProcessFragment(Regex.Replace(fragment, "\\(some boolean string\\)", boolString))
.SuccessOrFailureInWords();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public string normalize(string s)
{
// Bit naughty calling internal method normalize() directly
return replaceRealWhitespaceCharactersWithNames(
BrowserStyleWhitespaceComparer.Normalize(replaceNamedWhitespaceWithRealWhitespaceCharacters(s)));
new DefaultExpectationChecker().Normalize(replaceNamedWhitespaceWithRealWhitespaceCharacters(s)));
}

private static string replaceNamedWhitespaceWithRealWhitespaceCharacters(string s)
Expand Down
2 changes: 1 addition & 1 deletion Concordion.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Concordion.Spec", "Concordi
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gallio.ConcordionAdapter", "Gallio.ConcordionAdapter\Gallio.ConcordionAdapter.csproj", "{57D6B2E4-69A8-42A6-8220-AAE6EDFB902D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Concordion.Integration.NUnit", "Concordion.Integration.NUnit\Concordion.Integration.NUnit.csproj", "{FB522DBB-6F64-4834-9C87-029389AA0ABB}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Concordion.NUnit", "Concordion.NUnit\Concordion.NUnit.csproj", "{FB522DBB-6F64-4834-9C87-029389AA0ABB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
5 changes: 5 additions & 0 deletions Concordion/Concordion.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@
</Compile>
<Compile Include="Integration\ConcordionAssemblyAttribute.cs" />
<Compile Include="Integration\ConcordionTestAttribute.cs" />
<Compile Include="Internal\AbstractCheckerBase.cs" />
<Compile Include="Internal\BannedWordsValidator.cs" />
<Compile Include="Internal\BooleanExpectationChecker.cs" />
<Compile Include="Internal\BrowserStyleWhitespaceComparer.cs" />
<Compile Include="Internal\ChainOfExpectationCheckers.cs" />
<Compile Include="Internal\ClassNameBasedSpecificationLocator.cs" />
<Compile Include="Internal\CommandCall.cs" />
<Compile Include="Internal\CommandCallList.cs" />
Expand Down Expand Up @@ -146,8 +149,10 @@
<Compile Include="Internal\ConcordionConfig.cs" />
<Compile Include="Internal\ConcordionConfigParser.cs" />
<Compile Include="Internal\ConcordionModule.cs" />
<Compile Include="Internal\DefaultExpectationChecker.cs" />
<Compile Include="Internal\DocumentParser.cs" />
<Compile Include="Internal\EmbeddedResourceSource.cs" />
<Compile Include="Internal\IExpectationChecker.cs" />
<Compile Include="Internal\ExpectedToFailFixtureState.cs" />
<Compile Include="Internal\FileSource.cs" />
<Compile Include="Internal\FileTarget.cs" />
Expand Down
49 changes: 49 additions & 0 deletions Concordion/Internal/AbstractCheckerBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Text.RegularExpressions;

namespace Concordion.Internal
{
public abstract class AbstractCheckerBase : IExpectationChecker
{
public abstract bool IsAcceptable(string expected, object actual);

public string Normalize(object obj)
{
string s = this.ConvertObjectToString(obj);
s = this.ProcessLineContinuations(s);
s = this.StripNewlines(s);
s = this.ReplaceMultipleWhitespaceWithOneSpace(s);
return s.Trim();
}

private string ReplaceMultipleWhitespaceWithOneSpace(string s)
{
var lineContinuationRegex = new Regex(@"[\s]+");
var processedString = lineContinuationRegex.Replace(s, " ");

return processedString;
}

private string ProcessLineContinuations(string s)
{
var lineContinuationRegex = new Regex(@" _");
var processedString = lineContinuationRegex.Replace(s, String.Empty);

return processedString;
}

private string StripNewlines(string s)
{
var newlineRegex = new Regex(@"\r?\n");
var processedString = newlineRegex.Replace(s, String.Empty);

return processedString;
}

private string ConvertObjectToString(object obj)
{
if (obj == null) return "(null)";
else return obj.ToString();
}
}
}
22 changes: 22 additions & 0 deletions Concordion/Internal/BooleanExpectationChecker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Concordion.Internal
{
public class BooleanExpectationChecker : AbstractCheckerBase
{

public override bool IsAcceptable(string expected, object actual)
{
if (!(actual is bool)) return false;

var boolActual = (bool) actual;
var normalizedExpected = this.Normalize(expected).ToLower();
return (boolActual && Regex.IsMatch(normalizedExpected, "^(true|yes|y)$")) ||
(!boolActual && Regex.IsMatch(normalizedExpected, "^(false|no|n|-)$"));
}
}
}
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载