-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding generator for generating extension method when IOptions is referenced Bumping TFM to net8 for the tests
- Loading branch information
Showing
29 changed files
with
511 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
GeneratorTests/Moq.AutoMock.Generator.Example.MSTest/ControllerWithOptionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Microsoft.Extensions.Options; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Moq.AutoMock.Generator.Example.MSUnit; | ||
[TestClass] | ||
public class ControllerWithOptionsTests | ||
{ | ||
[TestMethod] | ||
public void CreateInstance_WithOptions_EmbedsOptions() | ||
{ | ||
AutoMocker mocker = new(); | ||
|
||
mocker.WithOptions<TestsOptions>(options => options.Number = 42); | ||
|
||
ControllerWithOptions controller = mocker.CreateInstance<ControllerWithOptions>(); | ||
|
||
Assert.AreEqual(42, controller.Options.Value.Number); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
GeneratorTests/Moq.AutoMock.Generator.Example.NUnit/ControllerWithOptionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Microsoft.Extensions.Options; | ||
using NUnit.Framework; | ||
|
||
namespace Moq.AutoMock.Generator.Example.NUnit; | ||
public class ControllerWithOptionsTests | ||
{ | ||
[Test] | ||
public void CreateInstance_WithOptions_EmbedsOptions() | ||
{ | ||
AutoMocker mocker = new(); | ||
|
||
mocker.WithOptions<TestsOptions>(options => options.Number = 42); | ||
|
||
ControllerWithOptions controller = mocker.CreateInstance<ControllerWithOptions>(); | ||
|
||
Assert.That(42 == controller.Options.Value.Number); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
GeneratorTests/Moq.AutoMock.Generator.Example.xUnit/ControllerWithOptionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Microsoft.Extensions.Options; | ||
using Xunit; | ||
|
||
namespace Moq.AutoMock.Generator.Example.xUnit; | ||
public class ControllerWithOptionsTests | ||
{ | ||
[Fact] | ||
public void CreateInstance_WithOptions_EmbedsOptions() | ||
{ | ||
AutoMocker mocker = new(); | ||
|
||
mocker.WithOptions<TestsOptions>(options => options.Number = 42); | ||
|
||
ControllerWithOptions controller = mocker.CreateInstance<ControllerWithOptions>(); | ||
|
||
Assert.Equal(42, controller.Options.Value.Number); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
GeneratorTests/Moq.AutoMocker.Generator.Example/ControllerWithOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Moq.AutoMock.Generator.Example; | ||
public class ControllerWithOptions | ||
{ | ||
public IOptions<TestsOptions> Options { get; } | ||
|
||
public ControllerWithOptions(IOptions<TestsOptions> options) | ||
{ | ||
Options = options; | ||
} | ||
} |
8 changes: 6 additions & 2 deletions
8
GeneratorTests/Moq.AutoMocker.Generator.Example/Moq.AutoMock.Generator.Example.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Options" /> | ||
</ItemGroup> | ||
|
||
</Project> |
6 changes: 6 additions & 0 deletions
6
GeneratorTests/Moq.AutoMocker.Generator.Example/TestsOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Moq.AutoMock.Generator.Example; | ||
|
||
public class TestsOptions | ||
{ | ||
public int Number { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 24 additions & 24 deletions
48
...Moq.AutoMocker.TestGenerator.Tests.csproj → ...ts/Moq.AutoMocker.Generators.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" /> | ||
<PackageReference Include="MSTest.TestAdapter" /> | ||
<PackageReference Include="MSTest.TestFramework" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.MSTest" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Moq.AutoMocker.TestGenerator\Moq.AutoMocker.TestGenerator.csproj" /> | ||
<ProjectReference Include="..\Moq.AutoMock\Moq.AutoMock.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" /> | ||
<PackageReference Include="MSTest.TestAdapter" /> | ||
<PackageReference Include="MSTest.TestFramework" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.MSTest" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Moq.AutoMocker.Generators\Moq.AutoMocker.Generators.csproj" /> | ||
<ProjectReference Include="..\Moq.AutoMock\Moq.AutoMock.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.