forked from x97mdr/pickles
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
289 additions
and
12 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/Pickles/Pickles.Test/FakeFolderStructures/AcceptanceTest/AdvancedFeature.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
@FeatureTag | ||
Feature: Feature title | ||
In order to avoid silly mistakes | ||
As a math idiot | ||
I want to be told the sum of two numbers | ||
|
||
Background: Background name | ||
Given background given | ||
When background when | ||
Then background then | ||
|
||
@simpleScenario | ||
Scenario: Simple Scenario | ||
Given simple scenario given | ||
And simple scenario given and | ||
When simple scenario when | ||
Then simple scenario then | ||
|
||
@scenarioOutline | ||
Scenario Outline: Scenario outline example | ||
Given outline given <value 1> | ||
When outline when <value 2> | ||
Then outline then <value 3> | ||
But nothing important here | ||
|
||
Scenarios: | ||
| value 1 | value 2 | value 3 | | ||
| 123 | 456 | 789 | | ||
| abc | def | ghi | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/Pickles/Pickles.Test/Formatters/JSON/when_creating_a_feature_with_meta_info.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.IO; | ||
using NUnit.Framework; | ||
using Pickles.DirectoryCrawler; | ||
using Pickles.DocumentationBuilders.JSON; | ||
using Pickles.Parser; | ||
using Should.Fluent; | ||
|
||
namespace Pickles.Test.Formatters.JSON | ||
{ | ||
public class when_creating_a_feature_with_meta_info | ||
{ | ||
|
||
private const string RELATIVE_PATH = @"AcceptanceTest"; | ||
private const string ROOT_PATH = @"FakeFolderStructures\AcceptanceTest"; | ||
private const string FEATURE_PATH = @"AdvancedFeature.feature"; | ||
|
||
private Feature _testFeature; | ||
private FileInfo _featureFileInfo; | ||
private FeatureDirectoryTreeNode _featureDirectoryNode; | ||
private FeatureWithMetaInfo _featureWithMeta; | ||
|
||
[TestFixtureSetUp] | ||
public void Setup() | ||
{ | ||
_testFeature = new Feature { Name = "Test" }; | ||
_featureFileInfo = new FileInfo(Path.Combine(ROOT_PATH, FEATURE_PATH)); | ||
_featureDirectoryNode = new FeatureDirectoryTreeNode(_featureFileInfo, RELATIVE_PATH, _testFeature); | ||
|
||
_featureWithMeta = new FeatureWithMetaInfo(_featureDirectoryNode); | ||
|
||
} | ||
|
||
[Test] | ||
public void it_should_contain_the_feature() | ||
{ | ||
_featureWithMeta.Feature.Should().Not.Be.Null(); | ||
_featureWithMeta.Feature.Name.Should().Equal("Test"); | ||
} | ||
|
||
[Test] | ||
public void it_should_contain_the_relative_path() | ||
{ | ||
_featureWithMeta.RelativeFolder.Should().Equal(RELATIVE_PATH); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/Pickles/Pickles.Test/Formatters/JSON/when_formatting_a_folder_structure_with_features.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.IO; | ||
using Ninject; | ||
using NUnit.Framework; | ||
using Pickles.DirectoryCrawler; | ||
using Pickles.DocumentationBuilders.JSON; | ||
using Should.Fluent; | ||
using Pickles.Test.Helpers; | ||
|
||
|
||
namespace Pickles.Test.Formatters.JSON | ||
{ | ||
[TestFixture] | ||
public class when_formatting_a_folder_structure_with_features : BaseFixture | ||
{ | ||
private string filePath = Path.Combine(OUTPUT_DIRECTORY, JSONDocumentationBuilder.JS_FILE_NAME); | ||
private const string ROOT_PATH = @"FakeFolderStructures"; | ||
private const string OUTPUT_DIRECTORY = @"C:\temp\"; | ||
|
||
|
||
[TestFixtureSetUp] | ||
public void Setup() | ||
{ | ||
var features = Kernel.Get<DirectoryTreeCrawler>().Crawl(ROOT_PATH); | ||
|
||
var configuration = new Configuration | ||
{ | ||
OutputFolder = new DirectoryInfo(OUTPUT_DIRECTORY), | ||
DocumentationFormat = DocumentationFormat.JSON | ||
}; | ||
|
||
var jsonDocumentationBuilder = new JSONDocumentationBuilder(configuration); | ||
jsonDocumentationBuilder.Build(features); | ||
} | ||
|
||
[Test] | ||
public void a_single_file_should_have_been_created() | ||
{ | ||
File.Exists(filePath).Should().Be.True(); | ||
} | ||
|
||
[Test] | ||
public void should_contain_the_features() | ||
{ | ||
var content = File.ReadAllText(filePath); | ||
content.AssertJSONKeyValue("Name", "Addition"); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Pickles/Pickles.Test/Helpers/JSONStringAssertHelpers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Should.Fluent; | ||
|
||
namespace Pickles.Test.Helpers | ||
{ | ||
public static class JSONStringAssertHelpers | ||
{ | ||
private const string KEY_VALUE_TEMPLATE = "\"{0}\": \"{1}\""; | ||
private const string ARRAY_TEMPLATE = "\"{0}\": [\r\n \"{1}\"\r\n ]"; | ||
|
||
public static void AssertJSONKeyValue(this string json, string key, string value) | ||
{ | ||
json.Should().Contain(string.Format(KEY_VALUE_TEMPLATE, key, value)); | ||
} | ||
|
||
public static void AssertJSONArrayValue(this string json, string key, string value) | ||
{ | ||
json.Should().Contain(string.Format(ARRAY_TEMPLATE, key, value)); | ||
} | ||
} | ||
} |
5 changes: 2 additions & 3 deletions
5
src/Pickles/Pickles.Test/Helpers/Class1.cs → ...Pickles.Test/Helpers/XElementExentions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/Pickles/Pickles/DocumentationBuilders/JSON/FeatureWithMetaInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using Pickles.DirectoryCrawler; | ||
using Pickles.Parser; | ||
|
||
namespace Pickles.DocumentationBuilders.JSON | ||
{ | ||
public class FeatureWithMetaInfo | ||
{ | ||
public string RelativeFolder { get; set; } | ||
public Feature Feature { get; set; } | ||
|
||
public FeatureWithMetaInfo(FeatureDirectoryTreeNode featureNodeTreeNode) | ||
{ | ||
Feature = featureNodeTreeNode.Feature; | ||
RelativeFolder = featureNodeTreeNode.RelativePathFromRoot; | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
src/Pickles/Pickles/DocumentationBuilders/JSON/JSONDocumentationBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#region License | ||
|
||
/* | ||
Copyright [2011] [Jeffrey Cameron] | ||
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. | ||
*/ | ||
|
||
#endregion | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
using NGenerics.DataStructures.Trees; | ||
using NGenerics.Patterns.Visitor; | ||
using Pickles.DirectoryCrawler; | ||
|
||
namespace Pickles.DocumentationBuilders.JSON | ||
{ | ||
public class JSONDocumentationBuilder : IDocumentationBuilder | ||
{ | ||
|
||
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||
|
||
private readonly Configuration configuration; | ||
|
||
public const string JS_FILE_NAME = @"pickledFeatures.json"; | ||
|
||
|
||
public JSONDocumentationBuilder(Configuration configuration) | ||
{ | ||
this.configuration = configuration; | ||
} | ||
|
||
public void Build(GeneralTree<IDirectoryTreeNode> features) | ||
{ | ||
if (log.IsInfoEnabled) | ||
{ | ||
log.InfoFormat("Writing JSON to {0}", this.configuration.OutputFolder.FullName); | ||
} | ||
|
||
var featuresToFormat = new List<FeatureWithMetaInfo>(); | ||
|
||
var actionVisitor = new ActionVisitor<IDirectoryTreeNode>(node => | ||
{ | ||
var featureTreeNode = node as FeatureDirectoryTreeNode; | ||
if (featureTreeNode != null) | ||
{ | ||
featuresToFormat.Add(new FeatureWithMetaInfo(featureTreeNode)); | ||
} | ||
}); | ||
|
||
features.AcceptVisitor(actionVisitor); | ||
|
||
CreateFile(OutputFilePath, GenerateJSON(featuresToFormat)); | ||
} | ||
|
||
private string OutputFilePath | ||
{ | ||
get { return Path.Combine(configuration.OutputFolder.FullName, JS_FILE_NAME); } | ||
} | ||
|
||
private static string GenerateJSON(List<FeatureWithMetaInfo> features) | ||
{ | ||
var settings = new JsonSerializerSettings | ||
{ | ||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore, | ||
NullValueHandling = NullValueHandling.Ignore, | ||
Converters = new List<JsonConverter> { new StringEnumConverter() } | ||
}; | ||
|
||
return JsonConvert.SerializeObject(features, Formatting.Indented, settings); | ||
} | ||
|
||
private static void CreateFile(string outputFolderName, string jsonToWrite) | ||
{ | ||
using (var writer = new StreamWriter(outputFolderName, false, Encoding.UTF8)) | ||
{ | ||
writer.Write(jsonToWrite); | ||
writer.Close(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ public enum DocumentationFormat | |
{ | ||
Html, | ||
Word, | ||
Dita | ||
Dita, | ||
JSON | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.