Skip to content

Commit 7900bfc

Browse files
Removed GenerationException throw when default patterns file is not found.
1 parent 52a869c commit 7900bfc

File tree

13 files changed

+46
-171
lines changed

13 files changed

+46
-171
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ A library and command line tool that can be used to generate data for testing, t
2525
If you are familiar with Regular Expressions then most of the syntax used will be familiar but there are significant differences in place given that regex is used to match a string against a pattern. The generator instead uses simple patterns of symbols to produce strings, because of the difference in usage the syntaxes cannot match up entirely. Patterns define what the generated values will be and can be composed using text and symbols. Sections of the pattern can be repeated a specific number of times (they can also be repeated a random number of times by providing a min and max). Patterns can also include alternate items that will be randomly selected, helping to produce relatively complicated outputs.
2626

2727
### Symbols
28-
The pattern is as follows:
28+
The following symbols are shorthand tokens which you can use in your generation patterns:
2929
- `\.` - A single random character of any type.
3030
- `\W` - A single random character from the following list ' .,;:\"'!&?£€$%^<>{}[]()*+-=\@#|~/'.
3131
- `\w` - A single random upper-case or lower-case letter.
@@ -37,6 +37,7 @@ The pattern is as follows:
3737
- `\c` - A single random lower-case consonant.
3838
- `\D` - A single random non number character.
3939
- `\d` - A single random number, 1-9.
40+
- `\S` - A single random non-whitespace character
4041
- `\s` - A whitespace character (Tab, New Line, Space, Carriage Return or Form Feed)
4142
- `\n` - A newline character.
4243
- `\t` - A tab character.
@@ -128,6 +129,8 @@ You can use the `tdg.exe` application to generate test data from the command lin
128129
### Pattern Files
129130
Pattern files contain Named Patterns which can be used within Templates. TDG comes with a few pattern files contained within the 'tdg-patterns' folder and you can add your own if you wish. The files are structured as simple xml documents that should be pretty self explanatory. To use a pattern file you have created you need to add its path to a GenerationConfig object when using the library or as part of the configuration directive at the start of a template. You can also include them from the command line using the `-n` or `--namedpatterns` argument.
130131

132+
**If you are adding TDG to a project using nuget and wish to use some of the named patterns defined in default.tdg-patterns you will need to change its build settings to "Content" and "Copy Always" to ensure it gets deployed with your application.**
133+
131134
### Commandline examples
132135
- Single repeating symbols using the following syntax
133136
- `tdg -t 'Letters <<\L{20}>> and Numbers <<\d{12}>>'`
@@ -147,7 +150,7 @@ Pattern files contain Named Patterns which can be used within Templates. TDG com
147150
- Generate 100 strings with random name like values and output to file.
148151
- `tdg -t 'Hi there <<\L\v\l\v \L\v\l\l\v\v\l\l\v>> how are you doing?' -c 100 -o C:\test1.txt`
149152
- Produces 100 items like *'Aepi Euuwoavio'*.
150-
- `tdg -t '<<Letters \w{2,20} and Numbers \d{2,12}\n>>'` produces the following output: *'Letters lKYjfCAuZEz and Numbers 1134618008
153+
- `tdg -t '<<Letters \w{2,20} and Numbers \d{2,12}\n>>'` produces the following output: *'Letters nR9mhIGy_KE and Numbers 1134618008
151154
'*
152155

153156
## This README was generated using the generator. See the unit tests for other examples.

VERSION

0 Bytes
Binary file not shown.

make.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function document{
103103
Write-host "DOCUMENT FAILED!" -foregroundcolor:red
104104
exit
105105
}
106-
Invoke-expression "./src/buildoutput/tdg.exe -i '.\src\templates\README.template.txt' -o '.\src\buildoutput\README.txt'"
106+
Invoke-expression "./src/buildoutput/tdg.exe -i '.\src\templates\README.template.md' -o '.\src\buildoutput\README.txt'"
107107
if($? -eq $False){
108108
Write-host "DOCUMENT FAILED!" -foregroundcolor:red
109109
exit
@@ -124,7 +124,7 @@ function deploy{
124124
# DEPLOYING
125125
write-host "Deploying" -foregroundcolor:blue
126126
$outputName = $projectName+"_V"+$buildVersion+"_BUILD.zip"
127-
zip a -tzip .\src\buildoutput\$outputName -r .\src\BuildOutput\*.* >> $logPath\LogDeploy.log
127+
zip a -tzip .\releases\$outputName -r .\src\BuildOutput\*.* >> $logPath\LogDeploy.log
128128

129129
}
130130

66.9 KB
Binary file not shown.

releases/tdg.3.4.1.0.nupkg

88.2 KB
Binary file not shown.

src/DataGenerator/gk.DataGenerator.CommandLine/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("3.4.0.0")]
34+
[assembly: AssemblyVersion("3.4.1.0")]

