Skip to content

Commit

Permalink
Disposing of AM injected types as part of the constructor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Keboo committed Feb 28, 2024
1 parent c99ad7e commit 81c8de8
Show file tree
Hide file tree
Showing 3 changed files with 361 additions and 299 deletions.
94 changes: 52 additions & 42 deletions Moq.AutoMocker.Generators.Tests/GeneratorsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@ public async Task Generation_WithProjectThatDoesNotReferenceAutoMocker_ProducesD
[TestMethod]
public async Task Generation_WithDecoratedNonPartialClass_ProducesDiagnosticError()
{
var code = @"
using Moq.AutoMock;
var code = """

namespace TestNamespace;
using Moq.AutoMock;

[ConstructorTests(TargetType = typeof(Controller))]
public class ControllerTests
{
}
namespace TestNamespace;

[ConstructorTests(TargetType = typeof(Controller))]
public class ControllerTests
{

}

public class Controller { }
";
public class Controller { }

""";
var expectedResult =
DiagnosticResult.CompilerError(Diagnostics.TestClassesMustBePartial.DiagnosticId)
.WithSpan(6, 1, 10, 2)
Expand All @@ -58,19 +60,21 @@ public class Controller { }
[TestMethod]
public async Task Generation_WithNoTargetTypeSpecified_ProducesDiagnosticError()
{
var code = @"
using Moq.AutoMock;
var code = """

namespace TestNamespace;
using Moq.AutoMock;

[ConstructorTests]
public class ControllerTests
{
}
namespace TestNamespace;

[ConstructorTests]
public class ControllerTests
{

}

public class Controller { }

public class Controller { }
";
""";
var expectedResult =
DiagnosticResult.CompilerError(Diagnostics.MustSpecifyTargetType.DiagnosticId)
.WithSpan(6, 2, 6, 18)
Expand Down Expand Up @@ -121,6 +125,9 @@ public void ControllerConstructor_WithNullILoggerController_ThrowsArgumentNullEx
Moq.AutoMock.AutoMocker mocker = new Moq.AutoMock.AutoMocker();
AutoMockerTestSetup(mocker, "ControllerConstructor_WithNullILoggerController_ThrowsArgumentNullException");
ControllerConstructor_WithNullILoggerController_ThrowsArgumentNullExceptionSetup(mocker);
using(System.IDisposable __mockerDisposable = mocker.AsDisposable())
{
}
}

}
Expand All @@ -145,32 +152,35 @@ public void ControllerConstructor_WithNullILoggerController_ThrowsArgumentNullEx
[TestMethod]
public async Task Generation_WithValueTypeParameter_DoesNotGenerateTest()
{
var code = @"
using Moq.AutoMock;
using System.Threading;
var code = """
using Moq.AutoMock;
using System.Threading;

namespace TestNamespace;
namespace TestNamespace;

[ConstructorTests(typeof(Controller))]
public partial class ControllerTests
{
}
[ConstructorTests(typeof(Controller))]
public partial class ControllerTests
{
}

public class Controller
{
public Controller(CancellationToken token) { }
}
";
string expected = @"namespace TestNamespace
{
partial class ControllerTests
{
partial void AutoMockerTestSetup(Moq.AutoMock.AutoMocker mocker, string testName);
public class Controller
{
public Controller(CancellationToken token) { }
}

}
}
";
""";
string expected = """
namespace TestNamespace
{
partial class ControllerTests
{
partial void AutoMockerTestSetup(Moq.AutoMock.AutoMocker mocker, string testName);

}
}

""";

await new VerifyCS.Test
{
Expand Down
Loading

0 comments on commit 81c8de8

Please sign in to comment.