Skip to content

Commit

Permalink
Feature/issue65 remove full framework (#66)
Browse files Browse the repository at this point in the history
* Added build.yml
* Updated target framework
* Removed old framework specific code
* Removed ReflectionExtensions
* Updated documentation
+semver: breaking
  • Loading branch information
roryprimrose authored Jan 14, 2020
1 parent 8313f09 commit 0983265
Show file tree
Hide file tree
Showing 127 changed files with 2,048 additions and 2,469 deletions.
141 changes: 141 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
name: CI

on:
# Trigger the workflow on push or pull request,
# for any branch or version tag
push:
branches:
- '**'
tags:
- 'v*.*.*'
pull_request:
branches:
- '**'

jobs:
build:
runs-on: ubuntu-latest

steps:

- name: Checkout
uses: actions/checkout@v1

- name: ResolveProject
shell: pwsh
run: Write-Host "::set-env name=PROJECT_NAME::$(${env:GITHUB_REPOSITORY}.substring(${env:GITHUB_REPOSITORY}.IndexOf('/') + 1))"

- name: Fetch tags and master for GitVersion
run: |
git fetch --tags
git branch --create-reflog master origin/master
- name: GitVersion
id: gitversion # step id used as reference for output values
uses: roryprimrose/rungitversion@v1

- name: Update project version
uses: roryprimrose/set-vs-sdk-project-version@v1
with:
version: ${{ steps.gitversion.outputs.NuGetVersionV2 }}
assemblyVersion: ${{ steps.gitversion.outputs.AssemblySemVer }}
fileVersion: ${{ steps.gitversion.outputs.MajorMinorPatch }}
informationalVersion: ${{ steps.gitversion.outputs.InformationalVersion }}

- name: Setup dotnet v2.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: '2.1.300' # SDK Version to use.

- name: Setup dotnet v3.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.100' # SDK Version to use.

# This step is required while waiting on https://github.com/actions/setup-dotnet/issues/25 to be resolved
- name: .net SxS
run: rsync -a ${DOTNET_ROOT/3.1.100/2.1.300}/* $DOTNET_ROOT/

- name: Restore
run: dotnet restore

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

- name: Test
run: dotnet test -c Release --no-build /p:CollectCoverage=true /p:CoverletOutput="$GITHUB_WORKSPACE/coverage/" /p:MergeWith="$GITHUB_WORKSPACE/coverage/coverage.json" /p:CoverletOutputFormat="lcov%2cjson" -m:1

- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: /home/runner/work/${{ env.PROJECT_NAME }}/${{ env.PROJECT_NAME }}/coverage/coverage.info

- name: Pack
run: dotnet pack "./${{ env.PROJECT_NAME }}/${{ env.PROJECT_NAME }}.csproj" -c Release --no-build --include-symbols -o $GITHUB_WORKSPACE/staging

- name: Publish build artifacts
uses: actions/upload-artifact@master
with:
name: packages
path: staging

- name: Setup nuget
uses: olegtarasov/download-nuget@v1
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')

- name: Publish to MyGet.org
env:
MYGET_APIKEY: ${{ secrets.MYGET_APIKEY }}
run: mono $NUGET_EXE push $GITHUB_WORKSPACE/staging/${{ env.PROJECT_NAME }}.*.symbols.nupkg $MYGET_APIKEY -source https://www.myget.org/F/neovolve/api/v2/package
if: github.event_name == 'pull_request'

# - name: Add GitHub registry to NuGet config
# run: mono $NUGET_EXE sources add -name "GPR" -Source https://nuget.pkg.github.com/divergic/index.json -UserName roryprimrose -Password ${{ secrets.GITHUB_TOKEN }}
# if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
#
# - name: Push generated package to GitHub registry
# run: mono $NUGET_EXE push $GITHUB_WORKSPACE/staging/${{ env.PROJECT_NAME }}.*.symbols.nupkg -Source "GPR"
# if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')

- name: Publish to NuGet.org
env:
NUGET_APIKEY: ${{ secrets.NUGET_APIKEY }}
run: mono $NUGET_EXE push $GITHUB_WORKSPACE/staging/${{ env.PROJECT_NAME }}.*.symbols.nupkg $NUGET_APIKEY -source https://api.nuget.org/v3/index.json
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')

- name: Create Release
id: create_release
uses: actions/create-release@v1.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.gitversion.outputs.NuGetVersionV2 }}
release_name: Release ${{ steps.gitversion.outputs.NuGetVersionV2 }}
draft: false
prerelease: ${{ contains(steps.gitversion.outputs.NuGetVersionV2, 'beta') }}
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')

- name: Upload Release Asset for package
id: upload-release-asset-package
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: staging/${{ env.PROJECT_NAME }}.${{ steps.gitversion.outputs.NuGetVersionV2 }}.nupkg
asset_name: ${{ env.PROJECT_NAME }}.${{ steps.gitversion.outputs.NuGetVersionV2 }}.nupkg
asset_content_type: application/zip
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')

- name: Upload Release Asset for symbol package
id: upload-release-asset-symbolpackage
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: staging/${{ env.PROJECT_NAME }}.${{ steps.gitversion.outputs.NuGetVersionV2 }}.symbols.nupkg
asset_name: ${{ env.PROJECT_NAME }}.${{ steps.gitversion.outputs.NuGetVersionV2 }}.symbols.nupkg
asset_content_type: application/zip
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.2;net452</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.0</TargetFrameworks>
<CodeAnalysisRuleSet>..\Solution Items\UnitTest.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="fluentassertions" Version="5.6.0" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.0" />
<PackageReference Include="nsubstitute" Version="4.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="fluentassertions" Version="5.10.0" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="nsubstitute" Version="4.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="2.7.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
50 changes: 37 additions & 13 deletions ModelBuilder.Synchronous.UnitTests/ScenarioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ public void CreateTUsesBuildStrategyToCreateInstanceTest()

var build = Substitute.For<IBuildStrategy>();
var generator = Substitute.For<IValueGenerator>();
var generators = new List<IValueGenerator> {generator}.AsReadOnly();
var generators = new List<IValueGenerator>
{
generator
}.AsReadOnly();

build.ValueGenerators.Returns(generators);
generator.IsSupported(typeof(Guid), null, Arg.Any<IBuildChain>()).Returns(true);
Expand Down Expand Up @@ -92,7 +95,10 @@ public void CreateTUsesBuildStrategyToCreateInstanceWithParametersTest()

var build = Substitute.For<IBuildStrategy>();
var creator = Substitute.For<ITypeCreator>();
var creators = new List<ITypeCreator> {creator}.AsReadOnly();
var creators = new List<ITypeCreator>
{
creator
}.AsReadOnly();

build.TypeCreators.Returns(creators);
creator.CanCreate(typeof(ReadOnlyModel), null, Arg.Any<IBuildChain>()).Returns(true);
Expand Down Expand Up @@ -121,7 +127,10 @@ public void CreateUsesBuildStrategyToCreateInstanceTest()

var build = Substitute.For<IBuildStrategy>();
var generator = Substitute.For<IValueGenerator>();
var generators = new List<IValueGenerator> {generator}.AsReadOnly();
var generators = new List<IValueGenerator>
{
generator
}.AsReadOnly();

build.ValueGenerators.Returns(generators);
generator.IsSupported(typeof(Guid), null, Arg.Any<IBuildChain>()).Returns(true);
Expand Down Expand Up @@ -149,7 +158,10 @@ public void CreateUsesBuildStrategyToCreateInstanceWithParametersTest()

var build = Substitute.For<IBuildStrategy>();
var creator = Substitute.For<ITypeCreator>();
var creators = new List<ITypeCreator> {creator}.AsReadOnly();
var creators = new List<ITypeCreator>
{
creator
}.AsReadOnly();

build.TypeCreators.Returns(creators);
creator.CanCreate(typeof(ReadOnlyModel), null, Arg.Any<IBuildChain>()).Returns(true);
Expand All @@ -175,9 +187,15 @@ public void ForReturnsDefaultExecuteStrategyWithDefaultBuildStrategyConfiguratio
{
var build = Substitute.For<IBuildStrategy>();
var generator = Substitute.For<IValueGenerator>();
var generators = new List<IValueGenerator> {generator}.AsReadOnly();
var generators = new List<IValueGenerator>
{
generator
}.AsReadOnly();
var creator = Substitute.For<ITypeCreator>();
var creators = new List<ITypeCreator> {creator}.AsReadOnly();
var creators = new List<ITypeCreator>
{
creator
}.AsReadOnly();
var ignoreRules = new List<IgnoreRule>().AsReadOnly();
var resolver = Substitute.For<IConstructorResolver>();

Expand Down Expand Up @@ -210,19 +228,25 @@ public void PopulateUsesBuildStrategyToPopulateInstanceTest()
var creator = Substitute.For<ITypeCreator>();
var propertyResolver = Substitute.For<IPropertyResolver>();

var creators = new List<ITypeCreator> {creator}.AsReadOnly();
var creators = new List<ITypeCreator>
{
creator
}.AsReadOnly();
var generator = Substitute.For<IValueGenerator>();
var generators = new List<IValueGenerator> {generator}.AsReadOnly();
var generators = new List<IValueGenerator>
{
generator
}.AsReadOnly();

build.PropertyResolver.Returns(propertyResolver);
build.TypeCreators.Returns(creators);
build.ValueGenerators.Returns(generators);
propertyResolver.CanPopulate(Arg.Any<PropertyInfo>()).Returns(true);
propertyResolver.ShouldPopulateProperty(Arg.Any<IBuildConfiguration>(),
Arg.Any<object>(),
Arg.Any<PropertyInfo>(),
Arg.Any<object[]>())
.Returns(true);
propertyResolver.ShouldPopulateProperty(
Arg.Any<IBuildConfiguration>(),
Arg.Any<object>(),
Arg.Any<PropertyInfo>(),
Arg.Any<object[]>()).Returns(true);
creator.CanPopulate(typeof(SlimModel), null, Arg.Any<IBuildChain>()).Returns(true);
creator.Populate(expected, Arg.Any<IExecuteStrategy>()).Returns(expected);
creator.AutoPopulate.Returns(true);
Expand Down
43 changes: 22 additions & 21 deletions ModelBuilder.UnitTests/AddressValueGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public void GenerateReturnsRandomValueTest()

var target = new AddressValueGenerator();

var first = (string) target.Generate(typeof(string), "address", executeStrategy) as string;
var first = (string) target.Generate(typeof(string), "address", executeStrategy);

string second = null;

for (var index = 0; index < 1000; index++)
{
second = (string) target.Generate(typeof(string), "address", executeStrategy) as string;
second = (string) target.Generate(typeof(string), "address", executeStrategy);

if (string.Equals(first, second, StringComparison.OrdinalIgnoreCase) == false)
{
Expand All @@ -57,22 +57,6 @@ public void GenerateReturnsRandomValueTest()

first.Should().NotBe(second);
}

[Fact]
public void GenerateReturnsStringValueTest()
{
var buildChain = new BuildHistory();
var executeStrategy = Substitute.For<IExecuteStrategy>();

executeStrategy.BuildChain.Returns(buildChain);

var target = new AddressValueGenerator();

var actual = target.Generate(typeof(string), "address", executeStrategy) as string;

actual.Should().BeOfType<string>();
actual.As<string>().Should().NotBeNullOrWhiteSpace();
}

[Theory]
[InlineData("address")]
Expand All @@ -96,13 +80,30 @@ public void GenerateReturnsStreetAddressTest(string propertyName)

actual.Should().NotBeNullOrWhiteSpace();

var matchingLocations = TestData.Locations.Where(x =>
actual.Contains(x.StreetName, StringComparison.OrdinalIgnoreCase)
&& actual.Contains(x.StreetSuffix, StringComparison.OrdinalIgnoreCase));
var matchingLocations = TestData.Locations.Where(
x => actual.Contains(x.StreetName, StringComparison.OrdinalIgnoreCase) && actual.Contains(
x.StreetSuffix,
StringComparison.OrdinalIgnoreCase));

matchingLocations.Should().NotBeEmpty();
}

[Fact]
public void GenerateReturnsStringValueTest()
{
var buildChain = new BuildHistory();
var executeStrategy = Substitute.For<IExecuteStrategy>();

executeStrategy.BuildChain.Returns(buildChain);

var target = new AddressValueGenerator();

var actual = target.Generate(typeof(string), "address", executeStrategy) as string;

actual.Should().BeOfType<string>();
actual.As<string>().Should().NotBeNullOrWhiteSpace();
}

[Theory]
[InlineData("address1")]
[InlineData("Address1")]
Expand Down
5 changes: 4 additions & 1 deletion ModelBuilder.UnitTests/AgeValueGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ public void SettingDefaultMaxAgeOnlyAffectsNewInstancesTest()
[Fact]
public void SettingMaxAgeShouldNotChangeDefaultMaxAgeTest()
{
var target = new AgeValueGenerator {MaxAge = Environment.TickCount};
var target = new AgeValueGenerator
{
MaxAge = Environment.TickCount
};

AgeValueGenerator.DefaultMaxAge.Should().NotBe(target.MaxAge);
}
Expand Down
Loading

0 comments on commit 0983265

Please sign in to comment.