Skip to content

Commit

Permalink
Separates test extensions into it's own assembly (Fixes #149) (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
nshenoy authored Aug 7, 2021
1 parent 0054d29 commit 9434db4
Show file tree
Hide file tree
Showing 29 changed files with 202 additions and 55 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/ci-testextensions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Build TestExtensions

on:
push:
branches: [ main ]
release:
types: [ published ]

env:
NETCORE_VERSION: '5.0.202'
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
PROJECT_NAME: LocalStorage.TestExtensions
GITHUB_FEED: https://nuget.pkg.github.com/Blazored/
GITHUB_USER: chrissainty
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NUGET_FEED: https://api.nuget.org/v3/index.json
NUGET_KEY: ${{ secrets.NUGET_KEY }}

jobs:
build:
name: Build, test and pack
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup .NET Core ${{ env.NETCORE_VERSION }}
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.NETCORE_VERSION }}
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Restore
run: dotnet restore

- name: Pack
run: dotnet pack -v normal -c Release --no-restore --include-symbols --include-source -p:PackageVersion=$GITHUB_RUN_ID src/Blazored.$PROJECT_NAME/Blazored.$PROJECT_NAME.*proj

- name: Upload Artifact TestExtensions
uses: actions/upload-artifact@v2
with:
name: nupkg
path: ./src/Blazored.${{ env.PROJECT_NAME }}/bin/Release/*.nupkg

prerelease:
needs: build
if: github.event_name != 'release'
runs-on: ubuntu-latest
steps:
- name: Download Artifact
uses: actions/download-artifact@v1
with:
name: nupkg
- name: Push to GitHub Feed
run: |
for f in ./nupkg/*.nupkg
do
curl -vX PUT -u "$GITHUB_USER:$GITHUB_TOKEN" -F package=@$f $GITHUB_FEED
done
deploy:
needs: build
if: github.event_name == 'release'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.NETCORE_VERSION }}
- name: Create Release NuGet package
run: |
arrTag=(${GITHUB_REF//\// })
VERSION="${arrTag[2]}"
echo Version: $VERSION
VERSION="${VERSION//v}"
echo Clean Version: $VERSION
dotnet pack -v normal -c Release --include-symbols --include-source -p:PackageVersion=$VERSION -o nupkg src/Blazored.$PROJECT_NAME/Blazored.$PROJECT_NAME.*proj
- name: Push to GitHub Feed
run: |
for f in ./nupkg/*.nupkg
do
curl -vX PUT -u "$GITHUB_USER:$GITHUB_TOKEN" -F package=@$f $GITHUB_FEED
done
- name: Push to NuGet Feed
run: dotnet nuget push ./nupkg/*.nupkg --source $NUGET_FEED --skip-duplicate --api-key $NUGET_KEY
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ PublishScripts/

# NuGet Packages
*.nupkg
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
Expand Down
17 changes: 16 additions & 1 deletion Blazored.LocalStorage.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
.github\workflows\ci-main.yml = .github\workflows\ci-main.yml
.github\workflows\ci-pr.yml = .github\workflows\ci-pr.yml
.github\workflows\ci-testextensions.yml = .github\workflows\ci-testextensions.yml
README.md = README.md
.github\workflows\release-drafter.yml = .github\workflows\release-drafter.yml
EndProjectSection
Expand All @@ -23,7 +24,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{B82A5126
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazored.LocalStorage.Tests", "tests\Blazored.LocalStorage.Tests\Blazored.LocalStorage.Tests.csproj", "{5A6A013E-325D-4A5F-B2FA-659B4FD2BDBC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bUnitExample", "samples\bUnitExample\bUnitExample.csproj", "{10F6FB83-3135-4B73-B0EB-D008A31AE8FA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bUnitExample", "samples\bUnitExample\bUnitExample.csproj", "{10F6FB83-3135-4B73-B0EB-D008A31AE8FA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazored.LocalStorage.TestExtensions", "src\Blazored.LocalStorage.TestExtensions\Blazored.LocalStorage.TestExtensions.csproj", "{650F351B-06A0-4D65-8A55-C9FF8D5BC177}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -95,6 +98,18 @@ Global
{10F6FB83-3135-4B73-B0EB-D008A31AE8FA}.Release|x64.Build.0 = Release|Any CPU
{10F6FB83-3135-4B73-B0EB-D008A31AE8FA}.Release|x86.ActiveCfg = Release|Any CPU
{10F6FB83-3135-4B73-B0EB-D008A31AE8FA}.Release|x86.Build.0 = Release|Any CPU
{650F351B-06A0-4D65-8A55-C9FF8D5BC177}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{650F351B-06A0-4D65-8A55-C9FF8D5BC177}.Debug|Any CPU.Build.0 = Debug|Any CPU
{650F351B-06A0-4D65-8A55-C9FF8D5BC177}.Debug|x64.ActiveCfg = Debug|Any CPU
{650F351B-06A0-4D65-8A55-C9FF8D5BC177}.Debug|x64.Build.0 = Debug|Any CPU
{650F351B-06A0-4D65-8A55-C9FF8D5BC177}.Debug|x86.ActiveCfg = Debug|Any CPU
{650F351B-06A0-4D65-8A55-C9FF8D5BC177}.Debug|x86.Build.0 = Debug|Any CPU
{650F351B-06A0-4D65-8A55-C9FF8D5BC177}.Release|Any CPU.ActiveCfg = Release|Any CPU
{650F351B-06A0-4D65-8A55-C9FF8D5BC177}.Release|Any CPU.Build.0 = Release|Any CPU
{650F351B-06A0-4D65-8A55-C9FF8D5BC177}.Release|x64.ActiveCfg = Release|Any CPU
{650F351B-06A0-4D65-8A55-C9FF8D5BC177}.Release|x64.Build.0 = Release|Any CPU
{650F351B-06A0-4D65-8A55-C9FF8D5BC177}.Release|x86.ActiveCfg = Release|Any CPU
{650F351B-06A0-4D65-8A55-C9FF8D5BC177}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ builder.Services.Replace(ServiceDescriptor.Scoped<IJsonSerializer, MySerializer>
You can find an example of this in the Blazor Server sample project. The standard serializer has been replaced with a new serializer which uses NewtonsoftJson.

## Testing with bUnit
This library provides test extensions for use with the [bUnit testing library](https://bunit.dev/). Using these test extensions will provide an in memory implementation which mimics local storage allowing more realistic testing of your components.
The `Blazored.LocalStorage.TestExtensions` library provides test extensions for use with the [bUnit testing library](https://bunit.dev/). Using these test extensions will provide an in memory implementation which mimics local storage allowing more realistic testing of your components.

Below is an example test which uses these extensions. You can find an example project which shows this code in action in the samples folder.

Expand Down
3 changes: 2 additions & 1 deletion samples/bUnitExample/bUnitExample.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
Expand All @@ -20,6 +20,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Blazored.LocalStorage.TestExtensions\Blazored.LocalStorage.TestExtensions.csproj" />
<ProjectReference Include="..\BlazorWebAssembly\BlazorWebAssembly.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Blazored.LocalStorage;
using Blazored.LocalStorage.JsonConverters;
using Blazored.LocalStorage.Serialization;
using Blazored.LocalStorage.StorageOptions;
using Blazored.LocalStorage.TestExtensions;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Diagnostics.CodeAnalysis;
using Blazored.LocalStorage;
using Blazored.LocalStorage.Testing;

namespace Bunit
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;net5.0</TargetFrameworks>

<Authors>Chris Sainty</Authors>
<Company></Company>
<Copyright>Copyright 2020 (c) Chris Sainty. All rights reserved.</Copyright>
<Description>A testing library to provide helper extensions for Blazored.LocalStorage</Description>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>

<!-- NuGet settings -->
<PackageId>Blazored.LocalStorage.TestExtensions</PackageId>
<PackageTags>Blazored;Blazor;Razor;Components;LocalStorage;Local Storage;ASP.NET Core;CSharp;Web</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/Blazored/LocalStorage</PackageProjectUrl>
<PackageIcon>icon.png</PackageIcon>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/Blazored/LocalStorage</RepositoryUrl>

<!-- SourceLink settings -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\src\Blazored.LocalStorage\Blazored.LocalStorage.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\src\Blazored.LocalStorage\icon.png" Pack="true" PackagePath="\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="bunit.core" Version="1.1.5" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Blazored.LocalStorage\Blazored.LocalStorage.csproj" />
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>
Blazored.LocalStorage.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e94102d6760ebcff1970798791888ddf102ac709e19db9a312721fafca42b894652b59bada7d592a4ab62a5b76507a27720e922bc310c4f5aa75acd8ab59632c920ac41a7e9abcaf4b8bb5525a60931faccea704dbdcf68e1207616751447dcfec687f18854148aa66a9a09e1edc8fd0c9bd11950b4baf7d46fe38993af4add4
</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<None Include="..\Blazored.LocalStorage\Blazored.LocalStorage.snk" Link="Blazored.LocalStorage.snk" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace Blazored.LocalStorage.Testing
namespace Blazored.LocalStorage.TestExtensions
{
internal class InMemoryStorageProvider : IStorageProvider
{
Expand Down
14 changes: 13 additions & 1 deletion src/Blazored.LocalStorage/Blazored.LocalStorage.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,19 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="bunit.core" Version="1.1.5" />
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>
Blazored.LocalStorage.TestExtensions, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e94102d6760ebcff1970798791888ddf102ac709e19db9a312721fafca42b894652b59bada7d592a4ab62a5b76507a27720e922bc310c4f5aa75acd8ab59632c920ac41a7e9abcaf4b8bb5525a60931faccea704dbdcf68e1207616751447dcfec687f18854148aa66a9a09e1edc8fd0c9bd11950b4baf7d46fe38993af4add4
</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>
Blazored.LocalStorage.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e94102d6760ebcff1970798791888ddf102ac709e19db9a312721fafca42b894652b59bada7d592a4ab62a5b76507a27720e922bc310c4f5aa75acd8ab59632c920ac41a7e9abcaf4b8bb5525a60931faccea704dbdcf68e1207616751447dcfec687f18854148aa66a9a09e1edc8fd0c9bd11950b4baf7d46fe38993af4add4
</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
using Blazored.LocalStorage.StorageOptions;
using Blazored.LocalStorage.StorageOptions;
using Microsoft.Extensions.Options;
using System.Runtime.CompilerServices;
using System.Text.Json;

[assembly: InternalsVisibleTo("Blazored.LocalStorage.Tests, PublicKey=" +
"0024000004800000940000000602000000240000525341310004000001000100e94102d6760ebc" +
"ff1970798791888ddf102ac709e19db9a312721fafca42b894652b59bada7d592a4ab62a5b7650" +
"7a27720e922bc310c4f5aa75acd8ab59632c920ac41a7e9abcaf4b8bb5525a60931faccea704db" +
"dcf68e1207616751447dcfec687f18854148aa66a9a09e1edc8fd0c9bd11950b4baf7d46fe3899" +
"3af4add4")]
namespace Blazored.LocalStorage.Serialization
{
internal class SystemTextJsonSerializer : IJsonSerializer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
Expand Down Expand Up @@ -27,6 +27,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Blazored.LocalStorage.TestExtensions\Blazored.LocalStorage.TestExtensions.csproj" />
<ProjectReference Include="..\..\src\Blazored.LocalStorage\Blazored.LocalStorage.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using System.Text.Json;
using System.Threading.Tasks;
using Blazored.LocalStorage.JsonConverters;
using Blazored.LocalStorage.Serialization;
using Blazored.LocalStorage.StorageOptions;
using Blazored.LocalStorage.Testing;
using Blazored.LocalStorage.TestExtensions;
using Blazored.LocalStorage.Tests.TestAssets;
using Microsoft.Extensions.Options;
using Moq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Text.Json;
using System.Threading.Tasks;
using Blazored.LocalStorage.JsonConverters;
using Blazored.LocalStorage.Serialization;
using Blazored.LocalStorage.StorageOptions;
using Blazored.LocalStorage.Testing;
using Blazored.LocalStorage.TestExtensions;
using Blazored.LocalStorage.Tests.TestAssets;
using Microsoft.Extensions.Options;
using Moq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using System.Text.Json;
using System.Threading.Tasks;
using Blazored.LocalStorage.JsonConverters;
using Blazored.LocalStorage.Serialization;
using Blazored.LocalStorage.StorageOptions;
using Blazored.LocalStorage.Testing;
using Blazored.LocalStorage.TestExtensions;
using Blazored.LocalStorage.Tests.TestAssets;
using Microsoft.Extensions.Options;
using Moq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Text.Json;
using System.Threading.Tasks;
using Blazored.LocalStorage.JsonConverters;
using Blazored.LocalStorage.Serialization;
using Blazored.LocalStorage.StorageOptions;
using Blazored.LocalStorage.Testing;
using Blazored.LocalStorage.TestExtensions;
using Blazored.LocalStorage.Tests.TestAssets;
using Microsoft.Extensions.Options;
using Moq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System;
using System.Text.Json;
using System.Threading.Tasks;
using Blazored.LocalStorage.JsonConverters;
using Blazored.LocalStorage.Serialization;
using Blazored.LocalStorage.StorageOptions;
using Blazored.LocalStorage.Testing;
using Blazored.LocalStorage.TestExtensions;
using Blazored.LocalStorage.Tests.TestAssets;
using Microsoft.Extensions.Options;
using Moq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System;
using System.Text.Json;
using System.Threading.Tasks;
using Blazored.LocalStorage.JsonConverters;
using Blazored.LocalStorage.Serialization;
using Blazored.LocalStorage.StorageOptions;
using Blazored.LocalStorage.Testing;
using Blazored.LocalStorage.TestExtensions;
using Blazored.LocalStorage.Tests.TestAssets;
using Microsoft.Extensions.Options;
using Moq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Blazored.LocalStorage.JsonConverters;
using Blazored.LocalStorage.Serialization;
using Blazored.LocalStorage.StorageOptions;
using Blazored.LocalStorage.Testing;
using Blazored.LocalStorage.TestExtensions;
using Blazored.LocalStorage.Tests.TestAssets;
using Microsoft.Extensions.Options;
using Moq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Blazored.LocalStorage.JsonConverters;
using Blazored.LocalStorage.Serialization;
using Blazored.LocalStorage.StorageOptions;
using Blazored.LocalStorage.Testing;
using Blazored.LocalStorage.TestExtensions;
using Blazored.LocalStorage.Tests.TestAssets;
using Microsoft.Extensions.Options;
using Moq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using System.Text.Json;
using System.Threading.Tasks;
using Blazored.LocalStorage.JsonConverters;
using Blazored.LocalStorage.Serialization;
using Blazored.LocalStorage.StorageOptions;
using Blazored.LocalStorage.Testing;
using Blazored.LocalStorage.TestExtensions;
using Blazored.LocalStorage.Tests.TestAssets;
using Microsoft.Extensions.Options;
using Moq;
Expand Down
Loading

0 comments on commit 9434db4

Please sign in to comment.