Skip to content

Commit

Permalink
Update build for .NET 6, improved packaging.
Browse files Browse the repository at this point in the history
  • Loading branch information
tillig committed Jul 26, 2023
1 parent 880f4d4 commit 1488557
Show file tree
Hide file tree
Showing 36 changed files with 1,313 additions and 1,133 deletions.
11 changes: 6 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ csharp_indent_switch_labels = true
csharp_indent_labels = one_less_than_current

; Modifier preferences
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async:warning

; Avoid this. unless absolutely necessary
dotnet_style_qualification_for_field = false:suggestion
Expand All @@ -48,31 +48,31 @@ dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion

; Name all constant fields using PascalCase
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = warning
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.required_modifiers = const
dotnet_naming_style.pascal_case_style.capitalization = pascal_case

; Static fields should be _camelCase
dotnet_naming_rule.static_fields_should_be_camel_case.severity = suggestion
dotnet_naming_rule.static_fields_should_be_camel_case.severity = warning
dotnet_naming_rule.static_fields_should_be_camel_case.symbols = static_fields
dotnet_naming_rule.static_fields_should_be_camel_case.style = camel_case_underscore_style
dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.required_modifiers = static
dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected

; Static readonly fields should be PascalCase
dotnet_naming_rule.static_readonly_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.static_readonly_fields_should_be_pascal_case.severity = warning
dotnet_naming_rule.static_readonly_fields_should_be_pascal_case.symbols = static_readonly_fields
dotnet_naming_rule.static_readonly_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.static_readonly_fields.applicable_kinds = field
dotnet_naming_symbols.static_readonly_fields.required_modifiers = static, readonly
dotnet_naming_symbols.static_readonly_fields.applicable_accessibilities = private, internal, private_protected

; Internal and private fields should be _camelCase
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = warning
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
Expand Down Expand Up @@ -128,6 +128,7 @@ csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion

# Other features
csharp_style_namespace_declarations = file_scoped:suggestion
csharp_style_prefer_index_operator = false:none
csharp_style_prefer_range_operator = false:none
csharp_style_pattern_local_over_anonymous_function = false:none
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ publish/
*.pubxml

# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
packages/

# Windows Azure Build Output
Expand Down
7 changes: 5 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"recommendations": [
"davidanson.vscode-markdownlint",
"editorconfig.editorconfig",
"formulahendry.dotnet-test-explorer",
"ms-dotnettools.csharp",
"editorconfig.editorconfig",
"davidanson.vscode-markdownlint"
"ryanluker.vscode-coverage-gutters",
"stkb.rewrap",
"travisillig.vscode-json-stable-stringify"
]
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
"actnars",
"autofac",
"codecov",
"cref",
"inheritdoc",
"langword",
"paramref",
"seealso",
"startable",
"typeparam",
"xunit"
],
"dotnet-test-explorer.testProjectPath": "test/**/*Test.csproj",
"dotnet.defaultSolution": "Autofac.Extras.Moq.sln",
"omnisharp.enableEditorConfigSupport": true,
"omnisharp.enableRoslynAnalyzers": true
}
30 changes: 27 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{
"args": [
"build",
"${workspaceFolder}/Autofac.Extras.Moq.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
Expand All @@ -12,11 +13,34 @@
"kind": "build"
},
"label": "build",
"presentation": {
"reveal": "silent"
"problemMatcher": "$msCompile",
"type": "process"
},
{
"args": [
"test",
"${workspaceFolder}/Autofac.Extras.Moq.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary",
"--results-directory",
"\"artifacts/coverage\"",
"--logger:trx",
"--filter",
"FullyQualifiedName!~Bench",
"/p:CoverletOutput=\"${workspaceFolder}/artifacts/coverage/\"",
"/p:CollectCoverage=true",
"/p:CoverletOutputFormat=lcov",
"/p:Exclude=\"[System.*]*\"",
"-m:1"
],
"command": "dotnet",
"group": {
"isDefault": true,
"kind": "test"
},
"label": "test",
"problemMatcher": "$msCompile",
"type": "shell"
"type": "process"
}
],
"version": "2.0.0"
Expand Down
44 changes: 41 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,51 @@
# Autofac.Extras.Moq

