forked from marcusoftnet/SpecFlow.Assist.Dynamic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the ability to use a custom property name mapper and property v…
…alue parser Fixes marcusoftnet#19 and marcusoftnet#5
- Loading branch information
Showing
15 changed files
with
294 additions
and
140 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,26 @@ | ||
using SpecFlow.Assist.Dynamic.PropertyNameMapping; | ||
using SpecFlow.Assist.Dynamic.PropertyValueParser; | ||
|
||
namespace SpecFlow.Assist.Dynamic | ||
{ | ||
public class Options | ||
{ | ||
public Options() | ||
{ | ||
this.DoTypeConversion = true; | ||
this.PropertyNameMapper = new DefaultPropertyNameMapper(); | ||
this.PropertyValueParser = new DefaultPropertyValueParser(); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether types should be converted | ||
/// according to conventions described in https://github.com/marcusoftnet/SpecFlow.Assist.Dynamic/wiki/Conversion-conventions#property-type-conversions | ||
/// </summary> | ||
/// <value><c>true</c> if types should be converted; otherwise, <c>false</c>.</value> | ||
public bool DoTypeConversion { get; set; } | ||
|
||
public IPropertyNameMapper PropertyNameMapper { get; set; } | ||
|
||
public IPropertyValueParser PropertyValueParser { get; set; } | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
SpecFlow.Assist.Dynamic/PropertyNameMapping/DefaultPropertyNameMapper.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,23 @@ | ||
namespace SpecFlow.Assist.Dynamic.PropertyNameMapping | ||
{ | ||
public class DefaultPropertyNameMapper : IPropertyNameMapper | ||
{ | ||
public string Map(string header) | ||
{ | ||
var words = header.Split(' '); | ||
var propName = words[0]; // leave the first word as is, since it might be correct cased... | ||
|
||
for (var i = 1; i < words.Length; i++) | ||
{ | ||
var s = words[i]; | ||
if (s.Length > 0) | ||
{ | ||
propName += s[0].ToString().ToUpperInvariant() + | ||
s.Substring(1).ToLowerInvariant(); | ||
} | ||
} | ||
|
||
return propName; | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
SpecFlow.Assist.Dynamic/PropertyNameMapping/IPropertyNameMapper.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,7 @@ | ||
namespace SpecFlow.Assist.Dynamic.PropertyNameMapping | ||
{ | ||
public interface IPropertyNameMapper | ||
{ | ||
string Map(string header); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
SpecFlow.Assist.Dynamic/PropertyValueParser/DefaultPropertyValueParser.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,35 @@ | ||
using System; | ||
|
||
namespace SpecFlow.Assist.Dynamic.PropertyValueParser | ||
{ | ||
public class DefaultPropertyValueParser : IPropertyValueParser | ||
{ | ||
public object Parse(string value) | ||
{ | ||
int i; | ||
if (int.TryParse(value, out i)) | ||
return i; | ||
|
||
double db; | ||
if (double.TryParse(value, out db)) | ||
{ | ||
decimal d; | ||
if (decimal.TryParse(value, out d) && d.Equals((decimal)db)) | ||
{ | ||
return db; | ||
} | ||
return d; | ||
} | ||
|
||
bool b; | ||
if (bool.TryParse(value, out b)) | ||
return b; | ||
|
||
DateTime dt; | ||
if (DateTime.TryParse(value, out dt)) | ||
return dt; | ||
|
||
return value; | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
SpecFlow.Assist.Dynamic/PropertyValueParser/IPropertyValueParser.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,7 @@ | ||
namespace SpecFlow.Assist.Dynamic.PropertyValueParser | ||
{ | ||
public interface IPropertyValueParser | ||
{ | ||
object Parse(string value); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using SpecFlow.Assist.Dynamic.PropertyNameMapping; | ||
|
||
namespace Specs.PropertyNameMapping | ||
{ | ||
public class CustomPropertyNameMapper : IPropertyNameMapper | ||
{ | ||
public string Map(string header) | ||
{ | ||
return header.Replace(" ", string.Empty); | ||
} | ||
} | ||
} |
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,12 @@ | ||
using SpecFlow.Assist.Dynamic.PropertyValueParser; | ||
|
||
namespace Specs.PropertyValueParser | ||
{ | ||
public class CustomPropertyValueParser : IPropertyValueParser | ||
{ | ||
public object Parse(string value) | ||
{ | ||
return 42; | ||
} | ||
} | ||
} |
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.