Skip to content

Commit d05f487

Browse files
Tidy and cleanup tests (#94)
* combine tests * appveyor * still broken * fixes
1 parent e13df80 commit d05f487

File tree

40 files changed

+424
-382
lines changed

40 files changed

+424
-382
lines changed

Machine.Specifications.Runner.VisualStudio.sln

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26228.4
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29209.62
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{405D88EB-F3ED-4B4C-B758-4EA98692F96F}"
77
ProjectSection(SolutionItems) = preProject
@@ -15,8 +15,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Machine.Specifications.Runn
1515
EndProject
1616
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Machine.Specifications.Runner.VisualStudio.Specs", "src\Machine.Specifications.Runner.VisualStudio.Specs\Machine.Specifications.Runner.VisualStudio.Specs.csproj", "{28A8C30C-7C6C-402B-86E2-D54A20748564}"
1717
EndProject
18-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleSpecs", "src\SampleSpecs\SampleSpecs.csproj", "{64E9F680-210D-4A69-BF87-13BA3E0FD3B7}"
19-
EndProject
2018
Global
2119
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2220
Debug|Any CPU = Debug|Any CPU
@@ -31,10 +29,6 @@ Global
3129
{28A8C30C-7C6C-402B-86E2-D54A20748564}.Debug|Any CPU.Build.0 = Debug|Any CPU
3230
{28A8C30C-7C6C-402B-86E2-D54A20748564}.Release|Any CPU.ActiveCfg = Release|Any CPU
3331
{28A8C30C-7C6C-402B-86E2-D54A20748564}.Release|Any CPU.Build.0 = Release|Any CPU
34-
{64E9F680-210D-4A69-BF87-13BA3E0FD3B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35-
{64E9F680-210D-4A69-BF87-13BA3E0FD3B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
36-
{64E9F680-210D-4A69-BF87-13BA3E0FD3B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
37-
{64E9F680-210D-4A69-BF87-13BA3E0FD3B7}.Release|Any CPU.Build.0 = Release|Any CPU
3832
EndGlobalSection
3933
GlobalSection(SolutionProperties) = preSolution
4034
HideSolutionNode = FALSE

appveyor.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ environment:
77
build_script:
88
- ps: .\build.ps1
99

10+
skip_branch_with_pr: true
11+
1012
test: off
1113

1214
artifacts:
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using Machine.Specifications;
5+
using Microsoft.CodeAnalysis;
6+
using Microsoft.CodeAnalysis.CSharp;
7+
8+
namespace Machine.VSTestAdapter.Specs
9+
{
10+
public class CompileContext : IDisposable
11+
{
12+
private readonly string _directory = Path.GetDirectoryName(typeof(CompileContext).Assembly.Location);
13+
14+
public string Compile(string code)
15+
{
16+
var filename = Path.Combine(_directory, Guid.NewGuid() + ".dll");
17+
18+
var result = CSharpCompilation.Create(Path.GetFileNameWithoutExtension(filename))
19+
.WithOptions(
20+
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary))
21+
.AddReferences(
22+
MetadataReference.CreateFromFile(typeof(object).Assembly.Location),
23+
#if NETCOREAPP
24+
GetReference("System.Runtime"),
25+
#endif
26+
MetadataReference.CreateFromFile(typeof(Establish).Assembly.Location),
27+
MetadataReference.CreateFromFile(typeof(ShouldExtensionMethods).Assembly.Location))
28+
.AddSyntaxTrees(CSharpSyntaxTree.ParseText(code))
29+
.Emit(filename, Path.ChangeExtension(filename, "pdb"));
30+
31+
if (!result.Success)
32+
throw new InvalidOperationException();
33+
34+
return filename;
35+
}
36+
37+
public void Dispose()
38+
{
39+
var files = Directory.GetFiles(_directory, "*.dll")
40+
.Concat(Directory.GetFiles(_directory, "*.pdb"))
41+
.Where(x => Guid.TryParse(Path.GetFileNameWithoutExtension(x), out _));
42+
43+
foreach (var file in files)
44+
{
45+
SafeDelete(file);
46+
}
47+
}
48+
49+
#if NETCOREAPP
50+
private MetadataReference GetReference(string name)
51+
{
52+
var references = AppContext.GetData("TRUSTED_PLATFORM_ASSEMBLIES")
53+
.ToString()
54+
.Split(Path.PathSeparator);
55+
56+
return references
57+
.Where(x => Path.GetFileNameWithoutExtension(x) == name)
58+
.Select(x => MetadataReference.CreateFromFile(x))
59+
.First();
60+
}
61+
#endif
62+
63+
private void SafeDelete(string filename)
64+
{
65+
try
66+
{
67+
File.Delete(filename);
68+
}
69+
catch
70+
{
71+
}
72+
}
73+
}
74+
}
Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Linq;
32
using Machine.Fakes;
43
using Machine.Specifications;
54
using Machine.VSTestAdapter.Configuration;
@@ -21,34 +20,36 @@ public class When_adapter_runs_tests : WithFakes
2120
</MSpec>
2221
</RunSettings>";
2322

24-
static MSpecTestAdapter Adapter;
23+
static MSpecTestAdapter adapter;
2524

26-
Establish establish = () => {
27-
The<IRunSettings>().WhenToldTo(runSettings => runSettings.SettingsXml).Return(ConfigurationXml);
28-
The<IRunContext>().WhenToldTo(context => context.RunSettings).Return(The<IRunSettings>());
29-
30-
Adapter = new MSpecTestAdapter(An<ISpecificationDiscoverer>(), The<ISpecificationExecutor>());
31-
};
32-
33-
34-
Because of = () => {
35-
Adapter.RunTests(new[] { "dll" }, The<IRunContext>(), An<IFrameworkHandle>());
36-
};
25+
Establish establish = () =>
26+
{
27+
The<IRunSettings>()
28+
.WhenToldTo(runSettings => runSettings.SettingsXml)
29+
.Return(ConfigurationXml);
3730

31+
The<IRunContext>()
32+
.WhenToldTo(context => context.RunSettings)
33+
.Return(The<IRunSettings>());
3834

39-
It should_pick_up_DisableFullTestNameInIDE = () => {
40-
The<ISpecificationExecutor>().WasToldTo(d => d.RunAssembly("dll",
41-
Param<Settings>.Matches(s => s.DisableFullTestNameInIDE == true),
42-
Param<Uri>.IsAnything,
43-
Param<IFrameworkHandle>.IsAnything));
35+
adapter = new MSpecTestAdapter(An<ISpecificationDiscoverer>(), The<ISpecificationExecutor>());
4436
};
4537

46-
It should_pick_up_DisableFullTestNameInOutput = () => {
47-
The<ISpecificationExecutor>().WasToldTo(d => d.RunAssembly("dll",
48-
Param<Settings>.Matches(s => s.DisableFullTestNameInOutput == true),
49-
Param<Uri>.IsAnything,
50-
Param<IFrameworkHandle>.IsAnything));
51-
};
52-
38+
Because of = () =>
39+
adapter.RunTests(new[] { "dll" }, The<IRunContext>(), An<IFrameworkHandle>());
40+
41+
It should_pick_up_DisableFullTestNameInIDE = () =>
42+
The<ISpecificationExecutor>()
43+
.WasToldTo(d => d.RunAssembly("dll",
44+
Param<Settings>.Matches(s => s.DisableFullTestNameInIDE),
45+
Param<Uri>.IsAnything,
46+
Param<IFrameworkHandle>.IsAnything));
47+
48+
It should_pick_up_DisableFullTestNameInOutput = () =>
49+
The<ISpecificationExecutor>()
50+
.WasToldTo(d => d.RunAssembly("dll",
51+
Param<Settings>.Matches(s => s.DisableFullTestNameInOutput),
52+
Param<Uri>.IsAnything,
53+
Param<IFrameworkHandle>.IsAnything));
5354
}
5455
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
using System.Linq;
3-
using Machine.Specifications;
1+
using Machine.Specifications;
42
using Machine.VSTestAdapter.Configuration;
53

64
namespace Machine.VSTestAdapter.Specs.Configuration
@@ -11,13 +9,10 @@ public class When_parsing_configuration_and_mspec_section_is_missing
119
static Settings Settings;
1210
static string ConfigurationXml = "<RunSettings></RunSettings>";
1311

14-
Because of = () => {
12+
Because of = () =>
1513
Settings = Settings.Parse(ConfigurationXml);
16-
};
1714

18-
It should_default_to_DisplayFullTestName_off = () => {
15+
It should_default_to_DisplayFullTestName_off = () =>
1916
Settings.DisableFullTestNameInOutput.ShouldBeFalse();
20-
};
21-
2217
}
2318
}

src/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/BuiltIn/When_discovering_behaviors.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@
66

77
namespace Machine.VSTestAdapter.Specs.Discovery.BuiltIn
88
{
9-
10-
11-
129
public class When_discovering_specs_using_behaviors : With_DiscoverySetup<BuiltInSpecificationDiscoverer>
1310
{
1411
It should_pick_up_the_behavior = () => {
1512
MSpecTestCase discoveredSpec = Results.SingleOrDefault(x => "sample_behavior_test".Equals(x.SpecificationName, StringComparison.Ordinal) &&
1613
"BehaviorSampleSpec".Equals(x.ClassName, StringComparison.Ordinal));
1714
discoveredSpec.ShouldNotBeNull();
1815

19-
discoveredSpec.LineNumber.ShouldEqual(14);
16+
discoveredSpec.LineNumber.ShouldEqual(10);
2017
discoveredSpec.CodeFilePath.EndsWith("BehaviorSample.cs", StringComparison.Ordinal);
2118
};
2219

@@ -29,4 +26,4 @@ public class When_discovering_specs_using_behaviors : With_DiscoverySetup<BuiltI
2926
discoveredSpec.BehaviorFieldType.ShouldEqual("SampleSpecs.SampleBehavior");
3027
};
3128
}
32-
}
29+
}

