Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/TestStack.BDDfy/DateTimeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Globalization;

namespace TestStack.BDDfy
{
public static class DateTimeExtensions
{
public static string AsShortDateTimeString(this DateTime dateTime)
{
return dateTime.ToString(CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern);
}
}
}
2 changes: 1 addition & 1 deletion src/TestStack.BDDfy/Processors/ExceptionProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static IEnumerable<Type> GetTypesSafely(Assembly assembly)
//http://stackoverflow.com/questions/520290/how-can-i-get-the-default-value-of-a-type-in-a-non-generic-way
static object DefaultValue(Type myType)
{
return !myType.IsValueType ? null : Activator.CreateInstance(myType);
return !myType.IsValueType() ? null : Activator.CreateInstance(myType);
}

public ExceptionProcessor() : this(BestGuessInconclusiveAssertion)
Expand Down
5 changes: 0 additions & 5 deletions src/TestStack.BDDfy/Processors/InconclusiveException.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Runtime.Serialization;

namespace TestStack.BDDfy.Processors
{
Expand All @@ -16,9 +15,5 @@ public InconclusiveException(string message) : base(message)
public InconclusiveException(string message, Exception innerException) : base(message, innerException)
{
}

protected InconclusiveException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}
9 changes: 0 additions & 9 deletions src/TestStack.BDDfy/Processors/UnusedExampleException.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
namespace TestStack.BDDfy.Processors
{
using System;
using System.Runtime.Serialization;

[Serializable]
public class UnusedExampleException : Exception
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could polyfill this if you wanted. Removing for everyone means you can no longer take exception across appdomains

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By polyfill, do you mean #if statements?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create an attribute in your code in the right namespace. Does nothing but don't need ifs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see what you mean. But then I would still need an #if for the serializable constructor?

public UnusedExampleException(ExampleValue unusedValue) :
base(string.Format("Example Column '{0}' is unused, all examples should be consumed by the test (have you misspelt a field or property?)\r\n\r\n"
+ "If this is not the case, raise an issue at https://github.com/TestStack/TestStack.BDDfy/issues.", unusedValue.Header))
{ }

protected UnusedExampleException(
SerializationInfo info,
StreamingContext context)
: base(info, context)
{
}
}
}
13 changes: 7 additions & 6 deletions src/TestStack.BDDfy/Reporters/Html/ClassicReportBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using TestStack.BDDfy.Configuration;

namespace TestStack.BDDfy.Reporters.Html
Expand Down Expand Up @@ -45,7 +46,7 @@ private void HtmlHead()
EmbedCssFile(HtmlReportResources.classic_css_min);
EmbedCssFile(_model.CustomStylesheet, HtmlReportResources.CustomStylesheetComment);

AddLine(string.Format("<title>BDDfy Test Result {0}</title>", _model.RunDate.ToShortDateString()));
AddLine(string.Format("<title>BDDfy Test Result {0}</title>", _model.RunDate.AsShortDateTimeString()));
}
}

Expand Down Expand Up @@ -187,15 +188,15 @@ private void AddScenarioWithExamples(ReportModel.Scenario[] scenarioGroup)
var firstScenario = scenarioGroup.First();
var scenarioResult = (Result)scenarioGroup.Max(s => (int)s.Result);

AddLine(string.Format("<div class='{0} canToggle scenarioTitle' data-toggle-target='{1}'>{2}{3}</div>", scenarioResult, firstScenario.Id, HttpUtility.HtmlEncode(firstScenario.Title), FormatTags(firstScenario.Tags)));
AddLine(string.Format("<div class='{0} canToggle scenarioTitle' data-toggle-target='{1}'>{2}{3}</div>", scenarioResult, firstScenario.Id, WebUtility.HtmlEncode(firstScenario.Title), FormatTags(firstScenario.Tags)));

