diff --git a/.gitignore b/.gitignore index 14585368..4d90753f 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ _NCrunch_TestStack.BDDfy/ TestStack.BDDfy.sln.ide/ src/packages/ src/.vs/ +project.lock.json diff --git a/src/NuGet.config b/src/NuGet.config index c052e6df..5e4d98d7 100644 --- a/src/NuGet.config +++ b/src/NuGet.config @@ -2,9 +2,8 @@ - - - + + \ No newline at end of file diff --git a/src/Samples/TestStack.BDDfy.Samples/AssemblySetupFixture.cs b/src/Samples/TestStack.BDDfy.Samples/AssemblySetupFixture.cs new file mode 100644 index 00000000..5e375cf7 --- /dev/null +++ b/src/Samples/TestStack.BDDfy.Samples/AssemblySetupFixture.cs @@ -0,0 +1,153 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Threading; +using System.Threading.Tasks; +using TestStack.BDDfy.Configuration; +using TestStack.BDDfy.Reporters.Html; +using TestStack.BDDfy.Samples; +using TestStack.BDDfy.Samples.Atm; +using Xunit.Abstractions; +using Xunit.Sdk; + +// The custom test framework enables the support +[assembly: Xunit.TestFramework("TestStack.BDDfy.Samples.XunitTestFrameworkWithAssemblyFixture", "TestStack.BDDfy.Samples")] + +// Add one of these for every fixture classes for the assembly. +// Just like other fixtures, you can implement IDisposable and it'll +// get cleaned up at the end of the test run. +[assembly: AssemblyFixture(typeof(AssemblySetupFixture))] + +namespace TestStack.BDDfy.Samples +{ + public class AssemblySetupFixture + { + public AssemblySetupFixture() + { + Configurator.Processors.Add(() => new CustomTextReporter()); + Configurator.BatchProcessors.MarkDownReport.Enable(); + Configurator.BatchProcessors.DiagnosticsReport.Enable(); + Configurator.BatchProcessors.Add(new HtmlReporter(new AtmHtmlReportConfig(), new MetroReportBuilder())); + } + } + + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] + public class AssemblyFixtureAttribute : Attribute + { + public AssemblyFixtureAttribute(Type fixtureType) + { + FixtureType = fixtureType; + } + + public Type FixtureType { get; private set; } + } + + public class XunitTestFrameworkWithAssemblyFixture : XunitTestFramework + { + public XunitTestFrameworkWithAssemblyFixture(IMessageSink messageSink) + : base(messageSink) + { } + + protected override ITestFrameworkExecutor CreateExecutor(AssemblyName assemblyName) + => new XunitTestFrameworkExecutorWithAssemblyFixture(assemblyName, SourceInformationProvider, DiagnosticMessageSink); + } + + public class XunitTestFrameworkExecutorWithAssemblyFixture : XunitTestFrameworkExecutor + { + public XunitTestFrameworkExecutorWithAssemblyFixture(AssemblyName assemblyName, + ISourceInformationProvider sourceInformationProvider, IMessageSink diagnosticMessageSink) + : base(assemblyName, sourceInformationProvider, diagnosticMessageSink) + { + } + + protected override async void RunTestCases(IEnumerable testCases, + IMessageSink executionMessageSink, ITestFrameworkExecutionOptions executionOptions) + { + using ( + var assemblyRunner = new XunitTestAssemblyRunnerWithAssemblyFixture(TestAssembly, testCases, + DiagnosticMessageSink, executionMessageSink, executionOptions)) + await assemblyRunner.RunAsync(); + } + } + + public class XunitTestAssemblyRunnerWithAssemblyFixture : XunitTestAssemblyRunner + { + readonly Dictionary assemblyFixtureMappings = new Dictionary(); + + public XunitTestAssemblyRunnerWithAssemblyFixture(ITestAssembly testAssembly, + IEnumerable testCases, + IMessageSink diagnosticMessageSink, + IMessageSink executionMessageSink, + ITestFrameworkExecutionOptions executionOptions) + : base(testAssembly, testCases, diagnosticMessageSink, executionMessageSink, executionOptions) + { } + + protected override async Task AfterTestAssemblyStartingAsync() + { + // Let everything initialize + await base.AfterTestAssemblyStartingAsync(); + + // Go find all the AssemblyFixtureAttributes adorned on the test assembly + Aggregator.Run(() => + { + var fixturesAttrs = ((IReflectionAssemblyInfo)TestAssembly.Assembly).Assembly + .GetCustomAttributes(typeof(AssemblyFixtureAttribute)) + .Cast() + .ToList(); + + // Instantiate all the fixtures + foreach (var fixtureAttr in fixturesAttrs) + assemblyFixtureMappings[fixtureAttr.FixtureType] = Activator.CreateInstance(fixtureAttr.FixtureType); + }); + } + + protected override Task BeforeTestAssemblyFinishedAsync() + { + // Make sure we clean up everybody who is disposable, and use Aggregator.Run to isolate Dispose failures + foreach (var disposable in assemblyFixtureMappings.Values.OfType()) + Aggregator.Run(disposable.Dispose); + + return base.BeforeTestAssemblyFinishedAsync(); + } + + protected override Task RunTestCollectionAsync(IMessageBus messageBus, + ITestCollection testCollection, + IEnumerable testCases, + CancellationTokenSource cancellationTokenSource) + => new XunitTestCollectionRunnerWithAssemblyFixture(assemblyFixtureMappings, testCollection, testCases, DiagnosticMessageSink, messageBus, TestCaseOrderer, new ExceptionAggregator(Aggregator), cancellationTokenSource).RunAsync(); + } + + public class XunitTestCollectionRunnerWithAssemblyFixture : XunitTestCollectionRunner + { + readonly Dictionary assemblyFixtureMappings; + readonly IMessageSink diagnosticMessageSink; + + public XunitTestCollectionRunnerWithAssemblyFixture(Dictionary assemblyFixtureMappings, + ITestCollection testCollection, + IEnumerable testCases, + IMessageSink diagnosticMessageSink, + IMessageBus messageBus, + ITestCaseOrderer testCaseOrderer, + ExceptionAggregator aggregator, + CancellationTokenSource cancellationTokenSource) + : base(testCollection, testCases, diagnosticMessageSink, messageBus, testCaseOrderer, aggregator, cancellationTokenSource) + { + this.assemblyFixtureMappings = assemblyFixtureMappings; + this.diagnosticMessageSink = diagnosticMessageSink; + } + + protected override Task RunTestClassAsync(ITestClass testClass, IReflectionTypeInfo @class, IEnumerable testCases) + { + // Don't want to use .Concat + .ToDictionary because of the possibility of overriding types, + // so instead we'll just let collection fixtures override assembly fixtures. + var combinedFixtures = new Dictionary(assemblyFixtureMappings); + foreach (var kvp in CollectionFixtureMappings) + combinedFixtures[kvp.Key] = kvp.Value; + + // We've done everything we need, so let the built-in types do the rest of the heavy lifting + return new XunitTestClassRunner(testClass, @class, testCases, diagnosticMessageSink, MessageBus, TestCaseOrderer, new ExceptionAggregator(Aggregator), CancellationTokenSource, combinedFixtures).RunAsync(); + } + } + +} \ No newline at end of file diff --git a/src/Samples/TestStack.BDDfy.Samples/BuyingTrainFares/Money.cs b/src/Samples/TestStack.BDDfy.Samples/BuyingTrainFares/Money.cs index 008b89f0..2ec30b57 100644 --- a/src/Samples/TestStack.BDDfy.Samples/BuyingTrainFares/Money.cs +++ b/src/Samples/TestStack.BDDfy.Samples/BuyingTrainFares/Money.cs @@ -41,7 +41,7 @@ public override int GetHashCode() public override string ToString() { - return Amount.ToString("C", CultureInfo.CreateSpecificCulture("EN-US")); + return Amount.ToString("C", new CultureInfo("EN-US")); } } } \ No newline at end of file diff --git a/src/Samples/TestStack.BDDfy.Samples/CustomTextReporter.cs b/src/Samples/TestStack.BDDfy.Samples/CustomTextReporter.cs index 980b9f54..152d28d1 100644 --- a/src/Samples/TestStack.BDDfy.Samples/CustomTextReporter.cs +++ b/src/Samples/TestStack.BDDfy.Samples/CustomTextReporter.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Linq; +using System.Reflection; using System.Text; namespace TestStack.BDDfy.Samples @@ -17,7 +18,7 @@ private static string OutputDirectory { get { - string codeBase = typeof(CustomTextReporter).Assembly.CodeBase; + string codeBase = typeof(CustomTextReporter).GetTypeInfo().Assembly.CodeBase; var uri = new UriBuilder(codeBase); string path = Uri.UnescapeDataString(uri.Path); return System.IO.Path.GetDirectoryName(path); diff --git a/src/Samples/TestStack.BDDfy.Samples/FodyWeavers.xml b/src/Samples/TestStack.BDDfy.Samples/FodyWeavers.xml deleted file mode 100644 index 4e845a26..00000000 --- a/src/Samples/TestStack.BDDfy.Samples/FodyWeavers.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/Samples/TestStack.BDDfy.Samples/ModuleInitializer.cs b/src/Samples/TestStack.BDDfy.Samples/ModuleInitializer.cs deleted file mode 100644 index a2b5fc56..00000000 --- a/src/Samples/TestStack.BDDfy.Samples/ModuleInitializer.cs +++ /dev/null @@ -1,21 +0,0 @@ -using TestStack.BDDfy.Configuration; -using TestStack.BDDfy.Reporters.Html; -using TestStack.BDDfy.Samples; -using TestStack.BDDfy.Samples.Atm; - -/// -/// Used by the ModuleInit. All code inside the Initialize method is ran as soon as the assembly is loaded. -/// -public static class ModuleInitializer -{ - /// - /// Initializes the module. - /// - public static void Initialize() - { - Configurator.Processors.Add(() => new CustomTextReporter()); - Configurator.BatchProcessors.MarkDownReport.Enable(); - Configurator.BatchProcessors.DiagnosticsReport.Enable(); - Configurator.BatchProcessors.Add(new HtmlReporter(new AtmHtmlReportConfig(), new MetroReportBuilder())); - } -} \ No newline at end of file diff --git a/src/Samples/TestStack.BDDfy.Samples/Properties/AssemblyInfo.cs b/src/Samples/TestStack.BDDfy.Samples/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..d1c773c9 --- /dev/null +++ b/src/Samples/TestStack.BDDfy.Samples/Properties/AssemblyInfo.cs @@ -0,0 +1,19 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 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. +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TestStack.BDDfy.Samples")] +[assembly: AssemblyTrademark("")] + +// 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("c45c458d-5e2d-4ea4-a4ea-bc1931ddf15b")] diff --git a/src/Samples/TestStack.BDDfy.Samples/TestStack.BDDfy.Samples.csproj b/src/Samples/TestStack.BDDfy.Samples/TestStack.BDDfy.Samples.csproj deleted file mode 100644 index b1c8a5b5..00000000 --- a/src/Samples/TestStack.BDDfy.Samples/TestStack.BDDfy.Samples.csproj +++ /dev/null @@ -1,111 +0,0 @@ - - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {9D14B03B-9514-4DD8-9D4B-914A10D7EB59} - Library - Properties - TestStack.BDDfy.Samples - TestStack.BDDfy.Samples - v4.5 - 512 - 9dadff8a - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ..\..\packages\Shouldly.2.3.1\lib\net40\Shouldly.dll - - - - ..\..\packages\xunit.1.9.2\lib\net20\xunit.dll - - - ..\..\packages\xunit.extensions.1.9.2\lib\net20\xunit.extensions.dll - - - - - {DA6BCB39-307C-4A8E-9A3A-27BB2DBC44A3} - TestStack.BDDfy - - - - - - - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - - \ No newline at end of file diff --git a/src/Samples/TestStack.BDDfy.Samples/TestStack.BDDfy.Samples.ncrunchproject b/src/Samples/TestStack.BDDfy.Samples/TestStack.BDDfy.Samples.ncrunchproject deleted file mode 100644 index 896f2193..00000000 --- a/src/Samples/TestStack.BDDfy.Samples/TestStack.BDDfy.Samples.ncrunchproject +++ /dev/null @@ -1,22 +0,0 @@ - - false - false - false - true - false - false - false - false - true - true - false - true - true - 60000 - - - - AutoDetect - STA - x86 - \ No newline at end of file diff --git a/src/Samples/TestStack.BDDfy.Samples/TestStack.BDDfy.Samples.v2.ncrunchproject b/src/Samples/TestStack.BDDfy.Samples/TestStack.BDDfy.Samples.v2.ncrunchproject deleted file mode 100644 index 896f2193..00000000 --- a/src/Samples/TestStack.BDDfy.Samples/TestStack.BDDfy.Samples.v2.ncrunchproject +++ /dev/null @@ -1,22 +0,0 @@ - - false - false - false - true - false - false - false - false - true - true - false - true - true - 60000 - - - - AutoDetect - STA - x86 - \ No newline at end of file diff --git a/src/Samples/TestStack.BDDfy.Samples/TestStack.BDDfy.Samples.xproj b/src/Samples/TestStack.BDDfy.Samples/TestStack.BDDfy.Samples.xproj new file mode 100644 index 00000000..c515245b --- /dev/null +++ b/src/Samples/TestStack.BDDfy.Samples/TestStack.BDDfy.Samples.xproj @@ -0,0 +1,22 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + c45c458d-5e2d-4ea4-a4ea-bc1931ddf15b + TestStack.BDDfy.Samples + .\obj + .\bin\ + v4.5.2 + + + 2.0 + + + + + + \ No newline at end of file diff --git a/src/Samples/TestStack.BDDfy.Samples/packages.config b/src/Samples/TestStack.BDDfy.Samples/packages.config deleted file mode 100644 index dce7248d..00000000 --- a/src/Samples/TestStack.BDDfy.Samples/packages.config +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/src/Samples/TestStack.BDDfy.Samples/project.json b/src/Samples/TestStack.BDDfy.Samples/project.json new file mode 100644 index 00000000..73451871 --- /dev/null +++ b/src/Samples/TestStack.BDDfy.Samples/project.json @@ -0,0 +1,42 @@ +{ + "version": "1.0.0-*", + "testRunner": "xunit", + + "dependencies": { + "dotnet-test-xunit": "2.2.0-preview2-build1029", + "Microsoft.NETCore.Platforms": "1.0.1", + "Shouldly": "2.8.0", + "TestStack.BDDfy": { + "target": "project" + }, + "xunit.core": "2.2.0-beta2-build3300" + }, + + "runtimes": { + "win10-x64": {} + }, + + "frameworks": { + "netcoreapp1.0": { + "dependencies": { + "Microsoft.NETCore.App": "1.0.0", + "System.Linq": "4.1.0" + }, + "imports": [ + "dnxcore50", + "portable-net45+win8" + ] + }, + "net46": { + "dependencies": { + }, + "buildOptions": { + "define": [ + "Approvals", + "Culture", + "NSubstitute" + ] + } + } + } +} diff --git a/src/TestStack.BDDfy.Tests/Concurrency/ParallelRunnerScenario.cs b/src/TestStack.BDDfy.Tests/Concurrency/ParallelRunnerScenario.cs index 73f5290e..700e1b7e 100644 --- a/src/TestStack.BDDfy.Tests/Concurrency/ParallelRunnerScenario.cs +++ b/src/TestStack.BDDfy.Tests/Concurrency/ParallelRunnerScenario.cs @@ -1,5 +1,4 @@ -using System; -using System.Linq; +using System.Linq; using System.Threading.Tasks; using TestStack.BDDfy.Tests.Stories; using Xunit; @@ -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()))); - } - catch (Exception e) - { - Assert.False(true, "Threw exception " + e); - } + await Task.WhenAll( + Enumerable.Range(0, 100) + .Select(_ => Task.Run(() => new DummyScenario().BDDfy()))); } } } diff --git a/src/TestStack.BDDfy.Tests/FodyWeavers.xml b/src/TestStack.BDDfy.Tests/FodyWeavers.xml deleted file mode 100644 index 42736963..00000000 --- a/src/TestStack.BDDfy.Tests/FodyWeavers.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Helpers.cs b/src/TestStack.BDDfy.Tests/Helpers.cs index 2cdf6c80..162bde49 100644 --- a/src/TestStack.BDDfy.Tests/Helpers.cs +++ b/src/TestStack.BDDfy.Tests/Helpers.cs @@ -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 methodOn) { - return methodOn.Method; + var methodCallExp = (MethodCallExpression)methodOn.Body; + return methodCallExp.Method; } } } \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/ModuleInitializer.cs b/src/TestStack.BDDfy.Tests/ModuleInitializer.cs deleted file mode 100644 index 72af39c1..00000000 --- a/src/TestStack.BDDfy.Tests/ModuleInitializer.cs +++ /dev/null @@ -1,15 +0,0 @@ -using TestStack.BDDfy.Configuration; - -/// -/// Used by the ModuleInit. All code inside the Initialize method is ran as soon as the assembly is loaded. -/// -public static class ModuleInitializer -{ - /// - /// Initializes the module. - /// - public static void Initialize() - { - Configurator.AsyncVoidSupportEnabled = false; - } -} \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/NetToStringTests.cs b/src/TestStack.BDDfy.Tests/NetToStringTests.cs index 9f46e345..0231e0de 100644 --- a/src/TestStack.BDDfy.Tests/NetToStringTests.cs +++ b/src/TestStack.BDDfy.Tests/NetToStringTests.cs @@ -2,7 +2,6 @@ using Shouldly; using TestStack.BDDfy.Configuration; using Xunit; -using Xunit.Extensions; namespace TestStack.BDDfy.Tests { @@ -78,8 +77,8 @@ public void ReportsIllegalExampleStepNames(string stepName, string expectedStepT NetToString.Convert(stepName).ShouldBe(expectedStepTitle, Case.Sensitive); }); - Assert.NotNull(exception); - Assert.IsType(exception); + exception.ShouldNotBeNull(); + exception.ShouldBeOfType(); } } } \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Properties/AssemblyInfo.cs b/src/TestStack.BDDfy.Tests/Properties/AssemblyInfo.cs index 20d1cd8c..9f97657d 100644 --- a/src/TestStack.BDDfy.Tests/Properties/AssemblyInfo.cs +++ b/src/TestStack.BDDfy.Tests/Properties/AssemblyInfo.cs @@ -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)] \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Reporters/Diagnostics/DiagnosticsReportBuilderTests.cs b/src/TestStack.BDDfy.Tests/Reporters/Diagnostics/DiagnosticsReportBuilderTests.cs index d5165da4..b3d6eef8 100644 --- a/src/TestStack.BDDfy.Tests/Reporters/Diagnostics/DiagnosticsReportBuilderTests.cs +++ b/src/TestStack.BDDfy.Tests/Reporters/Diagnostics/DiagnosticsReportBuilderTests.cs @@ -1,4 +1,5 @@ -using NSubstitute; +#if NSubstitute +using NSubstitute; using TestStack.BDDfy.Reporters; using TestStack.BDDfy.Reporters.Diagnostics; using TestStack.BDDfy.Reporters.Serializers; @@ -21,4 +22,5 @@ public void ShouldSerializeDiagnosticDataToSpecifiedFormat() serializer.Received().Serialize(Arg.Any()); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Reporters/Diagnostics/DiagnosticsReporterTests.cs b/src/TestStack.BDDfy.Tests/Reporters/Diagnostics/DiagnosticsReporterTests.cs index 318ab8e7..38c4017c 100644 --- a/src/TestStack.BDDfy.Tests/Reporters/Diagnostics/DiagnosticsReporterTests.cs +++ b/src/TestStack.BDDfy.Tests/Reporters/Diagnostics/DiagnosticsReporterTests.cs @@ -1,4 +1,5 @@ -using System; +#if NSubstitute +using System; using System.Collections.Generic; using NSubstitute; using TestStack.BDDfy.Reporters; @@ -46,3 +47,4 @@ private DiagnosticsReporter CreateSut() } } } +#endif \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Reporters/Html/ClassicReportBuilderTests.cs b/src/TestStack.BDDfy.Tests/Reporters/Html/ClassicReportBuilderTests.cs index 88248a52..6ea5dd5d 100644 --- a/src/TestStack.BDDfy.Tests/Reporters/Html/ClassicReportBuilderTests.cs +++ b/src/TestStack.BDDfy.Tests/Reporters/Html/ClassicReportBuilderTests.cs @@ -1,3 +1,4 @@ +#if Approvals using System; using System.Runtime.CompilerServices; using TestStack.BDDfy.Reporters; @@ -37,4 +38,5 @@ public void ShouldProduceExpectedHtmlWithExamples() ReportApprover.Approve(model, sut); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Reporters/Html/HtmlReporterTests.cs b/src/TestStack.BDDfy.Tests/Reporters/Html/HtmlReporterTests.cs index 192bbee9..e6a8c887 100644 --- a/src/TestStack.BDDfy.Tests/Reporters/Html/HtmlReporterTests.cs +++ b/src/TestStack.BDDfy.Tests/Reporters/Html/HtmlReporterTests.cs @@ -1,4 +1,5 @@ -using System; +#if NSubstitute +using System; using System.Collections.Generic; using NSubstitute; using Shouldly; @@ -99,3 +100,4 @@ public void ShouldNotLoadCustomJavascriptIfNoneExist() } } } +#endif \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Reporters/Html/MetroReportBuilderTests.cs b/src/TestStack.BDDfy.Tests/Reporters/Html/MetroReportBuilderTests.cs index 1e71ab22..c135aaa1 100644 --- a/src/TestStack.BDDfy.Tests/Reporters/Html/MetroReportBuilderTests.cs +++ b/src/TestStack.BDDfy.Tests/Reporters/Html/MetroReportBuilderTests.cs @@ -1,3 +1,4 @@ +#if Approvals using System; using System.Runtime.CompilerServices; using TestStack.BDDfy.Reporters; @@ -37,4 +38,5 @@ public void ShouldProduceExpectedHtmlWithExamples() ReportApprover.Approve(model, sut); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Reporters/Html/TemporaryCulture.cs b/src/TestStack.BDDfy.Tests/Reporters/Html/TemporaryCulture.cs index fda7d038..5ffed717 100644 --- a/src/TestStack.BDDfy.Tests/Reporters/Html/TemporaryCulture.cs +++ b/src/TestStack.BDDfy.Tests/Reporters/Html/TemporaryCulture.cs @@ -1,3 +1,4 @@ +#if Culture using System; using System.Globalization; using System.Threading; @@ -18,4 +19,5 @@ public void Dispose() Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(_originalCulture); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Reporters/Html/TestableHtmlReporter.cs b/src/TestStack.BDDfy.Tests/Reporters/Html/TestableHtmlReporter.cs index fb233032..6ac9f049 100644 --- a/src/TestStack.BDDfy.Tests/Reporters/Html/TestableHtmlReporter.cs +++ b/src/TestStack.BDDfy.Tests/Reporters/Html/TestableHtmlReporter.cs @@ -1,3 +1,4 @@ +#if NSubstitute using NSubstitute; using TestStack.BDDfy.Reporters; using TestStack.BDDfy.Reporters.Html; @@ -29,4 +30,5 @@ public static TestableHtmlReporter Create() Substitute.For(), Substitute.For()); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Reporters/MarkDown/MarkDownReportBuilderTests.cs b/src/TestStack.BDDfy.Tests/Reporters/MarkDown/MarkDownReportBuilderTests.cs index 24ae6442..2924d3ba 100644 --- a/src/TestStack.BDDfy.Tests/Reporters/MarkDown/MarkDownReportBuilderTests.cs +++ b/src/TestStack.BDDfy.Tests/Reporters/MarkDown/MarkDownReportBuilderTests.cs @@ -1,4 +1,5 @@ -using System; +#if Approvals +using System; using System.Runtime.CompilerServices; using TestStack.BDDfy.Reporters; using TestStack.BDDfy.Reporters.MarkDown; @@ -33,3 +34,4 @@ public void ShouldProduceExpectedMarkdownWithExamples() } } } +#endif \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Reporters/MarkDown/MarkDownReporterTests.cs b/src/TestStack.BDDfy.Tests/Reporters/MarkDown/MarkDownReporterTests.cs index d4fd31e9..06c6b607 100644 --- a/src/TestStack.BDDfy.Tests/Reporters/MarkDown/MarkDownReporterTests.cs +++ b/src/TestStack.BDDfy.Tests/Reporters/MarkDown/MarkDownReporterTests.cs @@ -1,4 +1,5 @@ -using System; +#if NSubstitute +using System; using System.Collections.Generic; using NSubstitute; using TestStack.BDDfy.Reporters; @@ -46,3 +47,4 @@ private MarkDownReporter CreateSut() } } } +#endif \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Reporters/ReportApprover.cs b/src/TestStack.BDDfy.Tests/Reporters/ReportApprover.cs index 919738ae..67d10180 100644 --- a/src/TestStack.BDDfy.Tests/Reporters/ReportApprover.cs +++ b/src/TestStack.BDDfy.Tests/Reporters/ReportApprover.cs @@ -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; @@ -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()); } } @@ -24,4 +27,55 @@ static string Scrub(string scrubPaths) return Regex.Replace(Regex.Replace(Regex.Replace(scrubPaths, @"(? Combine(params Func[] scrubbers) + { + return (inputText) => scrubbers.Aggregate(inputText, (c, s) => s(c)); + } + + public static Func NO_SCRUBBER = (s) => s; + + public static Func RemoveLinesContaining(string value) + { + return s => string.Join("\n", s.Split('\n').Where(l => !l.Contains(value))); + } + } + + } +#endif \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Reporters/TextReporter/TextReporterTests.cs b/src/TestStack.BDDfy.Tests/Reporters/TextReporter/TextReporterTests.cs index 36703b83..73718a8e 100644 --- a/src/TestStack.BDDfy.Tests/Reporters/TextReporter/TextReporterTests.cs +++ b/src/TestStack.BDDfy.Tests/Reporters/TextReporter/TextReporterTests.cs @@ -1,8 +1,8 @@ -using System.Collections.Generic; +#if Approvals +using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Text; -using ApprovalTests; -using ApprovalTests.Utilities; +using Shouldly; using TestStack.BDDfy.Reporters; using Xunit; @@ -24,7 +24,7 @@ public void ShouldProduceExpectedReport() actual.AppendLine(textReporter.ToString()); } - Approvals.Verify(actual.ToString(), StackTraceScrubber.ScrubStackTrace); + actual.ToString().ShouldMatchApproved(c => c.WithScrubber(StackTraceScrubber.ScrubStackTrace)); } [Fact] @@ -41,7 +41,7 @@ public void ShouldProduceExpectedTextWithExamples() actual.AppendLine(textReporter.ToString()); } - Approvals.Verify(actual.ToString(), StackTraceScrubber.ScrubStackTrace); + actual.ToString().ShouldMatchApproved(c => c.WithScrubber(StackTraceScrubber.ScrubStackTrace)); } [Fact] @@ -61,7 +61,8 @@ public void LongStepName() scenario)); var actual = new StringBuilder(); actual.AppendLine(textReporter.ToString()); - Approvals.Verify(actual.ToString(), StackTraceScrubber.ScrubStackTrace); + actual.ToString().ShouldMatchApproved(c => c.WithScrubber(StackTraceScrubber.ScrubStackTrace)); } } } +#endif \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Scanner/Examples/ExampleActionTests.cs b/src/TestStack.BDDfy.Tests/Scanner/Examples/ExampleActionTests.cs index 19ed31cf..2f24641b 100644 --- a/src/TestStack.BDDfy.Tests/Scanner/Examples/ExampleActionTests.cs +++ b/src/TestStack.BDDfy.Tests/Scanner/Examples/ExampleActionTests.cs @@ -1,4 +1,4 @@ -using ApprovalTests; +#if Approvals using Shouldly; using TestStack.BDDfy.Reporters; using Xunit; @@ -27,7 +27,7 @@ public void CanUseActionsInExamples() var textReporter = new TextReporter(); textReporter.Process(story); - Approvals.Verify(textReporter.ToString()); + textReporter.ToString().ShouldMatchApproved(); } private void ShouldBe(int i) @@ -40,4 +40,5 @@ private void SomeSetup() } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Scanner/Examples/ExampleTableTests.cs b/src/TestStack.BDDfy.Tests/Scanner/Examples/ExampleTableTests.cs index 6bc22baf..47c98247 100644 --- a/src/TestStack.BDDfy.Tests/Scanner/Examples/ExampleTableTests.cs +++ b/src/TestStack.BDDfy.Tests/Scanner/Examples/ExampleTableTests.cs @@ -1,6 +1,6 @@ -using System; +#if Approvals +using System; using System.Linq; -using ApprovalTests; using Shouldly; using Xunit; @@ -39,7 +39,7 @@ public void TableToString() {3, 4} }; - Approvals.Verify(table.ToString()); + table.ToString().ShouldMatchApproved(); } [Fact] @@ -51,7 +51,9 @@ public void TableToStringWithAdditionalColumn() {3, 4} }; - Approvals.Verify(table.ToString(new[] {"Additional"}, new[] {new[] {"SomeAdditional Value"}})); + table.ToString(new[] {"Additional"}, new[] {new[] {"SomeAdditional Value"}}) + .ShouldMatchApproved(); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Scanner/Examples/FluentWithExamples.cs b/src/TestStack.BDDfy.Tests/Scanner/Examples/FluentWithExamples.cs index 9895f91e..7e52f9d1 100644 --- a/src/TestStack.BDDfy.Tests/Scanner/Examples/FluentWithExamples.cs +++ b/src/TestStack.BDDfy.Tests/Scanner/Examples/FluentWithExamples.cs @@ -1,5 +1,5 @@ -using System.Runtime.CompilerServices; -using ApprovalTests; +#if Approvals +using System.Runtime.CompilerServices; using Shouldly; using TestStack.BDDfy.Reporters; using Xunit; @@ -28,7 +28,7 @@ public void FluentCanBeUsedWithExamples() var textReporter = new TextReporter(); textReporter.Process(story); - Approvals.Verify(textReporter.ToString()); + textReporter.ToString().ShouldMatchApproved(); } private void GivenIntWithValue(int differentName) @@ -49,7 +49,7 @@ public void Inline() var textReporter = new TextReporter(); textReporter.Process(story); - Approvals.Verify(textReporter.ToString()); + textReporter.ToString().ShouldMatchApproved(); } [Fact] @@ -106,4 +106,5 @@ private void MethodTaking__ExampleInt__(int exampleInt) private string multiWordHeading = null; public ExecutionOrder Prop_3 { get; set; } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Scanner/Examples/FluentWithExamplesAtEnd.cs b/src/TestStack.BDDfy.Tests/Scanner/Examples/FluentWithExamplesAtEnd.cs index c8df0cbf..8019f583 100644 --- a/src/TestStack.BDDfy.Tests/Scanner/Examples/FluentWithExamplesAtEnd.cs +++ b/src/TestStack.BDDfy.Tests/Scanner/Examples/FluentWithExamplesAtEnd.cs @@ -1,6 +1,4 @@ -using System; -using System.Runtime.CompilerServices; -using ApprovalTests; +#if Approvals using Shouldly; using TestStack.BDDfy.Reporters; using Xunit; @@ -20,7 +18,7 @@ public void FluentCanBeUsedWithExamples() var textReporter = new TextReporter(); textReporter.Process(story); - Approvals.Verify(textReporter.ToString()); + textReporter.ToString().ShouldMatchApproved(); } // This test crashes BDDfy or causes an infinite loop @@ -34,7 +32,7 @@ public void FluentCanBeUsedWithExamplesEndingInANumber() { var textReporter = new TextReporter(); textReporter.Process(story); - Approvals.Verify(textReporter.ToString()); + textReporter.ToString().ShouldMatchApproved(); } private void ThenAllIsGood() @@ -55,4 +53,5 @@ private void MethodTaking__ExampleIntA__(int exampleInt) { exampleInt.ShouldBeInRange(1, 2); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Scanner/Examples/ReflectiveWithExamples.cs b/src/TestStack.BDDfy.Tests/Scanner/Examples/ReflectiveWithExamples.cs index 1bf4bcbf..79440bda 100644 --- a/src/TestStack.BDDfy.Tests/Scanner/Examples/ReflectiveWithExamples.cs +++ b/src/TestStack.BDDfy.Tests/Scanner/Examples/ReflectiveWithExamples.cs @@ -1,4 +1,4 @@ -using ApprovalTests; +#if Approvals using Shouldly; using TestStack.BDDfy.Reporters; using Xunit; @@ -32,7 +32,8 @@ public void Run() var reporter = new TextReporter(); reporter.Process(story); - Approvals.Verify(reporter.ToString()); + reporter.ToString().ShouldMatchApproved(); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Scanner/FluentScanner/BDDfyUsingFluentApi.cs b/src/TestStack.BDDfy.Tests/Scanner/FluentScanner/BDDfyUsingFluentApi.cs index d720077f..db0551b6 100644 --- a/src/TestStack.BDDfy.Tests/Scanner/FluentScanner/BDDfyUsingFluentApi.cs +++ b/src/TestStack.BDDfy.Tests/Scanner/FluentScanner/BDDfyUsingFluentApi.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Reflection; using NUnit.Framework; @@ -278,7 +279,7 @@ public void WhenTitleIsNotProvidedItIsFetchedFromMethodName() .BDDfy(); var scenario = story.Scenarios.First(); - scenario.Title.ShouldBe(Configurator.Scanners.Humanize(MethodBase.GetCurrentMethod().Name)); + scenario.Title.ShouldBe(Configurator.Scanners.Humanize(nameof(WhenTitleIsNotProvidedItIsFetchedFromMethodName))); } [Fact] @@ -296,14 +297,14 @@ public void WhenTitleIsProvidedItIsUsedAsIs() private static void ExceptionThrowingAction() { - throw new ApplicationException(); + throw new InvalidDataException(); } [Fact] public void CanPassActionToFluentApi() { this.Given(x => x.GivenAnAction(ExceptionThrowingAction)) - .Then(x => x.ThenCallingTheActionThrows()) + .Then(x => x.ThenCallingTheActionThrows()) .BDDfy(); } @@ -311,7 +312,7 @@ public void CanPassActionToFluentApi() public void CanPassActionAndTitleToFluentApi() { this.Given(x => x.GivenAnAction(ExceptionThrowingAction), "Given an action that throws AppliationException") - .Then(x => x.ThenCallingTheActionThrows(), "Then calling the action does throw that exception") + .Then(x => x.ThenCallingTheActionThrows(), "Then calling the action does throw that exception") .BDDfy(); } } diff --git a/src/TestStack.BDDfy.Tests/Scanner/FluentScanner/DoesNotConflictWithnSubstitute.cs b/src/TestStack.BDDfy.Tests/Scanner/FluentScanner/DoesNotConflictWithnSubstitute.cs index 23a3e325..8baec8fa 100644 --- a/src/TestStack.BDDfy.Tests/Scanner/FluentScanner/DoesNotConflictWithnSubstitute.cs +++ b/src/TestStack.BDDfy.Tests/Scanner/FluentScanner/DoesNotConflictWithnSubstitute.cs @@ -1,4 +1,5 @@ -using NSubstitute; +#if NSubstitute +using NSubstitute; using Xunit; namespace TestStack.BDDfy.Tests.Scanner.FluentScanner @@ -33,4 +34,5 @@ private void GivenSomeStuff() _subsitute = Substitute.For(); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Scanner/FluentScanner/PrependStepTypeTests.cs b/src/TestStack.BDDfy.Tests/Scanner/FluentScanner/PrependStepTypeTests.cs index 632ca030..2b640dde 100644 --- a/src/TestStack.BDDfy.Tests/Scanner/FluentScanner/PrependStepTypeTests.cs +++ b/src/TestStack.BDDfy.Tests/Scanner/FluentScanner/PrependStepTypeTests.cs @@ -1,5 +1,6 @@ -using System.Runtime.CompilerServices; -using ApprovalTests; +#if Approvals +using System.Runtime.CompilerServices; +using Shouldly; using TestStack.BDDfy.Reporters; using Xunit; @@ -25,7 +26,7 @@ public void VerifyPrependStepTitles() var textReporter = new TextReporter(); textReporter.Process(story); - Approvals.Verify(textReporter.ToString()); + textReporter.ToString().ShouldMatchApproved(); } private void GivenAStepWithGivenInIt() @@ -73,4 +74,5 @@ private void WeAreWinning() } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/Scanner/ReflectiveScanner/WhenCombinationOfExecutableAttributeAndMethodNamingConventionIsUsed.cs b/src/TestStack.BDDfy.Tests/Scanner/ReflectiveScanner/WhenCombinationOfExecutableAttributeAndMethodNamingConventionIsUsed.cs index c6103932..764812bb 100644 --- a/src/TestStack.BDDfy.Tests/Scanner/ReflectiveScanner/WhenCombinationOfExecutableAttributeAndMethodNamingConventionIsUsed.cs +++ b/src/TestStack.BDDfy.Tests/Scanner/ReflectiveScanner/WhenCombinationOfExecutableAttributeAndMethodNamingConventionIsUsed.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Linq.Expressions; using Shouldly; using TestStack.BDDfy.Configuration; using Xunit; @@ -77,52 +78,52 @@ public void ScenarioTextIsSetUsingClassName() [Fact] public void GivenStepIsScanned() { - VerifyStepAndItsProperties(_sut.Given, ExecutionOrder.SetupState); + VerifyStepAndItsProperties(() => _sut.Given(), ExecutionOrder.SetupState); } [Fact] public void ExecutableAttributesHaveHigherPriorityThanNamingConventions() { - VerifyStepAndItsProperties(_sut.ThenThisMethodIsFoundAsAGivenStepNotThenStep, ExecutionOrder.ConsecutiveSetupState); + VerifyStepAndItsProperties(() => _sut.ThenThisMethodIsFoundAsAGivenStepNotThenStep(), ExecutionOrder.ConsecutiveSetupState); } [Fact] public void WhenStepIsScanned() { - VerifyStepAndItsProperties(_sut.When, ExecutionOrder.Transition); + VerifyStepAndItsProperties(() => _sut.When(), ExecutionOrder.Transition); } [Fact] public void LegacyTransitionStepIsScanned() { - VerifyStepAndItsProperties(_sut.LegacyTransitionMethod, ExecutionOrder.ConsecutiveTransition); + VerifyStepAndItsProperties(() => _sut.LegacyTransitionMethod(), ExecutionOrder.ConsecutiveTransition); } [Fact] public void ThenStepIsScanned() { - VerifyStepAndItsProperties(_sut.Then, ExecutionOrder.Assertion); + VerifyStepAndItsProperties(() => _sut.Then(), ExecutionOrder.Assertion); } [Fact] public void AndThenStepIsScanned() { - VerifyStepAndItsProperties(_sut.AndThen, ExecutionOrder.ConsecutiveAssertion); + VerifyStepAndItsProperties(() => _sut.AndThen(), ExecutionOrder.ConsecutiveAssertion); } [Fact] public void LegacyAssertionStepIsScanned() { - VerifyStepAndItsProperties(_sut.TestThatSomethingIsRight, ExecutionOrder.Assertion); + VerifyStepAndItsProperties(() => _sut.TestThatSomethingIsRight(), ExecutionOrder.Assertion); } [Fact] public void LegacyConsecutiveAssertionStepIsScanned() { - VerifyStepAndItsProperties(_sut.TestThatSomethingIsWrong, ExecutionOrder.ConsecutiveAssertion); + VerifyStepAndItsProperties(() => _sut.TestThatSomethingIsWrong(), ExecutionOrder.ConsecutiveAssertion); } - void VerifyStepAndItsProperties(Action stepMethodAction, ExecutionOrder expectedOrder, int expectedCount = 1) + void VerifyStepAndItsProperties(Expression stepMethodAction, ExecutionOrder expectedOrder, int expectedCount = 1) { var matchingSteps = _scenario.Steps.Where(s => s.Title.Trim() == Configurator.Scanners.Humanize(Helpers.GetMethodInfo(stepMethodAction).Name)); matchingSteps.Count().ShouldBe(expectedCount); @@ -132,7 +133,7 @@ void VerifyStepAndItsProperties(Action stepMethodAction, ExecutionOrder expected [Fact] public void IgnoredMethodShouldNotBeAddedToSteps() { - var matchingSteps = _scenario.Steps.Where(s => s.Title == Configurator.Scanners.Humanize(Helpers.GetMethodInfo(_sut.ThenIAmNotAStep).Name)); + var matchingSteps = _scenario.Steps.Where(s => s.Title == Configurator.Scanners.Humanize(Helpers.GetMethodInfo(() => _sut.ThenIAmNotAStep()).Name)); matchingSteps.ShouldBeEmpty(); } } diff --git a/src/TestStack.BDDfy.Tests/Scanner/ReflectiveScanner/WhenMethodNamesFollowNamingConventionsOtherThanGivenWhenThen.cs b/src/TestStack.BDDfy.Tests/Scanner/ReflectiveScanner/WhenMethodNamesFollowNamingConventionsOtherThanGivenWhenThen.cs index cd587917..2ac3fded 100644 --- a/src/TestStack.BDDfy.Tests/Scanner/ReflectiveScanner/WhenMethodNamesFollowNamingConventionsOtherThanGivenWhenThen.cs +++ b/src/TestStack.BDDfy.Tests/Scanner/ReflectiveScanner/WhenMethodNamesFollowNamingConventionsOtherThanGivenWhenThen.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using Shouldly; using TestStack.BDDfy.Configuration; using Xunit; @@ -75,8 +76,8 @@ public void TheSetupMethodIsPickedAsNonAsserting() [Fact] public void TheCorrectSpecificationStepsAreFound() { - AssertSpecificationStepIsScannedProperly(_scenario.SpecificationAppearingInTheBeginningOfTheMethodName); - AssertSpecificationStepIsScannedProperly(_scenario.AppearingAtTheEndOfTheMethodNameSpecification); + AssertSpecificationStepIsScannedProperly(() => _scenario.SpecificationAppearingInTheBeginningOfTheMethodName()); + AssertSpecificationStepIsScannedProperly(() => _scenario.AppearingAtTheEndOfTheMethodNameSpecification()); } [Fact] @@ -86,7 +87,7 @@ public void IncorrectSpecificationStepIsNotAdded() specMethod.ShouldBeEmpty(); } - void AssertSpecificationStepIsScannedProperly(Action getSpecMethod) + void AssertSpecificationStepIsScannedProperly(Expression getSpecMethod) { var specMethods = _steps.Where(s => s.Title.Trim() == Configurator.Scanners.Humanize(Helpers.GetMethodInfo(getSpecMethod).Name)); specMethods.Count().ShouldBe(1); diff --git a/src/TestStack.BDDfy.Tests/Scanner/ReflectiveScanner/WhenTestClassUsesExecutableAttributes.cs b/src/TestStack.BDDfy.Tests/Scanner/ReflectiveScanner/WhenTestClassUsesExecutableAttributes.cs index 9438d292..0061e313 100644 --- a/src/TestStack.BDDfy.Tests/Scanner/ReflectiveScanner/WhenTestClassUsesExecutableAttributes.cs +++ b/src/TestStack.BDDfy.Tests/Scanner/ReflectiveScanner/WhenTestClassUsesExecutableAttributes.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using Shouldly; using TestStack.BDDfy.Configuration; using Xunit; @@ -65,7 +66,7 @@ public WhenTestClassUsesExecutableAttributes() _steps = new ExecutableAttributeStepScanner().Scan(TestContext.GetContext(_typeWithAttribute)).ToList(); } - private static string GetStepTextFromMethodName(Action methodInfoAction) + private static string GetStepTextFromMethodName(Expression methodInfoAction) { return Configurator.Scanners.Humanize(Helpers.GetMethodInfo(methodInfoAction).Name); } @@ -82,7 +83,7 @@ public void Given() var givenStep = _steps.Single(s => s.Title == "Given"); givenStep.ExecutionOrder.ShouldBe(ExecutionOrder.SetupState); givenStep.Asserts.ShouldBe(false); - givenStep.Title.Trim().ShouldBe(GetStepTextFromMethodName(_typeWithAttribute.Given)); + givenStep.Title.Trim().ShouldBe(GetStepTextFromMethodName(() => _typeWithAttribute.Given())); } [Fact] @@ -91,7 +92,7 @@ public void AndGiven() var step = _steps.Single(s => s.Title.Trim() == "Some other part of the given"); step.ExecutionOrder.ShouldBe(ExecutionOrder.ConsecutiveSetupState); step.Asserts.ShouldBe(false); - step.Title.Trim().ShouldBe(GetStepTextFromMethodName(_typeWithAttribute.SomeOtherPartOfTheGiven)); + step.Title.Trim().ShouldBe(GetStepTextFromMethodName(() => _typeWithAttribute.SomeOtherPartOfTheGiven())); } [Fact] @@ -100,7 +101,7 @@ public void ButGiven() var step = _steps.Single(s => s.Title.Trim() == "Setup should avoid somethings"); step.ExecutionOrder.ShouldBe(ExecutionOrder.ConsecutiveSetupState); step.Asserts.ShouldBe(false); - step.Title.Trim().ShouldBe(GetStepTextFromMethodName(_typeWithAttribute.SetupShouldAvoidSomethings)); + step.Title.Trim().ShouldBe(GetStepTextFromMethodName(() => _typeWithAttribute.SetupShouldAvoidSomethings())); } [Fact] @@ -117,7 +118,7 @@ public void TheOtherPartOfWhen() { var step = _steps.Single(s => s.Title.Trim() == "The other part of when"); step.ExecutionOrder.ShouldBe(ExecutionOrder.ConsecutiveTransition); - step.Title.Trim().ShouldBe(GetStepTextFromMethodName(_typeWithAttribute.TheOtherPartOfWhen)); + step.Title.Trim().ShouldBe(GetStepTextFromMethodName(() => _typeWithAttribute.TheOtherPartOfWhen())); step.Asserts.ShouldBe(false); } @@ -126,7 +127,7 @@ public void ButWhen() { var step = _steps.Single(s => s.Title.Trim() == "And something has not happened"); step.ExecutionOrder.ShouldBe(ExecutionOrder.ConsecutiveTransition); - step.Title.Trim().ShouldBe(GetStepTextFromMethodName(_typeWithAttribute.AndSomethingHasNotHappened)); + step.Title.Trim().ShouldBe(GetStepTextFromMethodName(() => _typeWithAttribute.AndSomethingHasNotHappened())); step.Asserts.ShouldBe(false); } diff --git a/src/TestStack.BDDfy.Tests/TagsTests.cs b/src/TestStack.BDDfy.Tests/TagsTests.cs index b748261f..a066477e 100644 --- a/src/TestStack.BDDfy.Tests/TagsTests.cs +++ b/src/TestStack.BDDfy.Tests/TagsTests.cs @@ -1,6 +1,7 @@ -using System; +#if Approvals +using System; +using Shouldly; using System.Runtime.CompilerServices; -using ApprovalTests; using TestStack.BDDfy.Reporters; using TestStack.BDDfy.Reporters.Html; using TestStack.BDDfy.Reporters.MarkDown; @@ -22,7 +23,7 @@ public void TagsAreReportedInTextReport() var textReporter = new TextReporter(); textReporter.Process(story); - Approvals.Verify(textReporter.ToString()); + textReporter.ToString().ShouldMatchApproved(); } [Fact] @@ -75,4 +76,5 @@ private ReportModel CreateReportModel() return reportModel; } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj b/src/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj deleted file mode 100644 index 9a10aa20..00000000 --- a/src/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj +++ /dev/null @@ -1,214 +0,0 @@ - - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {357B22FF-84E9-4AB4-AADF-6B9DBB76FB32} - Library - Properties - TestStack.BDDfy.Tests - TestStack.BDDfy.Tests - v4.5 - 512 - - 1ff05bc7 - - - true - full - false - bin\Debug\ - DEBUG;TRACE;$(DefineConstants) - prompt - 4 - false - - - pdbonly - true - bin\Release\ - TRACE;$(DefineConstants) - prompt - 4 - true - false - - - - False - ..\packages\ApprovalTests.3.0.7\lib\net40\ApprovalTests.dll - - - False - ..\packages\ApprovalUtilities.3.0.7\lib\net35\ApprovalUtilities.dll - - - False - ..\packages\NSubstitute.1.8.1.0\lib\net45\NSubstitute.dll - - - False - ..\packages\Shouldly.2.3.1\lib\net40\Shouldly.dll - - - - - - - - - ..\packages\xunit.1.9.2\lib\net20\xunit.dll - - - ..\packages\xunit.extensions.1.9.2\lib\net20\xunit.extensions.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Code - - - Code - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {da6bcb39-307c-4a8e-9a3a-27bb2dbc44a3} - TestStack.BDDfy - - - - - - - - - - - - - - - - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - - \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.ncrunchproject b/src/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.ncrunchproject deleted file mode 100644 index 896f2193..00000000 --- a/src/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.ncrunchproject +++ /dev/null @@ -1,22 +0,0 @@ - - false - false - false - true - false - false - false - false - true - true - false - true - true - 60000 - - - - AutoDetect - STA - x86 - \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.v2.ncrunchproject b/src/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.v2.ncrunchproject deleted file mode 100644 index 896f2193..00000000 --- a/src/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.v2.ncrunchproject +++ /dev/null @@ -1,22 +0,0 @@ - - false - false - false - true - false - false - false - false - true - true - false - true - true - 60000 - - - - AutoDetect - STA - x86 - \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.xproj b/src/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.xproj new file mode 100644 index 00000000..fce62f3a --- /dev/null +++ b/src/TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.xproj @@ -0,0 +1,22 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + 1ceb33e8-3aac-4d02-a15b-5b75b5f662ad + TestStack.BDDfy.Tests + .\obj + .\bin\ + v4.6.1 + + + 2.0 + + + + + + \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/packages.config b/src/TestStack.BDDfy.Tests/packages.config deleted file mode 100644 index 65b1bb63..00000000 --- a/src/TestStack.BDDfy.Tests/packages.config +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/src/TestStack.BDDfy.Tests/project.json b/src/TestStack.BDDfy.Tests/project.json new file mode 100644 index 00000000..2138703b --- /dev/null +++ b/src/TestStack.BDDfy.Tests/project.json @@ -0,0 +1,42 @@ +{ + "version": "1.0.0-*", + "testRunner": "xunit", + + "dependencies": { + "Shouldly": "2.8.0", + "TestStack.BDDfy": { + "target": "project" + }, + "Microsoft.NETCore.Platforms": "1.0.1", + "xunit.core": "2.2.0-beta2-build3300", + "dotnet-test-xunit": "2.2.0-preview2-build1029" + }, + + "runtimes": { + "win10-x64": { } + }, + + "frameworks": { + "netcoreapp1.0": { + "dependencies": { + "Microsoft.NETCore.App": "1.0.0" + }, + "imports": [ + "dnxcore50", + "portable-net45+win8" + ] + }, + "net46": { + "dependencies": { + "NSubstitute": "1.10.0" + }, + "buildOptions": { + "define": [ + "Approvals", + "Culture", + "NSubstitute" + ] + } + } + } +} \ No newline at end of file diff --git a/src/TestStack.BDDfy.sln b/src/TestStack.BDDfy.sln index ecec0d87..ee0ee18d 100644 --- a/src/TestStack.BDDfy.sln +++ b/src/TestStack.BDDfy.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.25123.0 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8F515887-AAB5-4873-8BE9-5AB10685EBCB}" ProjectSection(SolutionItems) = preProject @@ -16,6 +16,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "TestStack.BDDfy", "TestStack.BDDfy\TestStack.BDDfy.xproj", "{20482E5C-B996-4CC8-B30B-FC7B16268B29}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "TestStack.BDDfy.Tests", "TestStack.BDDfy.Tests\TestStack.BDDfy.Tests.xproj", "{1CEB33E8-3AAC-4D02-A15B-5B75B5F662AD}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{AA78EE3D-14A7-47F0-85EF-4412F1514AE3}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "TestStack.BDDfy.Samples", "Samples\TestStack.BDDfy.Samples\TestStack.BDDfy.Samples.xproj", "{C45C458D-5E2D-4EA4-A4EA-BC1931DDF15B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -26,8 +32,19 @@ Global {20482E5C-B996-4CC8-B30B-FC7B16268B29}.Debug|Any CPU.Build.0 = Debug|Any CPU {20482E5C-B996-4CC8-B30B-FC7B16268B29}.Release|Any CPU.ActiveCfg = Release|Any CPU {20482E5C-B996-4CC8-B30B-FC7B16268B29}.Release|Any CPU.Build.0 = Release|Any CPU + {1CEB33E8-3AAC-4D02-A15B-5B75B5F662AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1CEB33E8-3AAC-4D02-A15B-5B75B5F662AD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1CEB33E8-3AAC-4D02-A15B-5B75B5F662AD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1CEB33E8-3AAC-4D02-A15B-5B75B5F662AD}.Release|Any CPU.Build.0 = Release|Any CPU + {C45C458D-5E2D-4EA4-A4EA-BC1931DDF15B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C45C458D-5E2D-4EA4-A4EA-BC1931DDF15B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C45C458D-5E2D-4EA4-A4EA-BC1931DDF15B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C45C458D-5E2D-4EA4-A4EA-BC1931DDF15B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {C45C458D-5E2D-4EA4-A4EA-BC1931DDF15B} = {AA78EE3D-14A7-47F0-85EF-4412F1514AE3} + EndGlobalSection EndGlobal diff --git a/src/TestStack.BDDfy/DateTimeExtensions.cs b/src/TestStack.BDDfy/DateTimeExtensions.cs new file mode 100644 index 00000000..a20bc7aa --- /dev/null +++ b/src/TestStack.BDDfy/DateTimeExtensions.cs @@ -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); + } + } +} diff --git a/src/TestStack.BDDfy/Engine.cs b/src/TestStack.BDDfy/Engine.cs index 9071c31d..3b115259 100644 --- a/src/TestStack.BDDfy/Engine.cs +++ b/src/TestStack.BDDfy/Engine.cs @@ -1,5 +1,4 @@ -using System; -using System.Linq; +using System.Linq; using TestStack.BDDfy.Configuration; using TestStack.BDDfy.Processors; @@ -11,10 +10,16 @@ public class Engine static Engine() { - AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload; +#if APPDOMAIN + System.AppDomain.CurrentDomain.DomainUnload += (sender, e) => { + InvokeBatchProcessors(); + }; +#else + System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += context => InvokeBatchProcessors(); +#endif } - static void CurrentDomain_DomainUnload(object sender, EventArgs e) + static void InvokeBatchProcessors() { foreach (var batchProcessor in Configurator.BatchProcessors.GetProcessors()) { diff --git a/src/TestStack.BDDfy/Processors/ExceptionProcessor.cs b/src/TestStack.BDDfy/Processors/ExceptionProcessor.cs index a6b93fe2..04768278 100644 --- a/src/TestStack.BDDfy/Processors/ExceptionProcessor.cs +++ b/src/TestStack.BDDfy/Processors/ExceptionProcessor.cs @@ -16,6 +16,8 @@ public class ExceptionProcessor : IProcessor static ExceptionProcessor() { var exceptionType = typeof(Exception); +// No best guess for CORE Clr +#if APPDOMAIN foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { if(ExcludedAssemblies.Any(ex => assembly.GetName().FullName.StartsWith(ex))) @@ -37,6 +39,7 @@ static ExceptionProcessor() } } } +#endif BestGuessInconclusiveAssertion = () => { throw new InconclusiveException(); }; } @@ -56,7 +59,7 @@ private static IEnumerable 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) diff --git a/src/TestStack.BDDfy/Processors/InconclusiveException.cs b/src/TestStack.BDDfy/Processors/InconclusiveException.cs index 109f4bd6..a0ee8841 100644 --- a/src/TestStack.BDDfy/Processors/InconclusiveException.cs +++ b/src/TestStack.BDDfy/Processors/InconclusiveException.cs @@ -16,9 +16,11 @@ public InconclusiveException(string message) : base(message) public InconclusiveException(string message, Exception innerException) : base(message, innerException) { } +#if NET40 protected InconclusiveException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif } } \ No newline at end of file diff --git a/src/TestStack.BDDfy/Processors/UnusedExampleException.cs b/src/TestStack.BDDfy/Processors/UnusedExampleException.cs index bdb2fa87..20d4cb78 100644 --- a/src/TestStack.BDDfy/Processors/UnusedExampleException.cs +++ b/src/TestStack.BDDfy/Processors/UnusedExampleException.cs @@ -1,8 +1,8 @@ -namespace TestStack.BDDfy.Processors -{ - using System; - using System.Runtime.Serialization; +using System; +using System.Runtime.Serialization; +namespace TestStack.BDDfy.Processors +{ [Serializable] public class UnusedExampleException : Exception { @@ -10,6 +10,7 @@ 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)) { } +#if NET40 protected UnusedExampleException( SerializationInfo info, @@ -17,5 +18,6 @@ protected UnusedExampleException( : base(info, context) { } +#endif } } \ No newline at end of file diff --git a/src/TestStack.BDDfy/Reporters/Html/ClassicReportBuilder.cs b/src/TestStack.BDDfy/Reporters/Html/ClassicReportBuilder.cs index 0809d2dd..bd699c84 100644 --- a/src/TestStack.BDDfy/Reporters/Html/ClassicReportBuilder.cs +++ b/src/TestStack.BDDfy/Reporters/Html/ClassicReportBuilder.cs @@ -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 @@ -45,7 +45,7 @@ private void HtmlHead() EmbedCssFile(HtmlReportResources.classic_css_min); EmbedCssFile(_model.CustomStylesheet, HtmlReportResources.CustomStylesheetComment); - AddLine(string.Format("BDDfy Test Result {0}", _model.RunDate.ToShortDateString())); + AddLine(string.Format("BDDfy Test Result {0}", _model.RunDate.AsShortDateTimeString())); } } @@ -187,7 +187,7 @@ private void AddScenarioWithExamples(ReportModel.Scenario[] scenarioGroup) var firstScenario = scenarioGroup.First(); var scenarioResult = (Result)scenarioGroup.Max(s => (int)s.Result); - AddLine(string.Format("
{2}{3}
", scenarioResult, firstScenario.Id, HttpUtility.HtmlEncode(firstScenario.Title), FormatTags(firstScenario.Tags))); + AddLine(string.Format("
{2}{3}
", scenarioResult, firstScenario.Id, WebUtility.HtmlEncode(firstScenario.Title), FormatTags(firstScenario.Tags))); using (OpenTag(string.Format("
    ", firstScenario.Id), HtmlTag.ul)) { @@ -195,7 +195,7 @@ private void AddScenarioWithExamples(ReportModel.Scenario[] scenarioGroup) { using (OpenTag(string.Format("
  • ", 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]; @@ -247,7 +247,7 @@ private void AddExampleRow(ReportModel.Scenario scenario, Result scenarioResult) { AddLine(string.Format("", scenario.Result)); foreach (var exampleValue in scenario.Example.Values) - AddLine(string.Format("{0}", HttpUtility.HtmlEncode(exampleValue.GetValueAsString()))); + AddLine(string.Format("{0}", WebUtility.HtmlEncode(exampleValue.GetValueAsString()))); if (scenarioResult != Result.Failed) return; @@ -260,7 +260,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("{1}", exceptionId, encodedExceptionMessage)); using (OpenTag(string.Format("
    ", exceptionId), HtmlTag.div)) { diff --git a/src/TestStack.BDDfy/Reporters/Html/DefaultHtmlReportConfiguration.cs b/src/TestStack.BDDfy/Reporters/Html/DefaultHtmlReportConfiguration.cs index 021217ef..8a4a9409 100644 --- a/src/TestStack.BDDfy/Reporters/Html/DefaultHtmlReportConfiguration.cs +++ b/src/TestStack.BDDfy/Reporters/Html/DefaultHtmlReportConfiguration.cs @@ -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); } } diff --git a/src/TestStack.BDDfy/Reporters/Html/HtmlReportResources.Designer.cs b/src/TestStack.BDDfy/Reporters/Html/HtmlReportResources.Designer.cs deleted file mode 100644 index 070729c8..00000000 --- a/src/TestStack.BDDfy/Reporters/Html/HtmlReportResources.Designer.cs +++ /dev/null @@ -1,128 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace TestStack.BDDfy.Reporters.Html { - using System; - using System.Reflection; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - public class HtmlReportResources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - internal HtmlReportResources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - public static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TestStack.BDDfy.HtmlReportResources", typeof(HtmlReportResources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - public static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to body{margin:0;padding:0;padding-bottom:40px;max-width:100%;background-color:#fff;font-size:10pt;font-family:Verdana,Arial,Helvetica,sans-serif}ul{margin:5px;padding:5px;border:1px solid #d0d0d0;-ms-border-radius:10px;border-radius:10px;background-color:#f0f0f0}li{list-style-type:none}#main{width:100%;height:100%}.header,.footer{background:#679bdb;background:-moz-linear-gradient(top,#679bdb 1%,#3b77a5 100%);background:-ms-linear-gradient(top,#679bdb 1%,#3b77a5 100%);background:-o-linear-gradient(top,#679bdb [rest of string was truncated]";. - /// - public static string classic_css_min { - get { - return ResourceManager.GetString("classic_css_min", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to $(function(){$(".canToggle").each(function(){var n=$("#"+$(this).data("toggle-target"));n.hide();$(this).click(function(){n.toggle(200)})});$(".expandAll").click(function(){$(".steps").css("display","")});$(".collapseAll").click(function(){$(".steps").css("display","none")});$("ul.resultSummary li:not('.storySummary'):not('.scenarioSummary')").append("<input type='checkbox' class='cbx_toggle' checked/>");$(".cbx_toggle").click(function(){var n=$(this),t=n.closest("li").attr("class");$("#testResult div.scena [rest of string was truncated]";. - /// - public static string classic_js_min { - get { - return ResourceManager.GetString("classic_js_min", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to If you drop a custom Javascript named BDDfyCustom.js in your output folder it gets embedded here. This way you can apply some custom Javascript logic to your html report.. - /// - public static string CustomJavascriptComment { - get { - return ResourceManager.GetString("CustomJavascriptComment", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to If you drop a custom stylesheet named BDDfyCustom.css in your output folder it gets embedded here. This way you can apply some custom styles over your html report.. - /// - public static string CustomStylesheetComment { - get { - return ResourceManager.GetString("CustomStylesheetComment", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to /*! jQuery v2.1.0 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */ - ///!function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k="".trim,l={},m=a.document,n="2.1.0",o=function(a,b){return new o.fn.init( [rest of string was truncated]";. - /// - public static string jquery_2_1_0_min { - get { - return ResourceManager.GetString("jquery_2_1_0_min", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline}article,aside,details [rest of string was truncated]";. - /// - public static string metro_css_min { - get { - return ResourceManager.GetString("metro_css_min", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to $(function(){$(".canToggle").each(function(){var n=$("#"+$(this).data("toggle-target"));n.hide();$(this).click(function(){n.toggle(200)})});$(".expandAll").click(function(){$(".steps").css("display","")});$(".collapseAll").click(function(){$(".steps").css("display","none")});$("#filterOptions a").click(function(){var n=$(this).children("div"),t,i;n.toggleClass("filterTileDisabled");t=!n.hasClass("filterTileDisabled");i=n.data("target-class");$("div."+i).closest(".scenario").toggle(t)})}); - ////* - /////# sourceMap [rest of string was truncated]";. - /// - public static string metro_js_min { - get { - return ResourceManager.GetString("metro_js_min", resourceCulture); - } - } - } -} diff --git a/src/TestStack.BDDfy/Reporters/Html/HtmlReportResources.cs b/src/TestStack.BDDfy/Reporters/Html/HtmlReportResources.cs new file mode 100644 index 00000000..62efea43 --- /dev/null +++ b/src/TestStack.BDDfy/Reporters/Html/HtmlReportResources.cs @@ -0,0 +1,34 @@ +using System.IO; + +namespace TestStack.BDDfy.Reporters.Html +{ + internal class HtmlReportResources + { + public static string metro_js_min => Read("TestStack.BDDfy.Reporters.Html.Scripts.metro.min.js"); + public static string metro_css_min => Read("TestStack.BDDfy.Reporters.Html.Scripts.metro.min.css"); + public static string classic_js_min => Read("TestStack.BDDfy.Reporters.Html.Scripts.classic.min.js"); + public static string jquery_2_1_0_min => Read("TestStack.BDDfy.Reporters.Html.Scripts.jquery-2.1.0.min.js"); + public static string classic_css_min => Read("TestStack.BDDfy.Reporters.Html.Scripts.classic.min.css"); + + public static string CustomStylesheetComment => + "If you drop a custom stylesheet named BDDfyCustom.css in your output folder" + + " it gets embedded here. This way you can apply some custom styles over your" + + " html report."; + + public static string CustomJavascriptComment => + "If you drop a custom Javascript named BDDfyCustom.js in your output folder" + + " it gets embedded here. This way you can apply some custom Javascript logic" + + " to your html report."; + + static string Read(string resourceName) + { + var assembly = typeof(HtmlReportResources).Assembly(); + + using (var stream = assembly.GetManifestResourceStream(resourceName)) + using (var reader = new StreamReader(stream)) + { + return reader.ReadToEnd(); + } + } + } +} \ No newline at end of file diff --git a/src/TestStack.BDDfy/Reporters/Html/HtmlReportResources.resx b/src/TestStack.BDDfy/Reporters/Html/HtmlReportResources.resx deleted file mode 100644 index dbc2e931..00000000 --- a/src/TestStack.BDDfy/Reporters/Html/HtmlReportResources.resx +++ /dev/null @@ -1,142 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - - Scripts\classic.min.css;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - - - Scripts\classic.min.js;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - - - If you drop a custom Javascript named BDDfyCustom.js in your output folder it gets embedded here. This way you can apply some custom Javascript logic to your html report. - - - If you drop a custom stylesheet named BDDfyCustom.css in your output folder it gets embedded here. This way you can apply some custom styles over your html report. - - - Scripts\jquery-2.1.0.min.js;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - - - Scripts\metro.min.css;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - - - Scripts\metro.min.js;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - - \ No newline at end of file diff --git a/src/TestStack.BDDfy/Reporters/Html/MetroReportBuilder.cs b/src/TestStack.BDDfy/Reporters/Html/MetroReportBuilder.cs index ecf5b3ef..b29e0bc7 100644 --- a/src/TestStack.BDDfy/Reporters/Html/MetroReportBuilder.cs +++ b/src/TestStack.BDDfy/Reporters/Html/MetroReportBuilder.cs @@ -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 @@ -45,7 +45,7 @@ private void HtmlHead() EmbedCssFile(HtmlReportResources.metro_css_min); EmbedCssFile(_model.CustomStylesheet, HtmlReportResources.CustomStylesheetComment); AddLine(""); - AddLine(string.Format("BDDfy Test Result {0}", _model.RunDate.ToShortDateString())); + AddLine(string.Format("BDDfy Test Result {0}", _model.RunDate.AsShortDateTimeString())); } } @@ -202,7 +202,7 @@ private void AddScenarioWithExamples(ReportModel.Scenario[] scenarioGroup) var firstScenario = scenarioGroup.First(); var scenarioResult = (Result)scenarioGroup.Max(s => (int)s.Result); - AddLine(string.Format("
    {2}{3}
    ", scenarioResult, firstScenario.Id, HttpUtility.HtmlEncode(firstScenario.Title), FormatTags(firstScenario.Tags))); + AddLine(string.Format("
    {2}{3}
    ", scenarioResult, firstScenario.Id, WebUtility.HtmlEncode(firstScenario.Title), FormatTags(firstScenario.Tags))); using (OpenTag(string.Format("
      ", firstScenario.Id), HtmlTag.ul)) { @@ -210,7 +210,7 @@ private void AddScenarioWithExamples(ReportModel.Scenario[] scenarioGroup) { using (OpenTag(string.Format("
    • ", 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]; @@ -262,7 +262,7 @@ private void AddExampleRow(ReportModel.Scenario scenario, Result scenarioResult) { AddLine(string.Format("", scenario.Result)); foreach (var exampleValue in scenario.Example.Values) - AddLine(string.Format("{0}", HttpUtility.HtmlEncode(exampleValue.GetValueAsString()))); + AddLine(string.Format("{0}", WebUtility.HtmlEncode(exampleValue.GetValueAsString()))); if (scenarioResult != Result.Failed) return; @@ -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("{1}", exceptionId, encodedExceptionMessage)); using (OpenTag(string.Format("
      ", exceptionId), HtmlTag.div)) { @@ -287,7 +287,7 @@ private void AddExampleRow(ReportModel.Scenario scenario, Result scenarioResult) private void AddScenario(ReportModel.Scenario scenario) { - AddLine(string.Format("
      {2}{3}
      ", scenario.Result, scenario.Id, HttpUtility.HtmlEncode(scenario.Title), FormatTags(scenario.Tags))); + AddLine(string.Format("
      {2}{3}
      ", scenario.Result, scenario.Id, WebUtility.HtmlEncode(scenario.Title), FormatTags(scenario.Tags))); using (OpenTag(string.Format("
        ", scenario.Id), HtmlTag.ul)) { diff --git a/src/TestStack.BDDfy/Reporters/MarkDown/MarkDownReportBuilder.cs b/src/TestStack.BDDfy/Reporters/MarkDown/MarkDownReportBuilder.cs index 8efa5e2f..4d1105bc 100644 --- a/src/TestStack.BDDfy/Reporters/MarkDown/MarkDownReportBuilder.cs +++ b/src/TestStack.BDDfy/Reporters/MarkDown/MarkDownReportBuilder.cs @@ -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 { @@ -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 @@ -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 } @@ -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); } diff --git a/src/TestStack.BDDfy/Reporters/Serializers/JsonSerializer.cs b/src/TestStack.BDDfy/Reporters/Serializers/JsonSerializer.cs index 7e250b57..a2b81166 100644 --- a/src/TestStack.BDDfy/Reporters/Serializers/JsonSerializer.cs +++ b/src/TestStack.BDDfy/Reporters/Serializers/JsonSerializer.cs @@ -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) @@ -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 + } \ No newline at end of file diff --git a/src/TestStack.BDDfy/Reporters/Writers/FileWriter.cs b/src/TestStack.BDDfy/Reporters/Writers/FileWriter.cs index ef12a3ec..1767eed6 100644 --- a/src/TestStack.BDDfy/Reporters/Writers/FileWriter.cs +++ b/src/TestStack.BDDfy/Reporters/Writers/FileWriter.cs @@ -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); diff --git a/src/TestStack.BDDfy/Scanners/ScenarioScanners/FluentScenarioScanner.cs b/src/TestStack.BDDfy/Scanners/ScenarioScanners/FluentScenarioScanner.cs index 5eda6a0b..87273685 100644 --- a/src/TestStack.BDDfy/Scanners/ScenarioScanners/FluentScenarioScanner.cs +++ b/src/TestStack.BDDfy/Scanners/ScenarioScanners/FluentScenarioScanner.cs @@ -1,6 +1,7 @@ -using System.Collections.Generic; -using System.Linq; +using System; +using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using TestStack.BDDfy.Configuration; namespace TestStack.BDDfy @@ -36,12 +37,23 @@ private List CloneSteps(IEnumerable steps) private static string GetTitleFromMethodNameInStackTrace(object testObject) { - var trace = new StackTrace(); + // ReSharper disable once JoinDeclarationAndInitializer + StackTrace trace; +#if STACKTRACE + trace = new StackTrace(); +#else + try + { + throw new Exception(); + } + catch (Exception e) + { + trace = new StackTrace(e, false); + } +#endif var frames = trace.GetFrames(); - if (frames == null) - return null; - var initiatingFrame = frames.LastOrDefault(s => s.GetMethod().DeclaringType == testObject.GetType()); + var initiatingFrame = frames?.LastOrDefault(s => s.GetMethod().DeclaringType == testObject.GetType()); if (initiatingFrame == null) return null; diff --git a/src/TestStack.BDDfy/Scanners/StepScanners/Examples/ExampleTable.cs b/src/TestStack.BDDfy/Scanners/StepScanners/Examples/ExampleTable.cs index 21f37eb5..52820db4 100644 --- a/src/TestStack.BDDfy/Scanners/StepScanners/Examples/ExampleTable.cs +++ b/src/TestStack.BDDfy/Scanners/StepScanners/Examples/ExampleTable.cs @@ -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) diff --git a/src/TestStack.BDDfy/Scanners/StepScanners/Examples/ExampleValue.cs b/src/TestStack.BDDfy/Scanners/StepScanners/Examples/ExampleValue.cs index 8b909c84..a0d581c0 100644 --- a/src/TestStack.BDDfy/Scanners/StepScanners/Examples/ExampleValue.cs +++ b/src/TestStack.BDDfy/Scanners/StepScanners/Examples/ExampleValue.cs @@ -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) ? "" : string.Format("\"{0}\"", _underlyingValue); throw new ArgumentException(string.Format("Cannot convert {0} to {1} (Column: '{2}', Row: {3})", valueAsString, targetType.Name, Header, Row)); @@ -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)) diff --git a/src/TestStack.BDDfy/Scanners/StepScanners/Examples/UnassignableExampleException.cs b/src/TestStack.BDDfy/Scanners/StepScanners/Examples/UnassignableExampleException.cs index f374c272..e056e7fc 100644 --- a/src/TestStack.BDDfy/Scanners/StepScanners/Examples/UnassignableExampleException.cs +++ b/src/TestStack.BDDfy/Scanners/StepScanners/Examples/UnassignableExampleException.cs @@ -10,6 +10,7 @@ public UnassignableExampleException(string message, Exception inner, ExampleValu { ExampleValue = exampleValue; } +#if NET40 protected UnassignableExampleException( SerializationInfo info, @@ -17,6 +18,7 @@ protected UnassignableExampleException( { } +#endif public ExampleValue ExampleValue { get; private set; } } } \ No newline at end of file diff --git a/src/TestStack.BDDfy/Scanners/StepScanners/Fluent/FluentScanner.cs b/src/TestStack.BDDfy/Scanners/StepScanners/Fluent/FluentScanner.cs index 33efc439..92e5f393 100644 --- a/src/TestStack.BDDfy/Scanners/StepScanners/Fluent/FluentScanner.cs +++ b/src/TestStack.BDDfy/Scanners/StepScanners/Fluent/FluentScanner.cs @@ -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); diff --git a/src/TestStack.BDDfy/Scanners/StepScanners/StepTitleException.cs b/src/TestStack.BDDfy/Scanners/StepScanners/StepTitleException.cs index 09c4dc1c..1e68d310 100644 --- a/src/TestStack.BDDfy/Scanners/StepScanners/StepTitleException.cs +++ b/src/TestStack.BDDfy/Scanners/StepScanners/StepTitleException.cs @@ -16,10 +16,12 @@ public StepTitleException(string message) : base(message) public StepTitleException(string message, Exception innerException) : base(message, innerException) { } + #if NET40 - protected StepTitleException(SerializationInfo info, StreamingContext context) + protected StepTitleException(SerializationInfo info, StreamingContext context) : base(info, context) { } +#endif } } \ No newline at end of file diff --git a/src/TestStack.BDDfy/Scanners/StoryAttributeMetaDataScanner.cs b/src/TestStack.BDDfy/Scanners/StoryAttributeMetaDataScanner.cs index d89ea4fb..d7b23c68 100644 --- a/src/TestStack.BDDfy/Scanners/StoryAttributeMetaDataScanner.cs +++ b/src/TestStack.BDDfy/Scanners/StoryAttributeMetaDataScanner.cs @@ -39,14 +39,26 @@ protected virtual Type GetCandidateStory(object testObject, Type explicitStoryTy if (explicitStoryType != null) return explicitStoryType; - var stackTrace = new StackTrace(); + // ReSharper disable once JoinDeclarationAndInitializer + StackTrace stackTrace; +#if STACKTRACE + stackTrace = new StackTrace(); +#else + try + { + throw new Exception(); + } + catch (Exception e) + { + stackTrace = new StackTrace(e, false); + } +#endif var frames = stackTrace.GetFrames(); if (frames == null) return null; - 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; diff --git a/src/TestStack.BDDfy/SerializableAttribute.cs b/src/TestStack.BDDfy/SerializableAttribute.cs new file mode 100644 index 00000000..85100866 --- /dev/null +++ b/src/TestStack.BDDfy/SerializableAttribute.cs @@ -0,0 +1,10 @@ +#if NET40 + +#else +namespace System.Runtime.Serialization +{ + public class SerializableAttribute : Attribute + { + } +} +#endif \ No newline at end of file diff --git a/src/TestStack.BDDfy/TypeExtensions.cs b/src/TestStack.BDDfy/TypeExtensions.cs new file mode 100644 index 00000000..d20d7329 --- /dev/null +++ b/src/TestStack.BDDfy/TypeExtensions.cs @@ -0,0 +1,81 @@ +using System; +using System.Reflection; + +namespace TestStack.BDDfy +{ +#if NET40 + public static class TypeExtensions + { + public static Assembly Assembly(this Type type) + { + return type.Assembly; + } + + public static object[] GetCustomAttributes(this Type type, Type attributeType, bool inherit) + { + return type.GetCustomAttributes(attributeType, inherit); + } + + public static bool IsEnum(this Type type) + { + return type.IsEnum; + } + + public static bool IsGenericType(this Type type) + { + return type.IsGenericType; + } + + public static bool IsInstanceOfType(this Type type, object obj) + { + return type.IsInstanceOfType(obj); + } + + public static bool IsValueType(this Type type) + { + return type.IsValueType; + } + } + +#else +using System.Linq; + public static class TypeExtensions + { + public static Assembly Assembly(this Type type) + { + return type.GetTypeInfo().Assembly; + + } + + public static object[] GetCustomAttributes(this Type type, Type attributeType, bool inherit) + { + return type.GetTypeInfo() + .GetCustomAttributes(attributeType, inherit) + .Cast() + .ToArray(); + } + + public static bool IsEnum(this Type type) + { + return type.GetTypeInfo().IsEnum; + } + + public static bool IsGenericType(this Type type) + { + return type.GetTypeInfo().IsGenericType; + } + + public static bool IsInstanceOfType(this Type type, object obj) + { + return type.GetTypeInfo().IsInstanceOfType(obj); + } + + public static bool IsValueType(this Type type) + { + return type.GetTypeInfo().IsValueType; + } + } + +#endif + +} diff --git a/src/TestStack.BDDfy/project.json b/src/TestStack.BDDfy/project.json index 33de3f1d..8b8e3bb0 100644 --- a/src/TestStack.BDDfy/project.json +++ b/src/TestStack.BDDfy/project.json @@ -1,10 +1,14 @@ -{ +{ "version": "1.0.0-*", "packOptions": { }, + "buildOptions": { + "embed": "**/Scripts/*.*" + }, "dependencies": { - + "NETStandard.Library": "1.6.0", + "Newtonsoft.Json": "9.0.1" }, "frameworks": { @@ -15,13 +19,25 @@ "frameworkAssemblies": { "System.Web": "4.0.0.0", "System.Web.Extensions": "4.0.0.0" + }, + "buildOptions": { + "define": [ + "APPDOMAIN", + "STACKTRACE" + ] + } + }, + "netstandard1.5": { + "imports": "dnxcore50", + "dependencies": { + "System.Reflection.TypeExtensions": "4.1.0", + "System.Runtime.Loader": "4.0.0", + "System.Threading.ThreadPool": "4.0.10", + "System.Linq.Expressions": "4.1.0", + "System.Reflection": "4.1.0", + "System.Runtime.Extensions": "4.1.0", + "System.Diagnostics.StackTrace": "4.0.1" } } - //"netstandard1.5": { - // "imports": "dnxcore50", - // "dependencies": { - // "NETStandard.Library": "1.5.0-rc2-24027" - // } - //} } } diff --git a/src/TestStack.BDDfy/project.lock.json b/src/TestStack.BDDfy/project.lock.json deleted file mode 100644 index e4c5d1ee..00000000 --- a/src/TestStack.BDDfy/project.lock.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "locked": false, - "version": 2, - "targets": { - ".NETFramework,Version=v4.0": {} - }, - "libraries": {}, - "projectFileDependencyGroups": { - "": [], - ".NETFramework,Version=v4.0": [ - "System.Web >= 4.0.0", - "System.Web.Extensions >= 4.0.0" - ] - }, - "tools": {}, - "projectFileToolGroups": {} -} \ No newline at end of file diff --git a/src/global.json b/src/global.json index 7e11641a..b5eaefb2 100644 --- a/src/global.json +++ b/src/global.json @@ -1,4 +1,4 @@ { - "projects": [ "src" ], - "sdk": { "version": "1.0.0-preview1-002702" } + "projects": [ "src", "." ], + "sdk": { "version": "1.0.0-preview2-003121" } } \ No newline at end of file