Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primary constructor test #269

Merged
merged 7 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
# PRs will be built, and a package posted to GH Packages
pull_request:

workflow_dispatch:

push:
paths-ignore:
- 'README.md'
Expand All @@ -30,9 +32,14 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v4

# Run unit tests
- name: NuGet restore
run: dotnet restore

- name: Build
run: dotnet build --configuration Release --no-restore

- name: Test
run: dotnet test --configuration Release --verbosity normal
run: dotnet test --configuration Release --no-build --verbosity normal

# Package Release
- name: Pack
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<LangVersion>10.0</LangVersion>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<EnforceCodeStyleInBuild Condition=" '$(BuildingForLiveUnitTesting)' == '' ">true</EnforceCodeStyleInBuild>
Expand Down
10 changes: 10 additions & 0 deletions Moq.AutoMock.Tests/DescribeCreateInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@ public void It_can_create_instances_of_nested_sealed_classes()
Assert.AreEqual(mockWithSealedService.SealedService, mockWithSealedService.NestedSealedService.SealedService);
}

[TestMethod]
public void It_can_create_instance_of_class_with_primary_constructor()
{
AutoMocker mocker = new();

PrimaryConstructor instance = mocker.CreateInstance<PrimaryConstructor>();

Assert.IsInstanceOfType(instance.Service, typeof(IService1));
}

private class CustomStringResolver : IMockResolver
{
public CustomStringResolver(string stringValue)
Expand Down
9 changes: 9 additions & 0 deletions Moq.AutoMock.Tests/Util/PrimaryConstructor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Diagnostics.CodeAnalysis;

namespace Moq.AutoMock.Tests.Util;

[ExcludeFromCodeCoverage]
public class PrimaryConstructor(IService1 service)
{
public IService1 Service { get; set; } = service;
}
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.400",
"version": "8.0.100",
"rollForward": "latestMinor"
}
}
Loading