src/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/BuiltIn/When_discovering_specs.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,30 @@
66

77
namespace Machine.VSTestAdapter.Specs.Discovery.BuiltIn
88
{
9-
109
public class When_discovering_specs : With_DiscoverySetup<BuiltInSpecificationDiscoverer>
1110
{
12-
It should_find_spec = () => {
11+
It should_find_spec = () =>
12+
{
1313
MSpecTestCase discoveredSpec = Results.SingleOrDefault(x => "should_pass".Equals(x.SpecificationName, StringComparison.Ordinal) &&
1414
"StandardSpec".Equals(x.ClassName, StringComparison.Ordinal));
1515
discoveredSpec.ShouldNotBeNull();
1616

17-
discoveredSpec.LineNumber.ShouldEqual(14);
17+
discoveredSpec.LineNumber.ShouldEqual(79);
1818
discoveredSpec.CodeFilePath.EndsWith("StandardSpec.cs", StringComparison.Ordinal);
1919
};
2020

21-
It should_find_empty_spec = () => {
21+
It should_find_empty_spec = () =>
22+
{
2223
MSpecTestCase discoveredSpec = Results.SingleOrDefault(x => "should_be_ignored".Equals(x.SpecificationName, StringComparison.Ordinal) &&
2324
"StandardSpec".Equals(x.ClassName, StringComparison.Ordinal));
2425
discoveredSpec.ShouldNotBeNull();
2526

26-
discoveredSpec.LineNumber.ShouldEqual(20);
27+
discoveredSpec.LineNumber.ShouldEqual(83);
2728
discoveredSpec.CodeFilePath.EndsWith("StandardSpec.cs", StringComparison.Ordinal);
2829
};
2930

30-
It should_find_ignored_spec_but_will_not_find_line_number = () => {
31+
It should_find_ignored_spec_but_will_not_find_line_number = () =>
32+
{
3133
MSpecTestCase discoveredSpec = Results.SingleOrDefault(x => "not_implemented".Equals(x.SpecificationName, StringComparison.Ordinal) &&
3234
"StandardSpec".Equals(x.ClassName, StringComparison.Ordinal));
3335
discoveredSpec.ShouldNotBeNull();
@@ -36,4 +38,4 @@ public class When_discovering_specs : With_DiscoverySetup<BuiltInSpecificationDi
3638
discoveredSpec.CodeFilePath.ShouldBeNull();
3739
};
3840
}
39-
}
41+
}

src/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/BuiltIn/When_discovering_specs_in_nested_types.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public class When_discovering_specs_in_nested_types : With_DiscoverySetup<BuiltI
1616

1717
discoveredSpec.ContextDisplayName.ShouldEqual("Parent NestedSpec");
1818

19-
discoveredSpec.LineNumber.ShouldEqual(14);
19+
discoveredSpec.LineNumber.ShouldEqual(70);
2020
discoveredSpec.CodeFilePath.EndsWith("NestedSpecSample.cs", StringComparison.Ordinal);
2121
};
2222
}
23-
}
23+
}