src/DataGenerator/gk.DataGenerator.CommandLine/gk.DataGenerator.tdg.nuspec

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
<tags>Test data generator generate regular expression</tags>
1616
</metadata>
1717
<files>
18-
<file src="C:\Development\projects\github.com\secretdeveloper\TestDataGenerator\src\BuildOutput\gk.DataGenerator.dll" target="lib\net45\gk.DataGenerator.dll" />
19-
<file src="C:\Development\projects\github.com\secretdeveloper\TestDataGenerator\src\BuildOutput\tdg.exe" target="lib\net45\tdg.exe" />
20-
<file src="C:\Development\projects\github.com\secretdeveloper\TestDataGenerator\src\BuildOutput\tdg-patterns\default.tdg-patterns" target="lib\net45\tdg-patterns\default.tdg-patterns" />
21-
<file src="C:\Development\projects\github.com\secretdeveloper\TestDataGenerator\src\BuildOutput\tdg-patterns\language.tdg-patterns" target="lib\net45\tdg-patterns\language.tdg-patterns" />
22-
<file src="C:\Development\projects\github.com\secretdeveloper\TestDataGenerator\src\BuildOutput\Eloquent.dll" target="lib\net45\Eloquent.dll" />
23-
<file src="C:\Development\projects\github.com\secretdeveloper\TestDataGenerator\src\BuildOutput\CommandLine.dll" target="lib\net45\CommandLine.dll" />
24-
<file src="C:\Development\projects\github.com\secretdeveloper\TestDataGenerator\src\BuildOutput\CommandLine.xml" target="lib\net45\CommandLine.xml" />
25-
<file src="C:\Development\projects\github.com\secretdeveloper\TestDataGenerator\src\BuildOutput\tdg.exe.config" target="lib\net45\tdg.exe.config" />
18+
<file src="C:\Development\projects\github.com\secretdeveloper\TestDataGenerator\src\BuildOutput\gk.DataGenerator.dll" target="" />
19+
<file src="C:\Development\projects\github.com\secretdeveloper\TestDataGenerator\src\BuildOutput\tdg.exe" target="" />
20+
<file src="C:\Development\projects\github.com\secretdeveloper\TestDataGenerator\src\BuildOutput\tdg-patterns\default.tdg-patterns" target="" />
21+
<file src="C:\Development\projects\github.com\secretdeveloper\TestDataGenerator\src\BuildOutput\tdg-patterns\language.tdg-patterns" target="" />
22+
<file src="C:\Development\projects\github.com\secretdeveloper\TestDataGenerator\src\BuildOutput\Eloquent.dll" target="" />
23+
<file src="C:\Development\projects\github.com\secretdeveloper\TestDataGenerator\src\BuildOutput\CommandLine.dll" target="" />
24+
<file src="C:\Development\projects\github.com\secretdeveloper\TestDataGenerator\src\BuildOutput\CommandLine.xml" target="" />
25+
<file src="C:\Development\projects\github.com\secretdeveloper\TestDataGenerator\src\BuildOutput\tdg.exe.config" target="" />
2626
<file src="C:\Development\projects\github.com\secretdeveloper\TestDataGenerator\src\BuildOutput\README.txt" target="" />
2727
</files>
2828
</package>

src/DataGenerator/gk.DataGenerator/FileReader.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ namespace gk.DataGenerator
99
{
1010
public static class FileReader
1111
{
12+
private const string _PatternFolder_Name = "tdg-patterns";
13+
private const string _PatternFile_Extension = "tdg-patterns";
14+
1215
public static NamedPatterns LoadNamedPatterns(string path)
1316
{
1417
NamedPatterns result;
@@ -22,7 +25,7 @@ public static NamedPatterns LoadNamedPatterns(string path)
2225

2326
public static string GetPatternFilePath(string filePath)
2427
{
25-
if (!Path.HasExtension(filePath)) filePath = Path.ChangeExtension(filePath, "tdg-patterns");
28+
if (!Path.HasExtension(filePath)) filePath = Path.ChangeExtension(filePath, _PatternFile_Extension);
2629

2730
var paths = new List<string>();
2831
paths.Add(filePath);
@@ -34,17 +37,16 @@ public static string GetPatternFilePath(string filePath)
3437
paths.Add(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filePath));
3538

3639
// check if it is within the _PatternFolder_Name folder
37-
paths.Add(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "tdg-patterns", filePath));
40+
paths.Add(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _PatternFolder_Name, filePath));
3841
}
3942

4043
foreach (var path in paths)
4144
{
4245
if (File.Exists(path)) return path;
4346
}
4447

45-
var msg = string.Format("Unable to find pattern file '{0}'. Searched in the following locations:\n{1}", filePath, string.Join("\n", paths));
48+
var msg = String.Format("Unable to find pattern file '{0}'. Searched in the following locations:\n{1}", filePath, String.Join("\n", paths));
4649
throw new GenerationException(msg);
4750
}
48-
4951
}
5052
}