using (OpenTag(string.Format("<ul class='steps' id='{0}'>", firstScenario.Id), HtmlTag.ul))
{
foreach (var step in firstScenario.Steps.Where(s => s.ShouldReport))
{
using (OpenTag(string.Format("<li class='step {0}'>", step.ExecutionOrder), HtmlTag.li))
{
var titleLines = HttpUtility.HtmlEncode(step.Title)
var titleLines = WebUtility.HtmlEncode(step.Title)
.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
var title = titleLines[0];

Expand Down Expand Up @@ -247,7 +248,7 @@ private void AddExampleRow(ReportModel.Scenario scenario, Result scenarioResult)
{
AddLine(string.Format("<td><Span class='{0}' style='margin-right:4px;' /></td>", scenario.Result));
foreach (var exampleValue in scenario.Example.Values)
AddLine(string.Format("<td>{0}</td>", HttpUtility.HtmlEncode(exampleValue.GetValueAsString())));
AddLine(string.Format("<td>{0}</td>", WebUtility.HtmlEncode(exampleValue.GetValueAsString())));

if (scenarioResult != Result.Failed)
return;
Expand All @@ -260,7 +261,7 @@ private void AddExampleRow(ReportModel.Scenario scenario, Result scenarioResult)
return;

var exceptionId = Configurator.IdGenerator.GetStepId();
var encodedExceptionMessage = HttpUtility.HtmlEncode(failingStep.Exception.Message);
var encodedExceptionMessage = WebUtility.HtmlEncode(failingStep.Exception.Message);
AddLine(string.Format("<span class='canToggle' data-toggle-target='{0}'>{1}</span>", exceptionId, encodedExceptionMessage));
using (OpenTag(string.Format("<div class='step' id='{0}'>", exceptionId), HtmlTag.div))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ private static string AssemblyDirectory
{
get
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
var codeBase = typeof(DefaultHtmlReportConfiguration).Assembly().CodeBase;
var uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
var path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/TestStack.BDDfy/Reporters/Html/MetroReportBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using TestStack.BDDfy.Configuration;

namespace TestStack.BDDfy.Reporters.Html
Expand Down Expand Up @@ -45,7 +45,7 @@ private void HtmlHead()
EmbedCssFile(HtmlReportResources.metro_css_min);
EmbedCssFile(_model.CustomStylesheet, HtmlReportResources.CustomStylesheetComment);
AddLine("<link href='http://fonts.googleapis.com/css?family=Roboto:400,300' rel='stylesheet' type='text/css'>");
AddLine(string.Format("<title>BDDfy Test Result {0}</title>", _model.RunDate.ToShortDateString()));
AddLine(string.Format("<title>BDDfy Test Result {0}</title>", _model.RunDate.AsShortDateTimeString()));
}
}

Expand Down Expand Up @@ -202,15 +202,15 @@ private void AddScenarioWithExamples(ReportModel.Scenario[] scenarioGroup)
var firstScenario = scenarioGroup.First();
var scenarioResult = (Result)scenarioGroup.Max(s => (int)s.Result);

AddLine(string.Format("<div class='{0} canToggle scenarioTitle' data-toggle-target='{1}'>{2}{3}</div>", scenarioResult, firstScenario.Id, HttpUtility.HtmlEncode(firstScenario.Title), FormatTags(firstScenario.Tags)));
AddLine(string.Format("<div class='{0} canToggle scenarioTitle' data-toggle-target='{1}'>{2}{3}</div>", scenarioResult, firstScenario.Id, WebUtility.HtmlEncode(firstScenario.Title), FormatTags(firstScenario.Tags)));

using (OpenTag(string.Format("<ul class='steps' id='{0}'>", firstScenario.Id), HtmlTag.ul))
{
foreach (var step in firstScenario.Steps.Where(s => s.ShouldReport))
{
using (OpenTag(string.Format("<li class='step {0}'>", step.ExecutionOrder), HtmlTag.li))
{
var titleLines = HttpUtility.HtmlEncode(step.Title)
var titleLines = WebUtility.HtmlEncode(step.Title)
.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
var title = titleLines[0];

Expand Down Expand Up @@ -262,7 +262,7 @@ private void AddExampleRow(ReportModel.Scenario scenario, Result scenarioResult)
{
AddLine(string.Format("<td><Span class='{0}' style='margin-right:4px;' /></td>", scenario.Result));
foreach (var exampleValue in scenario.Example.Values)
AddLine(string.Format("<td>{0}</td>", HttpUtility.HtmlEncode(exampleValue.GetValueAsString())));
AddLine(string.Format("<td>{0}</td>", WebUtility.HtmlEncode(exampleValue.GetValueAsString())));

if (scenarioResult != Result.Failed)
return;
Expand All @@ -275,7 +275,7 @@ private void AddExampleRow(ReportModel.Scenario scenario, Result scenarioResult)
return;

var exceptionId = Configurator.IdGenerator.GetStepId();
var encodedExceptionMessage = HttpUtility.HtmlEncode(failingStep.Exception.Message);
var encodedExceptionMessage = WebUtility.HtmlEncode(failingStep.Exception.Message);
AddLine(string.Format("<span class='canToggle' data-toggle-target='{0}'>{1}</span>", exceptionId, encodedExceptionMessage));
using (OpenTag(string.Format("<div class='step FailedException' id='{0}'>", exceptionId), HtmlTag.div))
{
Expand All @@ -287,7 +287,7 @@ private void AddExampleRow(ReportModel.Scenario scenario, Result scenarioResult)

private void AddScenario(ReportModel.Scenario scenario)
{
AddLine(string.Format("<div class='{0} canToggle scenarioTitle' data-toggle-target='{1}'>{2}{3}</div>", scenario.Result, scenario.Id, HttpUtility.HtmlEncode(scenario.Title), FormatTags(scenario.Tags)));
AddLine(string.Format("<div class='{0} canToggle scenarioTitle' data-toggle-target='{1}'>{2}{3}</div>", scenario.Result, scenario.Id, WebUtility.HtmlEncode(scenario.Title), FormatTags(scenario.Tags)));

using (OpenTag(string.Format("<ul class='steps' id='{0}'>", scenario.Id), HtmlTag.ul))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;

namespace TestStack.BDDfy.Reporters.MarkDown
{
Expand Down Expand Up @@ -41,7 +41,7 @@ public string CreateReport(FileReportModel model)
if (exampleScenario.Steps.Any())
{
foreach (var step in exampleScenario.Steps.Where(s => s.ShouldReport))
report.AppendLine(" " + HttpUtility.HtmlEncode(step.Title) + " ");
report.AppendLine(" " + WebUtility.HtmlEncode(step.Title) + " ");
}

report.AppendLine(); // separator
Expand All @@ -55,7 +55,7 @@ public string CreateReport(FileReportModel model)
report.AppendLine(string.Format("### {0}", scenario.Title));

foreach (var step in scenario.Steps.Where(s => s.ShouldReport))
report.AppendLine(" " + HttpUtility.HtmlEncode(step.Title) + " ");
report.AppendLine(" " + WebUtility.HtmlEncode(step.Title) + " ");

report.AppendLine(); // separator
}
Expand Down Expand Up @@ -121,7 +121,7 @@ private void WriteExamples(StringBuilder report, ReportModel.Scenario exampleSce
var failingStep = scenario.Steps.FirstOrDefault(s => s.Result == Result.Failed);
var error = failingStep == null
? null
: string.Format("Step: {0} failed with exception: {1}", HttpUtility.HtmlEncode(failingStep.Title), CreateExceptionMessage(failingStep));
: string.Format("Step: {0} failed with exception: {1}", WebUtility.HtmlEncode(failingStep.Title), CreateExceptionMessage(failingStep));

addRow(scenario.Example.Values.Select(e => e.GetValueAsString()), scenario.Result.ToString(), error);
}
Expand Down
24 changes: 22 additions & 2 deletions src/TestStack.BDDfy/Reporters/Serializers/JsonSerializer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Web.Script.Serialization;

namespace TestStack.BDDfy.Reporters.Serializers
{
#if NET40
using System.Web.Script.Serialization;

public class JsonSerializer : ISerializer
{
public string Serialize(object obj)
Expand All @@ -12,4 +13,23 @@ public string Serialize(object obj)
return new JsonFormatter(json).Format();
}
}

#else
using Newtonsoft.Json;

public class JsonSerializer : ISerializer
{
public string Serialize(object obj)
{
return JsonConvert.SerializeObject(obj, Formatting.Indented,
new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
}
}

#endif

}
2 changes: 1 addition & 1 deletion src/TestStack.BDDfy/Reporters/Writers/FileWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private static string GetDefaultOutputDirectory
{
get
{
string codeBase = typeof(DiagnosticsReporter).Assembly.CodeBase;
string codeBase = typeof(DiagnosticsReporter).Assembly().CodeBase;
var uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static bool HeaderMatches(string header, string name)
if (name == null)
return false;

return Sanitise(name).Equals(Sanitise(header), StringComparison.InvariantCultureIgnoreCase);
return Sanitise(name).ToLower().Equals(Sanitise(header).ToLower());
}

private static string Sanitise(string value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public object GetValue(Type targetType)
var stringValue = _underlyingValue as string;
if (_underlyingValue == null)
{
if (targetType.IsValueType && !(targetType.IsGenericType && targetType.GetGenericTypeDefinition() == typeof(Nullable<>)))
if (targetType.IsValueType() && !(targetType.IsGenericType() && targetType.GetGenericTypeDefinition() == typeof(Nullable<>)))
{
var valueAsString = string.IsNullOrEmpty(stringValue) ? "<null>" : string.Format("\"{0}\"", _underlyingValue);
throw new ArgumentException(string.Format("Cannot convert {0} to {1} (Column: '{2}', Row: {3})", valueAsString, targetType.Name, Header, Row));
Expand All @@ -48,7 +48,7 @@ public object GetValue(Type targetType)
if (targetType.IsInstanceOfType(_underlyingValue))
return _underlyingValue;

if (targetType.IsEnum && _underlyingValue is string)
if (targetType.IsEnum() && _underlyingValue is string)
return Enum.Parse(targetType, (string)_underlyingValue);

if (targetType == typeof(DateTime))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
using System;
using System.Runtime.Serialization;

namespace TestStack.BDDfy
{
[Serializable]
public class UnassignableExampleException : Exception
{
public UnassignableExampleException(string message, Exception inner, ExampleValue exampleValue) : base(message, inner)
{
ExampleValue = exampleValue;
}

protected UnassignableExampleException(
SerializationInfo info,
StreamingContext context) : base(info, context)
{
}

public ExampleValue ExampleValue { get; private set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void AddStep(Action stepAction, string title, bool reports, ExecutionOrde

private string AppendPrefix(string title, string stepPrefix)
{
if (!title.StartsWith(stepPrefix, StringComparison.InvariantCultureIgnoreCase))
if (!title.ToLower().StartsWith(stepPrefix.ToLower()))
{
if (title.Length == 0)
return string.Format("{0} ", stepPrefix);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Runtime.Serialization;

namespace TestStack.BDDfy
{
Expand All @@ -16,10 +15,5 @@ public StepTitleException(string message) : base(message)
public StepTitleException(string message, Exception innerException) : base(message, innerException)
{
}

protected StepTitleException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected virtual Type GetCandidateStory(object testObject, Type explicitStoryTy

var scenarioType = testObject.GetType();
// This is assuming scenario and story live in the same assembly
var firstFrame = frames.LastOrDefault(f => f.GetMethod().DeclaringType.Assembly == scenarioType.Assembly);
var firstFrame = frames.LastOrDefault(f => f.GetMethod().DeclaringType.Assembly() == scenarioType.Assembly());
if (firstFrame == null)
return null;

Expand Down
Loading