Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ _NCrunch_TestStack.BDDfy/
TestStack.BDDfy.sln.ide/
src/packages/
src/.vs/
project.lock.json
3 changes: 1 addition & 2 deletions src/NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

<configuration>
<packageSources>
<!-- add key="CoreCLR Xunit" value="https://www.myget.org/F/coreclr-xunit/api/v3/index.json" / -->
<!-- add key="AspNet CI Feed" value="https://www.myget.org/F/aspnetcirelease/api/v3/index.json" /> -->
<add key="myget.org xunit" value="https://www.myget.org/F/xunit/api/v3/index.json" />
<add key="myget.org dotnet" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
16 changes: 4 additions & 12 deletions src/TestStack.BDDfy.Tests/Concurrency/ParallelRunnerScenario.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Linq;
using System.Threading.Tasks;
using TestStack.BDDfy.Tests.Stories;
using Xunit;
Expand All @@ -11,16 +10,9 @@ public class ParallelRunnerScenario
[Fact]
public async Task CanHandleMultipleThreadsExecutingBddfyConcurrently()
{
try
{
await Task.WhenAll(
Enumerable.Range(0, 100)
.Select(_ => Task.Run(() => new DummyScenario().BDDfy<ParallelRunnerScenario>())));
}
catch (Exception e)
{
Assert.False(true, "Threw exception " + e);
}
await Task.WhenAll(
Enumerable.Range(0, 100)
.Select(_ => Task.Run(() => new DummyScenario().BDDfy<ParallelRunnerScenario>())));
}
}
}
4 changes: 0 additions & 4 deletions src/TestStack.BDDfy.Tests/FodyWeavers.xml

This file was deleted.

6 changes: 4 additions & 2 deletions src/TestStack.BDDfy.Tests/Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using System;
using System.Linq.Expressions;
using System.Reflection;

namespace TestStack.BDDfy.Tests
{
public class Helpers
{
public static MethodInfo GetMethodInfo(Action methodOn)
public static MethodInfo GetMethodInfo(Expression<Action> methodOn)
{
return methodOn.Method;
var methodCallExp = (MethodCallExpression)methodOn.Body;
return methodCallExp.Method;
}
}
}
15 changes: 0 additions & 15 deletions src/TestStack.BDDfy.Tests/ModuleInitializer.cs

This file was deleted.

5 changes: 2 additions & 3 deletions src/TestStack.BDDfy.Tests/NetToStringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Shouldly;
using TestStack.BDDfy.Configuration;
using Xunit;
using Xunit.Extensions;

namespace TestStack.BDDfy.Tests
{
Expand Down Expand Up @@ -78,8 +77,8 @@ public void ReportsIllegalExampleStepNames(string stepName, string expectedStepT
NetToString.Convert(stepName).ShouldBe(expectedStepTitle, Case.Sensitive);
});

Assert.NotNull(exception);
Assert.IsType<ArgumentException>(exception);
exception.ShouldNotBeNull();
exception.ShouldBeOfType<ArgumentException>();
}
}
}
35 changes: 9 additions & 26 deletions src/TestStack.BDDfy.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,22 @@
using System.Reflection;
using System.Runtime.InteropServices;
using Xunit;

// General Information about an assembly is controlled through the following
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
using ApprovalTests.Reporters;