src/DataGenerator/gk.DataGenerator/GenerationConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public int? Seed
2626
private Random mRandom;
2727
public Random Random
2828
{
29-
get { return mRandom ?? (mRandom = new Random(mSeed.Value)); }
29+
get { return mRandom; }
3030
set { mRandom = value; }
3131
}
3232

src/DataGenerator/gk.DataGenerator/Generators/AlphaNumericGenerator.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ namespace gk.DataGenerator.Generators
1111
{
1212
public static class AlphaNumericGenerator
1313
{
14-
private const string _AllPossibleCharacters = _AllLetters + _AllNumbers + _AllNonAlphaNumericCharacters;
14+
private const string _AllPossibleCharacters = _AllLetters + _AllNumbers + _AllNonWhitespaceNonAlphaNumericCharacters + " ";
1515
private const string _AllLetters = _ShortHand_l + _ShortHand_L;
1616
private const string _AllNumbers = "0123456789";
17-
private const string _AllNonAlphaNumericCharacters = " .,;:\"'!&?£$€$%^<>{}[]()*\\+-=@#_|~/";
17+
private const string _AllWhitespaceCharacters = " \t\n\r\f";
18+
private const string _AllNonWhitespaceNonAlphaNumericCharacters = ".,;:\"'!&?£$€$%^<>{}[]()*\\+-=@#_|~/";
1819

1920
private const string _ShortHand_l = "abcdefghijklmnopqrstuvwxyz"; // \l
2021
private const string _ShortHand_L = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // \L
2122
private const string _ShortHand_V = "AEIOU"; // \V
2223
private const string _ShortHand_v = "aeiou"; // \v
2324
private const string _ShortHand_C = "BCDFGHJKLMNPQRSTVWXYZ"; // \C
2425
private const string _ShortHand_c = "bcdfghjklmnpqrstvwxyz"; // \c
25-
private const string _ShortHand_D = _AllLetters + _AllNonAlphaNumericCharacters; // \D
26+
private const string _ShortHand_D = _AllLetters + _AllNonWhitespaceNonAlphaNumericCharacters + " "; // \D
2627
private const string _ShortHand_d = _AllNumbers; // \d
27-
private const string _ShortHand_W = " .,;:\"'!&?£€$%^<>{}[]()*\\+-=@#|~/"; // \W
28-
private const string _ShortHand_w = _AllLetters; // \w
29-
private const string _ShortHand_s = " \t\n\r\f"; // \s
30-
private const string _ShortHand_S = _ShortHand_l + _ShortHand_L + _AllNumbers + _AllNonAlphaNumericCharacters; // \S
31-
28+
private const string _ShortHand_W = _AllNonWhitespaceNonAlphaNumericCharacters + " "; // \W
29+
private const string _ShortHand_w = _AllLetters + _AllNumbers + "_"; // \w
30+
private const string _ShortHand_s = _AllWhitespaceCharacters; // \s
31+
private const string _ShortHand_S = _AllLetters + _AllNumbers + _AllNonWhitespaceNonAlphaNumericCharacters; // \S
3232

3333
private const string _Config_Start = "<#";
3434
private const string _Config_End = "#>";
@@ -54,9 +54,6 @@ public static class AlphaNumericGenerator
5454

5555
private const int _ErrorSnippet_ContextLength = 50;
5656

57-
private const string _PatternFolder_Name = "tdg-patterns";
58-
private const string _PatternFile_Extension = "tdg-patterns";
59-
6057

6158
/// <summary>
6259
/// The number of characters before and after the problem location to include in error messages.
@@ -205,9 +202,6 @@ private static void AppendPatternsFromConfigToCollection(GenerationConfig config
205202
{
206203
var correctedPath = FileReader.GetPatternFilePath(patternFile);
207204

208-
if (!File.Exists(correctedPath))
209-
throw new GenerationException("PatternFile not found:" + patternFile + "\n Attempted to locate it at\n'"+correctedPath+"\nbut it was not found.");
210-
211205
try
212206
{
213207
var patt = FileReader.LoadNamedPatterns(correctedPath);
@@ -241,11 +235,17 @@ private static GenerationConfig LoadAndRemoveConfigFromTemplate(ref string templ
241235
private static NamedPatterns LoadDefaultNamedPatterns()
242236
{
243237
var patterns = new NamedPatterns();
244-
var path = FileReader.GetPatternFilePath("default");
245-
//Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _PatternFolder_Name, "default.tdg-patterns");
246-
if (File.Exists(path))
238+
try
239+
{
240+
var path = FileReader.GetPatternFilePath("default");
241+
if (File.Exists(path))
242+
{
243+
patterns = FileReader.LoadNamedPatterns(path);
244+
}
245+
}
246+
catch(GenerationException)
247247
{
248-
patterns = FileReader.LoadNamedPatterns(path);
248+
// Error loading defaults - not throwing as they may not have been deployed
249249
}
250250
return patterns;
251251
}

0 commit comments

Comments
 (0)