From 3ce6f2107caa55d30cd60cb9a3601d3c3a218866 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Thu, 9 Sep 2021 08:40:48 +0200 Subject: [PATCH] Fix test runner failing for test classes with constructor (#51) --- .../TestsRewriter.cs | 328 ++++++++++-------- .../expected_results.json | 2 +- .../expected_results.json | 2 +- .../WithConstructor/.meta/Example.cs | 4 + .../WithConstructor/.meta/config.json | 7 + .../Solutions/WithConstructor/Fake.cs | 4 + .../Solutions/WithConstructor/Fake.csproj | 18 + .../Solutions/WithConstructor/FakeTests.cs | 16 + .../WithConstructor/expected_results.json | 11 + .../Solutions/WithDisposable/.meta/Example.cs | 4 + .../WithDisposable/.meta/config.json | 7 + .../Solutions/WithDisposable/Fake.cs | 4 + .../Solutions/WithDisposable/Fake.csproj | 18 + .../Solutions/WithDisposable/FakeTests.cs | 22 ++ .../WithDisposable/expected_results.json | 11 + .../TestRunnerTests.cs | 14 + 16 files changed, 316 insertions(+), 156 deletions(-) create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/.meta/Example.cs create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/.meta/config.json create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/Fake.cs create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/Fake.csproj create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/FakeTests.cs create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/expected_results.json create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/.meta/Example.cs create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/.meta/config.json create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/Fake.cs create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/Fake.csproj create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/FakeTests.cs create mode 100644 test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/expected_results.json diff --git a/src/Exercism.TestRunner.CSharp/TestsRewriter.cs b/src/Exercism.TestRunner.CSharp/TestsRewriter.cs index 8a9f0b7..f46214e 100644 --- a/src/Exercism.TestRunner.CSharp/TestsRewriter.cs +++ b/src/Exercism.TestRunner.CSharp/TestsRewriter.cs @@ -1,4 +1,6 @@ -using Microsoft.CodeAnalysis; +using System.Linq; + +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -13,7 +15,8 @@ public static SyntaxTree Rewrite(this SyntaxTree tree) => private static SyntaxNode Rewrite(this SyntaxNode node) => node.UnskipTests() - .CaptureConsoleOutput(); + .CaptureConsoleOutput() + .NormalizeWhitespace(); private static SyntaxNode UnskipTests(this SyntaxNode testsRoot) => new UnskipTestsRewriter().Visit(testsRoot); @@ -36,14 +39,171 @@ public override SyntaxNode VisitAttribute(AttributeSyntax node) private class CaptureConsoleOutputRewriter : CSharpSyntaxRewriter { - public override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node) => - base.VisitClassDeclaration( - node.WithBaseList(BaseList( - SingletonSeparatedList( - SimpleBaseType( + public override SyntaxNode VisitConstructorDeclaration(ConstructorDeclarationSyntax node) => + base.VisitConstructorDeclaration( + node.AddParameterListParameters( + Parameter(Identifier("testOutput")) + .WithType( + QualifiedName( QualifiedName( - IdentifierName("System"), - IdentifierName("IDisposable")))))) + IdentifierName("Xunit"), + IdentifierName("Abstractions")), + IdentifierName("ITestOutputHelper")))) + .AddBodyStatements( + ExpressionStatement( + AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + IdentifierName("_testOutput"), + IdentifierName("testOutput"))), + ExpressionStatement( + AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + IdentifierName("_stringWriter"), + ObjectCreationExpression( + QualifiedName( + QualifiedName( + IdentifierName("System"), + IdentifierName("IO")), + IdentifierName("StringWriter"))) + .WithArgumentList( + ArgumentList()))), + ExpressionStatement( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("System"), + IdentifierName("Console")), + IdentifierName("SetOut"))) + .WithArgumentList( + ArgumentList( + SingletonSeparatedList( + Argument( + IdentifierName("_stringWriter")))))), + ExpressionStatement( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("System"), + IdentifierName("Console")), + IdentifierName("SetError"))) + .WithArgumentList( + ArgumentList( + SingletonSeparatedList( + Argument( + IdentifierName("_stringWriter")))))))); + + public override SyntaxNode? VisitMethodDeclaration(MethodDeclarationSyntax node) + { + if (node.Identifier.Text == "Dispose") + return base.VisitMethodDeclaration( + node.AddBodyStatements(LocalDeclarationStatement( + VariableDeclaration( + IdentifierName("var")) + .WithVariables( + SingletonSeparatedList( + VariableDeclarator( + Identifier("output")) + .WithInitializer( + EqualsValueClause( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("_stringWriter"), + IdentifierName("ToString")))))))), + IfStatement( + BinaryExpression( + SyntaxKind.GreaterThanExpression, + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("output"), + IdentifierName("Length")), + LiteralExpression( + SyntaxKind.NumericLiteralExpression, + Literal(500))), + Block( + SingletonList( + ExpressionStatement( + AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + IdentifierName("output"), + BinaryExpression( + SyntaxKind.AddExpression, + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("output"), + IdentifierName("Substring"))) + .WithArgumentList( + ArgumentList( + SeparatedList( + new SyntaxNodeOrToken[] + { + Argument( + LiteralExpression( + SyntaxKind + .NumericLiteralExpression, + Literal(0))), + Token(SyntaxKind.CommaToken), + Argument( + LiteralExpression( + SyntaxKind + .NumericLiteralExpression, + Literal(450))) + }))), + LiteralExpression( + SyntaxKind.StringLiteralExpression, + Literal(@" + + Output was truncated. Please limit to 500 chars.")))))))), + ExpressionStatement( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("_testOutput"), + IdentifierName("WriteLine"))) + .WithArgumentList( + ArgumentList( + SingletonSeparatedList( + Argument( + IdentifierName("output")))))) + + )); + + + return base.VisitMethodDeclaration(node); + } + + public override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node) + { + // TODO: refactor to method + if (!node.DescendantNodes().OfType().Any()) + node = node.AddMembers( + ConstructorDeclaration(Identifier(node.Identifier.Text)) + .WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword))) + .WithBody(Block())); + + // TODO: refactor to method + if (node.BaseList == null || !node.BaseList.DescendantNodes().OfType().Any(baseType => baseType.ToString().EndsWith("IDisposable"))) + node = node.AddBaseListTypes( + SimpleBaseType( + QualifiedName( + IdentifierName("System"), + IdentifierName("IDisposable")))); + + // TODO: refactor to method + if (node.DescendantNodes().OfType().All(method => method.Identifier.Text != "Dispose")) + node = node.AddMembers( + MethodDeclaration( + PredefinedType(Token(SyntaxKind.VoidKeyword)), + Identifier("Dispose")) + .WithModifiers(TokenList(Token(SyntaxKind.PublicKeyword)))); + + return base.VisitClassDeclaration( + node .AddMembers( FieldDeclaration( VariableDeclaration( @@ -53,160 +213,20 @@ public override SyntaxNode VisitClassDeclaration(ClassDeclarationSyntax node) => IdentifierName("Abstractions")), IdentifierName("ITestOutputHelper"))) .WithVariables( - SingletonSeparatedList( + SingletonSeparatedList( VariableDeclarator( Identifier("_testOutput"))))), FieldDeclaration( VariableDeclaration( QualifiedName( - QualifiedName( - IdentifierName("System"), + QualifiedName(IdentifierName("System"), IdentifierName("IO")), IdentifierName("StringWriter"))) .WithVariables( - SingletonSeparatedList( + SingletonSeparatedList( VariableDeclarator( - Identifier("_stringWriter"))))), - ConstructorDeclaration( - Identifier(node.Identifier.Text)) - .WithModifiers( - TokenList( - Token(SyntaxKind.PublicKeyword))) - .WithParameterList( - ParameterList( - SingletonSeparatedList( - Parameter( - Identifier("testOutput")) - .WithType( - QualifiedName( - QualifiedName( - IdentifierName("Xunit"), - IdentifierName("Abstractions")), - IdentifierName("ITestOutputHelper")))))) - .WithBody( - Block( - ExpressionStatement( - AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - IdentifierName("_testOutput"), - IdentifierName("testOutput"))), - ExpressionStatement( - AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - IdentifierName("_stringWriter"), - ObjectCreationExpression( - QualifiedName( - QualifiedName( - IdentifierName("System"), - IdentifierName("IO")), - IdentifierName("StringWriter"))) - .WithArgumentList( - ArgumentList()))), - ExpressionStatement( - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName("System"), - IdentifierName("Console")), - IdentifierName("SetOut"))) - .WithArgumentList( - ArgumentList( - SingletonSeparatedList( - Argument( - IdentifierName("_stringWriter")))))), - ExpressionStatement( - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName("System"), - IdentifierName("Console")), - IdentifierName("SetError"))) - .WithArgumentList( - ArgumentList( - SingletonSeparatedList( - Argument( - IdentifierName("_stringWriter")))))))), - MethodDeclaration( - PredefinedType( - Token(SyntaxKind.VoidKeyword)), - Identifier("Dispose")) - .WithModifiers( - TokenList( - Token(SyntaxKind.PublicKeyword))) - .WithBody( - Block( - LocalDeclarationStatement( - VariableDeclaration( - IdentifierName("var")) - .WithVariables( - SingletonSeparatedList( - VariableDeclarator( - Identifier("output")) - .WithInitializer( - EqualsValueClause( - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName("_stringWriter"), - IdentifierName("ToString")))))))), - IfStatement( - BinaryExpression( - SyntaxKind.GreaterThanExpression, - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName("output"), - IdentifierName("Length")), - LiteralExpression( - SyntaxKind.NumericLiteralExpression, - Literal(500))), - Block( - SingletonList( - ExpressionStatement( - AssignmentExpression( - SyntaxKind.SimpleAssignmentExpression, - IdentifierName("output"), - BinaryExpression( - SyntaxKind.AddExpression, - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName("output"), - IdentifierName("Substring"))) - .WithArgumentList( - ArgumentList( - SeparatedList( - new SyntaxNodeOrToken[]{ - Argument( - LiteralExpression( - SyntaxKind.NumericLiteralExpression, - Literal(0))), - Token(SyntaxKind.CommaToken), - Argument( - LiteralExpression( - SyntaxKind.NumericLiteralExpression, - Literal(450)))}))), - LiteralExpression( - SyntaxKind.StringLiteralExpression, - Literal(@" - - Output was truncated. Please limit to 500 chars.")))))))), - ExpressionStatement( - InvocationExpression( - MemberAccessExpression( - SyntaxKind.SimpleMemberAccessExpression, - IdentifierName("_testOutput"), - IdentifierName("WriteLine"))) - .WithArgumentList( - ArgumentList( - SingletonSeparatedList( - Argument( - IdentifierName("output"))))))))).NormalizeWhitespace()); - - + Identifier("_stringWriter"))))))); + } } } } \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/MultipleCompileErrors/expected_results.json b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/MultipleCompileErrors/expected_results.json index 578e96e..f65e4d6 100644 --- a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/MultipleCompileErrors/expected_results.json +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/MultipleCompileErrors/expected_results.json @@ -1,6 +1,6 @@ { "version": 3, "status": "error", - "message": "FakeTests.cs(5,66): error CS0117: \u0027Fake\u0027 does not contain a definition for \u0027Add\u0027\nFakeTests.cs(7,66): error CS0117: \u0027Fake\u0027 does not contain a definition for \u0027Sub\u0027", + "message": "FakeTests.cs(6,66): error CS0117: \u0027Fake\u0027 does not contain a definition for \u0027Add\u0027\nFakeTests.cs(8,66): error CS0117: \u0027Fake\u0027 does not contain a definition for \u0027Sub\u0027", "tests": [] } \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/MultipleTestsWithTestOutputExceedingLimit/expected_results.json b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/MultipleTestsWithTestOutputExceedingLimit/expected_results.json index 45af368..0ca7130 100644 --- a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/MultipleTestsWithTestOutputExceedingLimit/expected_results.json +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/MultipleTestsWithTestOutputExceedingLimit/expected_results.json @@ -5,7 +5,7 @@ { "name": "Add should add numbers", "status": "pass", - "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n\n Output was truncated. Please limit to 500 chars.", + "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n\n Output was truncated. Please limit to 500 chars.", "test_code": "Assert.Equal(2, Fake.Add(1, 1))" }, { diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/.meta/Example.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/.meta/Example.cs new file mode 100644 index 0000000..bfbf44e --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/.meta/Example.cs @@ -0,0 +1,4 @@ +public static class Fake +{ + public static int Add(int x, int y) => x + y; +} \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/.meta/config.json b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/.meta/config.json new file mode 100644 index 0000000..b6395cc --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/.meta/config.json @@ -0,0 +1,7 @@ +{ + "files": { + "solution": ["Fake.cs"], + "test": ["FakeTests.cs"], + "example": [".meta/Example.cs"] + } +} \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/Fake.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/Fake.cs new file mode 100644 index 0000000..22d63a6 --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/Fake.cs @@ -0,0 +1,4 @@ +public class Fake +{ + public int Add(int x, int y) => x + y; +} \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/Fake.csproj b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/Fake.csproj new file mode 100644 index 0000000..d6a2c1b --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/Fake.csproj @@ -0,0 +1,18 @@ + + + + net5.0 + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/FakeTests.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/FakeTests.cs new file mode 100644 index 0000000..a43e275 --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/FakeTests.cs @@ -0,0 +1,16 @@ +using Xunit; +using System.Globalization; +using System.Threading; + +public class FakeTests +{ + public FakeTests() + { + var enUsCulture = new CultureInfo("en-US"); + Thread.CurrentThread.CurrentCulture = enUsCulture; + Thread.CurrentThread.CurrentUICulture = enUsCulture; + } + + [Fact] + public void Add_should_add_numbers() => Assert.Equal(2, new Fake().Add(1, 1)); +} \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/expected_results.json b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/expected_results.json new file mode 100644 index 0000000..56365e0 --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithConstructor/expected_results.json @@ -0,0 +1,11 @@ +{ + "version": 3, + "status": "pass", + "tests": [ + { + "name": "Add should add numbers", + "status": "pass", + "test_code": "Assert.Equal(2, Fake.Add(1, 1))" + } + ] +} \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/.meta/Example.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/.meta/Example.cs new file mode 100644 index 0000000..bfbf44e --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/.meta/Example.cs @@ -0,0 +1,4 @@ +public static class Fake +{ + public static int Add(int x, int y) => x + y; +} \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/.meta/config.json b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/.meta/config.json new file mode 100644 index 0000000..b6395cc --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/.meta/config.json @@ -0,0 +1,7 @@ +{ + "files": { + "solution": ["Fake.cs"], + "test": ["FakeTests.cs"], + "example": [".meta/Example.cs"] + } +} \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/Fake.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/Fake.cs new file mode 100644 index 0000000..22d63a6 --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/Fake.cs @@ -0,0 +1,4 @@ +public class Fake +{ + public int Add(int x, int y) => x + y; +} \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/Fake.csproj b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/Fake.csproj new file mode 100644 index 0000000..d6a2c1b --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/Fake.csproj @@ -0,0 +1,18 @@ + + + + net5.0 + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/FakeTests.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/FakeTests.cs new file mode 100644 index 0000000..4bfc655 --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/FakeTests.cs @@ -0,0 +1,22 @@ +using System; + +using Xunit; +using System.IO; + +public class FakeTests : IDisposable +{ + private FileStream _file; + + public FakeTests() + { + _file = File.Open("tmp.txt", FileMode.Create); + } + + [Fact] + public void Add_should_add_numbers() => Assert.Equal(2, new Fake().Add(1, 1)); + + public void Dispose() + { + _file.Dispose(); + } +} \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/expected_results.json b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/expected_results.json new file mode 100644 index 0000000..56365e0 --- /dev/null +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/Solutions/WithDisposable/expected_results.json @@ -0,0 +1,11 @@ +{ + "version": 3, + "status": "pass", + "tests": [ + { + "name": "Add should add numbers", + "status": "pass", + "test_code": "Assert.Equal(2, Fake.Add(1, 1))" + } + ] +} \ No newline at end of file diff --git a/test/Exercism.TestRunner.CSharp.IntegrationTests/TestRunnerTests.cs b/test/Exercism.TestRunner.CSharp.IntegrationTests/TestRunnerTests.cs index d65ea2a..50ec71f 100644 --- a/test/Exercism.TestRunner.CSharp.IntegrationTests/TestRunnerTests.cs +++ b/test/Exercism.TestRunner.CSharp.IntegrationTests/TestRunnerTests.cs @@ -129,5 +129,19 @@ public void WithExample() var testRun = TestSolutionRunner.Run("WithExample"); Assert.Equal(testRun.Expected, testRun.Actual); } + + [Fact] + public void WithConstructor() + { + var testRun = TestSolutionRunner.Run("WithConstructor"); + Assert.Equal(testRun.Expected, testRun.Actual); + } + + [Fact] + public void WithDisposable() + { + var testRun = TestSolutionRunner.Run("WithDisposable"); + Assert.Equal(testRun.Expected, testRun.Actual); + } } } \ No newline at end of file