Moq auto mocking integration for [Autofac IoC](https://github.com/autofac/Autofac).
Moq auto mocking integration for [Autofac](https://github.com/autofac/Autofac).

[![Build status](https://ci.appveyor.com/api/projects/status/8c7natm3bsmn7ebx?svg=true)](https://ci.appveyor.com/project/Autofac/autofac-extras-moq) [![codecov](https://codecov.io/gh/Autofac/Autofac.Extras.Moq/branch/develop/graph/badge.svg)](https://app.codecov.io/gh/autofac/Autofac.Extras.Moq) [![NuGet](https://img.shields.io/nuget/v/Autofac.Extras.Moq.svg)](https://nuget.org/packages/Autofac.Extras.Moq)

[![Open in Visual Studio Code](https://open.vscode.dev/badges/open-in-vscode.svg)](https://open.vscode.dev/autofac/Autofac.Extras.Moq)

Please file issues and pull requests for this package in this repository rather than in the Autofac core repo.

- [Documentation](https://autofac.readthedocs.io/en/latest/integration/moq.html)
- [NuGet](https://www.nuget.org/packages/Autofac.Extras.Moq)
- [Contributing](https://autofac.readthedocs.io/en/latest/contributors.html)

## Quick Start

Given you have a system under test and a dependency:

```c#
public class SystemUnderTest
{
public SystemUnderTest(IDependency dependency)
{
}
}

public interface IDependency
{
}
```

When writing your unit test, use the `Autofac.Extras.Moq.AutoMock` class to instantiate the system under test. Doing this will automatically inject a mock dependency into the constructor for you. At the time you create the `AutoMock` factory, you can specify default mock behavior:

- `AutoMock.GetLoose()` - creates automatic mocks using loose mocking behavior.
- `AutoMock.GetStrict()` - creates automatic mocks using strict mocking behavior.
- `AutoMock.GetFromRepository(repo)` - creates mocks based on an existing configured repository.

```c#
[Test]
public void Test()
{
using (var mock = AutoMock.GetLoose())
{
// The AutoMock class will inject a mock IDependency
// into the SystemUnderTest constructor
var sut = mock.Create<SystemUnderTest>();
}
}
```

## Get Help

**Need help with Autofac?** We have [a documentation site](https://autofac.readthedocs.io/) as well as [API documentation](https://autofac.org/apidoc/). We're ready to answer your questions on [Stack Overflow](https://stackoverflow.com/questions/tagged/autofac) or check out the [discussion forum](https://groups.google.com/forum/#forum/autofac).
20 changes: 10 additions & 10 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ nuget:

clone_depth: 1

test: off
test: false

build_script:
- pwsh: .\build.ps1

artifacts:
- path: artifacts\packages\**\*.nupkg
name: MyGet
- path: artifacts\packages\**\*.*nupkg
name: MyGet
type: NuGetPackage

deploy:
- provider: NuGet
server: https://www.myget.org/F/autofac/api/v2/package
api_key:
secure: xUXExgVAagrdEicCjSxsQVrwiLo2TtnfqMbYB9Cauq2cpbm/EVz957PBK0v/GEYq
skip_symbols: true
symbol_server: https://www.myget.org/F/autofac/symbols/api/v2/package
artifact: MyGet
- provider: NuGet
server: https://www.myget.org/F/autofac/api/v2/package
symbol_server: https://www.myget.org/F/autofac/api/v2/package
api_key:
secure: xUXExgVAagrdEicCjSxsQVrwiLo2TtnfqMbYB9Cauq2cpbm/EVz957PBK0v/GEYq
artifact: MyGet
101 changes: 56 additions & 45 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,76 @@

Push-Location $PSScriptRoot
try {
Import-Module $PSScriptRoot/build/Autofac.Build.psd1 -Force
Import-Module $PSScriptRoot/build/Autofac.Build.psd1 -Force

$artifactsPath = "$PSScriptRoot/artifacts"
$packagesPath = "$artifactsPath/packages"
$artifactsPath = "$PSScriptRoot/artifacts"
$packagesPath = "$artifactsPath/packages"

$globalJson = (Get-Content "$PSScriptRoot/global.json" | ConvertFrom-Json -NoEnumerate);
$globalJson = (Get-Content "$PSScriptRoot/global.json" | ConvertFrom-Json -NoEnumerate);

$sdkVersion = $globalJson.sdk.version
$sdkVersion = $globalJson.sdk.version

# Clean up artifacts folder
if (Test-Path $artifactsPath) {
Write-Message "Cleaning $artifactsPath folder"
Remove-Item $artifactsPath -Force -Recurse
}
# Clean up artifacts folder
if (Test-Path $artifactsPath) {
Write-Message "Cleaning $artifactsPath folder"
Remove-Item $artifactsPath -Force -Recurse
}

# Install dotnet SDK versions during CI. In a local build we assume you have
# everything installed; on CI we'll force the install. If you install _any_
# SDKs, you have to install _all_ of them because you can't install SDKs in
# two different locations. dotnet CLI locates SDKs relative to the
# executable.
if ($Null -ne $env:APPVEYOR_BUILD_NUMBER) {
Install-DotNetCli -Version $sdkVersion
foreach ($additional in $globalJson.additionalSdks) {
Install-DotNetCli -Version $additional;
# Install dotnet SDK versions during CI. In a local build we assume you have
# everything installed; on CI we'll force the install. If you install _any_
# SDKs, you have to install _all_ of them because you can't install SDKs in
# two different locations. dotnet CLI locates SDKs relative to the
# executable.
if ($Null -ne $env:APPVEYOR_BUILD_NUMBER) {
Install-DotNetCli -Version $sdkVersion
foreach ($additional in $globalJson.additionalSdks)
{
Install-DotNetCli -Version $additional;
}
}
}

# Write out dotnet information
& dotnet --info
# Write out dotnet information
& dotnet --info

# Set version suffix
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$NULL -ne $env:APPVEYOR_REPO_BRANCH];
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$NULL -ne $env:APPVEYOR_BUILD_NUMBER];
$versionSuffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)).Replace('/', '-'))-$revision" }[$branch -eq "master" -and $revision -ne "local"]

# Set version suffix
$branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$NULL -ne $env:APPVEYOR_REPO_BRANCH];
$revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$NULL -ne $env:APPVEYOR_BUILD_NUMBER];
$versionSuffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)).Replace('/', '-'))-$revision" }[$branch -eq "master" -and $revision -ne "local"]
Write-Message "Package version suffix is '$versionSuffix'"

Write-Message "Package version suffix is '$versionSuffix'"
# Package restore
Write-Message "Restoring packages"
Get-DotNetProjectDirectory -RootPath $PSScriptRoot | Restore-DependencyPackages

# Package restore
Write-Message "Restoring packages"
Get-DotNetProjectDirectory -RootPath $PSScriptRoot | Restore-DependencyPackages
# Build/package
Write-Message "Building projects and packages"
Get-DotNetProjectDirectory -RootPath $PSScriptRoot\src | Invoke-DotNetPack -PackagesPath $packagesPath -VersionSuffix $versionSuffix

# Build/package
Write-Message "Building projects and packages"
Get-DotNetProjectDirectory -RootPath $PSScriptRoot\src | Invoke-DotNetPack -PackagesPath $packagesPath -VersionSuffix $versionSuffix
# Test
Write-Message "Executing unit tests"
Get-DotNetProjectDirectory -RootPath $PSScriptRoot\test | Invoke-Test

# Test
Write-Message "Executing unit tests"
Get-DotNetProjectDirectory -RootPath $PSScriptRoot\test | Invoke-Test
if ($env:CI -eq "true") {
# Generate Coverage Report
Write-Message "Downloading and verifying Codecov Uploader"
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri https://keybase.io/codecovsecurity/pgp_keys.asc -OutFile codecov.asc
gpg --no-default-keyring --keyring trustedkeys.gpg --import codecov.asc
Invoke-WebRequest -Uri https://uploader.codecov.io/latest/linux/codecov -Outfile codecov
Invoke-WebRequest -Uri https://uploader.codecov.io/latest/linux/codecov.SHA256SUM -Outfile codecov.SHA256SUM
Invoke-WebRequest -Uri https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig -Outfile codecov.SHA256SUM.sig
gpgv codecov.SHA256SUM.sig codecov.SHA256SUM
shasum -a 256 -c codecov.SHA256SUM
chmod +x codecov

if ($env:CI -eq "true") {
# Generate Coverage Report
Write-Message "Generating Codecov Report"
Invoke-WebRequest -Uri 'https://codecov.io/bash' -OutFile codecov.sh
& bash codecov.sh -f "artifacts/coverage/*/coverage*.info"
}
Write-Message "Generating Codecov Report"
& ./codecov -f "artifacts/coverage/*/coverage*.info"
}

# Finished
Write-Message "Build finished"
# Finished
Write-Message "Build finished"
}
finally {
Pop-Location
Pop-Location
}
7 changes: 5 additions & 2 deletions build/Analyzers.ruleset
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Autofac Analyzer Rules" Description="Analyzer rules for Autofac assemblies." ToolsVersion="16.0">
<!-- https://github.com/dotnet/roslyn/blob/master/docs/compilers/Rule%20Set%20Format.md -->
<IncludeAll Action="Warning" />
<Rules AnalyzerId="Microsoft.Usage" RuleNamespace="Microsoft.Usage">
<!-- Do not directly await a task without calling ConfigureAwait - we need the context for HttpContext.Current and other context propagation. -->
<Rule Id="CA2007" Action="None" />
<!-- Use ArgumentNullException.ThrowIfNull instead of if/throw - netstandard2.0 and netstandard2.1 don't have ArgumentNullException.ThrowIfNull. -->
<Rule Id="CA1510" Action="None" />
<!-- Implement serialization constructors - false positive when building .NET Core -->
<Rule Id="CA2229" Action="None" />
<!-- Mark ISerializable types with SerializableAttribute - false positive when building .NET Core -->
Expand All @@ -27,13 +28,15 @@
<Rule Id="SA1203" Action="None" />
<!-- Enforce order of static vs. non-static members -->
<Rule Id="SA1204" Action="None" />
<!-- Modifiers are not ordered - .editorconfig handles this -->
<Rule Id="SA1206" Action="None" />
<!-- Enforce order of readonly vs. non-readonly members -->
<Rule Id="SA1214" Action="None" />
<!-- Fields can't start with underscore -->
<Rule Id="SA1309" Action="None" />
<!-- Suppressions must have a justification -->
<Rule Id="SA1404" Action="None" />
<!-- Parameter documentation mus be in the right order -->
<!-- Parameter documentation must be in the right order -->
<Rule Id="SA1612" Action="None" />
<!-- Return value must be documented -->
<Rule Id="SA1615" Action="None" />
Expand Down
3 changes: 1 addition & 2 deletions build/Autofac.Build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ function Invoke-Test {
/p:CoverletOutput="../../artifacts/coverage/$($Project.Name)/" `
/p:CoverletOutputFormat="json%2clcov" `
/p:ExcludeByAttribute=CompilerGeneratedAttribute `
/p:ExcludeByAttribute=GeneratedCodeAttribute `
/p:Exclude="[Autofac.Test.Scenarios.ScannedAssembly]*"
/p:ExcludeByAttribute=GeneratedCodeAttribute

if ($LASTEXITCODE -ne 0) {
Pop-Location
Expand Down
Loading

0 comments on commit 1488557

Please sign in to comment.