Skip to content

Commit

Permalink
Add Unit tests and fix failed ones
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Gondermann committed Oct 4, 2018
1 parent 7de933d commit 64c2f15
Show file tree
Hide file tree
Showing 14 changed files with 684 additions and 71 deletions.
7 changes: 7 additions & 0 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ Target "BuildTest.Runners.CommandLine" (fun _ ->
|> Log "AppBuild-Output: "
)

Target "BuildTest.Runners.UI" (fun _ ->
!! "src/Pickles/Pickles.UserInterface.UnitTests/Pickles.UserInterface.UnitTests.csproj"
|> MSBuildRelease testDir "Build"
|> Log "AppBuild-Output: "
)

let createZip (packageType : string) =
!! (buildDir + "/" + packageType + "/*.*") -- "*.zip"
|> Zip (buildDir + packageType) (deployDir + "Pickles-" + packageType + "-" + version + ".zip")
Expand Down Expand Up @@ -151,6 +157,7 @@ Target "Default" (fun _ ->
==> "BuildTest.DocumentationBuilders.Json"
==> "BuildTest.DocumentationBuilders.Word"
==> "BuildTest.Runners.CommandLine"
==> "BuildTest.Runners.UI"
==> "Zip"
==> "Default"

Expand Down
2 changes: 1 addition & 1 deletion src/Pickles/.vs/config/applicationhost.config
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
</site>
<site name="Pickles.BaseDhtmlFiles" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Dev\Code\GitHub\DirkRombauts\pickles\src\Pickles\Pickles.BaseDhtmlFiles" /> </application>
<virtualDirectory path="/" physicalPath="C:\Projects\pickles\src\Pickles\Pickles.BaseDhtmlFiles" /> </application>
<bindings>
<binding protocol="http" bindingInformation="*:52000:localhost" />
</bindings>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CLICommandGeneratorTests.cs" company="PicklesDoc">
// Copyright 2011 Jeffrey Cameron
// Copyright 2012-present PicklesDoc team and community contributors
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------


using NFluent;

using NUnit.Framework;

using PicklesDoc.Pickles;
using PicklesDoc.Pickles.UserInterface.CommandGeneration;
using PicklesDoc.Pickles.UserInterface.Settings;

namespace System.CommandGeneration
{
[TestFixture]
public class WhenGeneratingCLICommands : PicklesDoc.Pickles.Test.BaseFixture
{
private const string MinimalCommandLine = @"pickles.exe --feature-directory=""C:\Specs"" ";

private MainModel CreateMinimalModel()
{
return
new MainModel
{
FeatureDirectory = @"C:\Specs",
DocumentationFormats = new[] { DocumentationFormat.Html },
EnableComments = true,
TestResultsFormat = TestResultsFormat.NUnit
};
}

private CommandGeneratorBase CreateGenerator()
{
return new CLICommandGenerator();
}

[Test]
public void ThenASingleCommandIsGeneratedForEverySelectedDocumentFormat()
{
var model = new MainModel
{
FeatureDirectory = @"C:\Specs",
DocumentationFormats = new[] { DocumentationFormat.Cucumber, DocumentationFormat.Json },
EnableComments = true
};

var sut = this.CreateGenerator();

Check.That(sut.Generate(model, "en"))
.IsEqualTo(
@"pickles.exe --feature-directory=""C:\Specs"" --documentation-format=cucumber"
+ Environment.NewLine
+ @"pickles.exe --feature-directory=""C:\Specs"" --documentation-format=json");
}

[Test]
public void ThenTheDocumentFormatIsAppendedToTheOutputDirectoryIfCreateDirectoryForEachOutputFormatIsTrue()
{
var model = new MainModel
{
FeatureDirectory = @"C:\Specs",
OutputDirectory = @"C:\Out",
CreateDirectoryForEachOutputFormat = true,
DocumentationFormats = new[] { DocumentationFormat.Cucumber, DocumentationFormat.Json },
EnableComments = true
};

var sut = this.CreateGenerator();

Check.That(sut.Generate(model, "en"))
.IsEqualTo(
@"pickles.exe --feature-directory=""C:\Specs"" --output-directory=""C:\Out\Cucumber"" --documentation-format=cucumber"
+ Environment.NewLine
+ @"pickles.exe --feature-directory=""C:\Specs"" --output-directory=""C:\Out\Json"" --documentation-format=json");
}

[Test]
public void ThenTheDocumentFormatIsAppendedToTheOutputDirectoryIfCreateDirectoryForEachOutputFormatIsTrueIfOutputDirectoryEndsWithDirectorySeparator()
{
var model = new MainModel
{
FeatureDirectory = @"C:\Specs",
OutputDirectory = @"C:\Out\",
CreateDirectoryForEachOutputFormat = true,
DocumentationFormats = new[] { DocumentationFormat.Cucumber, DocumentationFormat.Json },
EnableComments = true
};

var sut = this.CreateGenerator();

Check.That(sut.Generate(model, "en"))
.IsEqualTo(
@"pickles.exe --feature-directory=""C:\Specs"" --output-directory=""C:\Out\Cucumber"" --documentation-format=cucumber"
+ Environment.NewLine
+ @"pickles.exe --feature-directory=""C:\Specs"" --output-directory=""C:\Out\Json"" --documentation-format=json");
}

[Test]
public void ThenTheProjectNameAndVersionIsAppendedIfSet()
{
var model = this.CreateMinimalModel();
model.ProjectName = "TestProject";
model.ProjectVersion = "v1.2.4beta1";

var sut = this.CreateGenerator();

Check.That(sut.Generate(model, "en"))
.IsEqualTo(MinimalCommandLine + "--system-under-test-name=TestProject --system-under-test-version=v1.2.4beta1");
}

[Test]
public void ThenTheTestResultsFormatAndTheLinkedResultsFileIsAppendedIfIncludeTestResultsIsTrue()
{
var model = this.CreateMinimalModel();
model.IncludeTestResults = true;
model.TestResultsFile = "result.xml";
model.TestResultsFormat = TestResultsFormat.XUnit;

var sut = this.CreateGenerator();

Check.That(sut.Generate(model, "en"))
.IsEqualTo(MinimalCommandLine + @"--link-results-file=""result.xml"" --test-results-format=xunit");
}

[Test]
public void ThenTheLinkedResultsFileIsAppendedOnlyIfIncludeTestResultsIsTrueAndTheTestResultsFormatIsNunit()
{
var model = this.CreateMinimalModel();
model.IncludeTestResults = true;
model.TestResultsFile = "result.xml";
model.TestResultsFormat = TestResultsFormat.NUnit;

var sut = this.CreateGenerator();

Check.That(sut.Generate(model, "en"))
.IsEqualTo(MinimalCommandLine + @"--link-results-file=""result.xml""");
}

[Test]
public void ThenLanguageIsAppendedIfItIsNotEnglish()
{
var model = this.CreateMinimalModel();

var sut = this.CreateGenerator();

Check.That(sut.Generate(model, "de"))
.IsEqualTo(MinimalCommandLine + @"--language=de");
}

[Test]
public void ThenTheIncludeExperimentalFeaturesFlagIsAppendedIfIncludeExperimentalFeaturesIsTrue()
{
var model = this.CreateMinimalModel();
model.IncludeExperimentalFeatures = true;

var sut = this.CreateGenerator();

Check.That(sut.Generate(model, "en"))
.IsEqualTo(MinimalCommandLine + @"--include-experimental-features");
}

[Test]
public void ThenTheEnableCommentsFlagIsAppendedIfIncludeEnableCommentsIsFalse()
{
var model = this.CreateMinimalModel();
model.EnableComments = false;

var sut = this.CreateGenerator();

Check.That(sut.Generate(model, "en"))
.IsEqualTo(MinimalCommandLine + @"--enableComments=false");
}

[Test]
public void ThenTheExcludeTagsAreAppendedIfSet()
{
var model = this.CreateMinimalModel();
model.ExcludeTags = "ignore,foo";

var sut = this.CreateGenerator();

Check.That(sut.Generate(model, "en"))
.IsEqualTo(MinimalCommandLine + @"--excludeTags=ignore,foo");
}

[Test]
public void ThenTheHideTagsAreAppendedIfSet()
{
var model = this.CreateMinimalModel();
model.HideTags = "ignore,foo";

var sut = this.CreateGenerator();

Check.That(sut.Generate(model, "en"))
.IsEqualTo(MinimalCommandLine + @"--hideTags=ignore,foo");
}
}
}
Loading

0 comments on commit 64c2f15

Please sign in to comment.