src/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/BuiltIn/When_discovering_specs_with_custom_act_assert_delegates.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public class When_discovering_specs_with_custom_act_assert_delegates : With_Disc
1414
"CustomActAssertDelegateSpec".Equals(x.ClassName, StringComparison.Ordinal));
1515
discoveredSpec.ShouldNotBeNull();
1616

17-
discoveredSpec.LineNumber.ShouldEqual(31);
17+
discoveredSpec.LineNumber.ShouldEqual(63);
1818
discoveredSpec.CodeFilePath.EndsWith("CustomActAssertDelegateSpec.cs", StringComparison.Ordinal);
1919
};
2020
}
21-
}
21+
}

src/Machine.Specifications.Runner.VisualStudio.Specs/Discovery/When_DisableFullTestNameInIDE_is_off.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,35 @@
44
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
55
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
66
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
7-
using SampleSpecs;
87
using System.Reflection;
8+
using Machine.VSTestAdapter.Specs.Fixtures;
99

1010
namespace Machine.VSTestAdapter.Specs.Discovery
1111
{
1212
public class When_DisableFullTestNameInIDE_is_off : WithFakes
1313
{
14+
static CompileContext compiler;
15+
static Assembly assembly;
1416

15-
Because of = () => {
16-
The<MSpecTestAdapter>().DiscoverTests(new[] { typeof(When_something).GetTypeInfo().Assembly.Location },
17-
An<IDiscoveryContext>(),
18-
An<IMessageLogger>(),
19-
The<ITestCaseDiscoverySink>());
17+
Establish context = () =>
18+
{
19+
compiler = new CompileContext();
20+
21+
var assemblyPath = compiler.Compile(SampleFixture.Code);
22+
assembly = Assembly.LoadFile(assemblyPath);
2023
};
2124

25+
Because of = () =>
26+
The<MSpecTestAdapter>()
27+
.DiscoverTests(new[] {assembly.GetType("SampleSpecs.When_something").GetTypeInfo().Assembly.Location},
28+
An<IDiscoveryContext>(),
29+
An<IMessageLogger>(),
30+
The<ITestCaseDiscoverySink>());
31+
2232

23-
It should_use_full_type_and_field_name_for_display_name = () => {
33+
It should_use_full_type_and_field_name_for_display_name = () =>
2434
The<ITestCaseDiscoverySink>()
2535
.WasToldTo(d => d.SendTestCase(Param<TestCase>.Matches(t => t.DisplayName.Equals("When something it should pass", StringComparison.Ordinal))))
2636
.OnlyOnce();
27-
};
2837
}
2938
}

0 commit comments

Comments
 (0)