Skip to content

Commit

Permalink
Add a test to check the issue in #514
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric L. Charlier committed Sep 7, 2019
1 parent 0b7d641 commit 3e37143
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 4 deletions.
3 changes: 3 additions & 0 deletions NBi.Testing/Acceptance/GenbiL/Resources/ResultSetFile.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fileSut;fileAssert
..\csv\001.csv;..\txt\001.txt
..\csv\002.csv;..\txt\002.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<testSuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://NBi/TestSuite">
<settings />
<test name="Compare '..\csv\001.csv' to '..\txt\001.txt'">
<system-under-test>
<result-set>
<file>
<path>..\csv\001.csv</path>
</file>
</result-set>
</system-under-test>
<assert>
<equal-to>
<result-set>
<file>
<path>..\txt\001.txt</path>
<parser name="myTextParser" />
</file>
</result-set>
</equal-to>
</assert>
</test>
<test name="Compare '..\csv\002.csv' to '..\txt\002.txt'">
<system-under-test>
<result-set>
<file>
<path>..\csv\002.csv</path>
</file>
</result-set>
</system-under-test>
<assert>
<equal-to>
<result-set>
<file>
<path>..\txt\002.txt</path>
<parser name="myTextParser" />
</file>
</result-set>
</equal-to>
</assert>
</test>
</testSuite>
6 changes: 6 additions & 0 deletions NBi.Testing/Acceptance/GenbiL/Resources/ResultSetFile.genbil
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
case load file 'Acceptance\GenbiL\Resources\ResultSetFile.csv';

template load file 'Acceptance\GenbiL\Resources\ResultSetFile.nbitt';
suite generate;
suite save as 'Acceptance\GenbiL\Resources\ResultSetFile.nbits';

10 changes: 10 additions & 0 deletions NBi.Testing/Acceptance/GenbiL/Resources/ResultSetFile.nbitt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<test name="Compare '$fileSut$' to '$fileAssert$'">
<system-under-test>
<result-set file="$fileSut$" />
</system-under-test>
<assert>
<equal-to>
<result-set file="$fileAssert$!myTextParse" />
</equal-to>
</assert>
</test>
73 changes: 73 additions & 0 deletions NBi.Testing/Acceptance/GenbiL/ResultSetFileTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using NBi.GenbiL;
using NUnit.Framework;

namespace NBi.Testing.Acceptance.GenbiL
{
[TestFixture]
public class ResultSetFileTest
{
private const string TEST_SUITE_NAME="ResultSetFile";
private string DefinitionFilename { get => $"Acceptance\\GenbiL\\Resources\\{TEST_SUITE_NAME}.genbil"; }
private string TargetFilename { get => $"Acceptance\\GenbiL\\Resources\\{TEST_SUITE_NAME}.nbits"; }
private string ExpectedFilename { get => $"Acceptance\\GenbiL\\Resources\\{TEST_SUITE_NAME}.expected.nbits"; }

#region SetUp & TearDown
//Called only at instance creation
[TestFixtureSetUp]
public void SetupMethods()
{

}

//Called only at instance destruction
[TestFixtureTearDown]
public void TearDownMethods()
{

}

//Called before each test
[SetUp]
public void SetupTest()
{
if (File.Exists(TargetFilename))
File.Delete(TargetFilename);
}

//Called after each test
[TearDown]
public void TearDownTest()
{
//if (File.Exists(TargetFilename))
// File.Delete(TargetFilename);
}
#endregion

[Test]
public void Execute_Group_FileGenerated()
{
var generator = new TestSuiteGenerator();
generator.Load(DefinitionFilename);
generator.Execute();

Assert.That(File.Exists(TargetFilename));
}

[Test]
public void Execute_Group_ExpectedContent()
{
var generator = new TestSuiteGenerator();
generator.Load(DefinitionFilename);
generator.Execute();

var expected = File.ReadAllText(ExpectedFilename);
var actual = File.ReadAllText(TargetFilename);
actual = Regex.Replace(actual, @"(\s*)<edition(.*)/>", "", RegexOptions.Multiline);
Assert.That(actual, Is.EqualTo(expected));
}
}
}
21 changes: 17 additions & 4 deletions NBi.Testing/NBi.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
<Compile Include="Acceptance\GenbiL\DictionaryTest.cs" />
<Compile Include="Acceptance\GenbiL\ConsumablesTest.cs" />
<Compile Include="Acceptance\GenbiL\ExecutionEqualTo.cs" />
<Compile Include="Acceptance\GenbiL\ResultSetFileTest.cs" />
<Compile Include="Acceptance\GenbiL\GroupByTest.cs" />
<Compile Include="Acceptance\GenbiL\SplitDistinctTest.cs" />
<Compile Include="Acceptance\GenbiL\SyntaxOldNewTest.cs" />
Expand Down Expand Up @@ -352,7 +353,19 @@
<EmbeddedResource Include="Acceptance\GenbiL\Resources\MultipleTemplates1.nbitt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<None Include="Acceptance\GenbiL\Resources\dictionary.csv">
<None Include="Acceptance\GenbiL\Resources\ResultSetFile.expected.nbits">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Acceptance\GenbiL\Resources\ResultSetFile.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<EmbeddedResource Include="Acceptance\GenbiL\Resources\ResultSetFile.genbil">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Acceptance\GenbiL\Resources\ResultSetFile.nbitt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<None Include="Acceptance\GenbiL\Resources\Dictionary.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Acceptance\GenbiL\Resources\Consumables.csv">
Expand All @@ -361,10 +374,10 @@
<EmbeddedResource Include="Acceptance\GenbiL\Resources\Consumables.genbil">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Acceptance\GenbiL\Resources\dictionary.nbitt">
<EmbeddedResource Include="Acceptance\GenbiL\Resources\Dictionary.nbitt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Acceptance\GenbiL\Resources\dictionary.genbil">
<EmbeddedResource Include="Acceptance\GenbiL\Resources\Dictionary.genbil">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Acceptance\GenbiL\Resources\SyntaxOldNew.genbil">
Expand Down Expand Up @@ -751,7 +764,7 @@
<EmbeddedResource Include="Acceptance\Resources\PurchaseOrders.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<None Include="Acceptance\GenbiL\Resources\dimension.csv">
<None Include="Acceptance\GenbiL\Resources\Dimension.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<EmbeddedResource Include="Acceptance\Resources\Negative\ItemsMessage-0002.txt" />
Expand Down

0 comments on commit 3e37143

Please sign in to comment.