Skip to content

Commit

Permalink
Primary constructor test (#269)
Browse files Browse the repository at this point in the history
* Adding test for primary constructors

* Adding workflow dispatch CI trigger

* Bump lang version

* Bumping SDK in global.json

* Split up restore/build/test

* Fixing type name
  • Loading branch information
Keboo authored Feb 2, 2024
1 parent fe98630 commit 9fb3544
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
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"
}
}

0 comments on commit 9fb3544

Please sign in to comment.