[assembly: AssemblyTitle("BDDfy.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("BDDfy.Tests")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TestStack.BDDfy.Tests")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f9519669-4620-4abd-977a-c3cb2b54126a")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: Guid("1ceb33e8-3aac-4d02-a15b-5b75b5f662ad")]

[assembly: UseReporter(typeof(DiffReporter))]
// BDDfy tests overwrite static configuration for test, cannot use parallel testing
[assembly: CollectionBehavior(DisableTestParallelization = true)]
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NSubstitute;
#if NSubstitute
using NSubstitute;
using TestStack.BDDfy.Reporters;
using TestStack.BDDfy.Reporters.Diagnostics;
using TestStack.BDDfy.Reporters.Serializers;
Expand All @@ -21,4 +22,5 @@ public void ShouldSerializeDiagnosticDataToSpecifiedFormat()
serializer.Received().Serialize(Arg.Any<object>());
}
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#if NSubstitute
using System;
using System.Collections.Generic;
using NSubstitute;
using TestStack.BDDfy.Reporters;
Expand Down Expand Up @@ -46,3 +47,4 @@ private DiagnosticsReporter CreateSut()
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if Approvals
using System;
using System.Runtime.CompilerServices;
using TestStack.BDDfy.Reporters;
Expand Down Expand Up @@ -37,4 +38,5 @@ public void ShouldProduceExpectedHtmlWithExamples()
ReportApprover.Approve(model, sut);
}
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#if NSubstitute
using System;
using System.Collections.Generic;
using NSubstitute;
using Shouldly;
Expand Down Expand Up @@ -99,3 +100,4 @@ public void ShouldNotLoadCustomJavascriptIfNoneExist()
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if Approvals
using System;
using System.Runtime.CompilerServices;
using TestStack.BDDfy.Reporters;
Expand Down Expand Up @@ -37,4 +38,5 @@ public void ShouldProduceExpectedHtmlWithExamples()
ReportApprover.Approve(model, sut);
}
}
}
}
#endif
4 changes: 3 additions & 1 deletion src/TestStack.BDDfy.Tests/Reporters/Html/TemporaryCulture.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if Culture
using System;
using System.Globalization;
using System.Threading;
Expand All @@ -18,4 +19,5 @@ public void Dispose()
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(_originalCulture);
}
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if NSubstitute
using NSubstitute;
using TestStack.BDDfy.Reporters;
using TestStack.BDDfy.Reporters.Html;
Expand Down Expand Up @@ -29,4 +30,5 @@ public static TestableHtmlReporter Create()
Substitute.For<IReportWriter>(), Substitute.For<IFileReader>());
}
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#if Approvals
using System;
using System.Runtime.CompilerServices;
using TestStack.BDDfy.Reporters;
using TestStack.BDDfy.Reporters.MarkDown;
Expand Down Expand Up @@ -33,3 +34,4 @@ public void ShouldProduceExpectedMarkdownWithExamples()
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#if NSubstitute
using System;
using System.Collections.Generic;
using NSubstitute;
using TestStack.BDDfy.Reporters;
Expand Down Expand Up @@ -46,3 +47,4 @@ private MarkDownReporter CreateSut()
}
}
}
#endif
62 changes: 58 additions & 4 deletions src/TestStack.BDDfy.Tests/Reporters/ReportApprover.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
#if Approvals
using System;
using System.Linq;
using System.Text.RegularExpressions;
using ApprovalTests;
using ApprovalTests.Utilities;
using Shouldly;
using TestStack.BDDfy.Reporters;
using TestStack.BDDfy.Tests.Reporters.Html;

Expand All @@ -15,7 +16,9 @@ public static void Approve(FileReportModel model, IReportBuilder reportBuilder)
using (new TemporaryCulture("en-GB"))
{
var result = reportBuilder.CreateReport(model);
Approvals.Verify(result, s => Scrub(StackTraceScrubber.ScrubLineNumbers(StackTraceScrubber.ScrubPaths(s))));
result.ShouldMatchApproved(c => c
.WithScrubber(s => StackTraceScrubber.ScrubLineNumbers(StackTraceScrubber.ScrubPaths(s)))
.UseCallerLocation());
}
}

Expand All @@ -24,4 +27,55 @@ static string Scrub(string scrubPaths)
return Regex.Replace(Regex.Replace(Regex.Replace(scrubPaths, @"(?<!\r)\n", "\r\n"), "step-\\d+-\\d+", "step-1-1"), "scenario-\\d+", "scenario-1");
}
}

public static class StackTraceScrubber
{
public static string ScrubAnonymousIds(string source)
{
var regex = new Regex(@"\w+__\w+");
return regex.Replace(source, string.Empty);
}

public static string ScrubLineNumbers(string source)
{
var regex = new Regex(@":line \d+");
return regex.Replace(source, string.Empty);
}

static Regex windowsPathRegex = new Regex(@"\b\w:[\\\w.\s-]+\\");
static Regex unixPathRegex = new Regex(@"\/[\/\w.\s-]+\/");
public static string ScrubPaths(string source)
{
var result = windowsPathRegex.Replace(source, "...\\");
result = unixPathRegex.Replace(result, ".../");
return result;
}

public static string ScrubStackTrace(this string text)
{
return ScrubberUtils.Combine(ScrubAnonymousIds, ScrubPaths, ScrubLineNumbers)(text);
}

public static string Scrub(this Exception exception)
{
return ("" + exception).ScrubStackTrace();
}
}
public class ScrubberUtils
{
public static Func<string, string> Combine(params Func<string, string>[] scrubbers)
{
return (inputText) => scrubbers.Aggregate(inputText, (c, s) => s(c));
}

public static Func<string, string> NO_SCRUBBER = (s) => s;

public static Func<string, string> RemoveLinesContaining(string value)
{
return s => string.Join("\n", s.Split('\n').Where(l => !l.Contains(value)));
}
}


}
#endif
Loading