Skip to content

Commit

Permalink
Moved test extensions to separate project
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissainty authored Oct 8, 2021
2 parents 9aad9bd + fbc31d4 commit 0a1a428
Show file tree
Hide file tree
Showing 36 changed files with 231 additions and 193 deletions.
78 changes: 27 additions & 51 deletions .github/workflows/ci-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
PROJECT_NAME: SessionStorage
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 }}
Expand All @@ -38,60 +36,24 @@ jobs:
- name: Build
run: dotnet build -c Release --no-restore src/Blazored.$PROJECT_NAME/Blazored.$PROJECT_NAME.csproj

- name: Test
run: dotnet test -c Release
- name: Build Test Extensions
run: dotnet build -c Release --no-restore src/Blazored.$PROJECT_NAME.TestExtensions/Blazored.$PROJECT_NAME.TestExtensions.csproj

- 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: Test Local Storage
run: dotnet test -c Release --no-restore --verbosity normal tests/Blazored.$PROJECT_NAME.Tests

- name: Publish Sample Site
run: dotnet publish -c Release samples/BlazorWebAssembly/BlazorWebAssembly.csproj

- name: Rewrite base href
uses: SteveSandersonMS/ghaction-rewrite-base-href@v1
with:
html_path: samples/BlazorWebAssembly/bin/Release/net5.0/publish/wwwroot/index.html
base_href: /${{ env.PROJECT_NAME }}/

- name: Deploy to Github Pages
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
ACCESS_TOKEN: $GITHUB_TOKEN
BASE_BRANCH: main # The branch the action should deploy from.
BRANCH: gh-pages # The branch the action should deploy to.
FOLDER: samples/BlazorWebAssembly/bin/Release/net5.0/publish/wwwroot # The folder the action should deploy.
SINGLE_COMMIT: true

- name: Upload Artifact
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//\// })
Expand All @@ -100,11 +62,25 @@ jobs:
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
dotnet pack -v normal -c Release --include-symbols --include-source -p:PackageVersion=$VERSION -o nupkg src/Blazored.$PROJECT_NAME.TestExtensions/Blazored.$PROJECT_NAME.TestExtensions.csproj
- name: Push to NuGet Feed
run: dotnet nuget push ./nupkg/*.nupkg --source $NUGET_FEED --skip-duplicate --api-key $NUGET_KEY
run: dotnet nuget push ./nupkg/*.nupkg --source $NUGET_FEED --api-key $NUGET_KEY --skip-duplicate

- name: Publish Sample Site
run: dotnet publish -c Release samples/BlazorWebAssembly/BlazorWebAssembly.csproj

- name: Rewrite base href
uses: SteveSandersonMS/ghaction-rewrite-base-href@v1
with:
html_path: samples/BlazorWebAssembly/bin/Release/net5.0/publish/wwwroot/index.html
base_href: /${{ env.PROJECT_NAME }}/

- name: Deploy to Github Pages
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
ACCESS_TOKEN: $GITHUB_TOKEN
BASE_BRANCH: main # The branch the action should deploy from.
BRANCH: gh-pages # The branch the action should deploy to.
FOLDER: samples/BlazorWebAssembly/bin/Release/net5.0/publish/wwwroot # The folder the action should deploy.
SINGLE_COMMIT: true
9 changes: 6 additions & 3 deletions .github/workflows/ci-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches: [ main ]

env:
NETCORE_VERSION: '5.0.202'
NETCORE_VERSION: '5.0.x'
PROJECT_NAME: Blazored.SessionStorage

jobs:
Expand All @@ -23,8 +23,11 @@ jobs:
- name: Restoring packages...
run: dotnet restore

- name: Building project...
- name: Building Session Storage...
run: dotnet build --configuration Release --no-restore src/$PROJECT_NAME/$PROJECT_NAME.csproj

- name: Build Session Storage Test Extensions
run: dotnet build -c Release --no-restore src/$PROJECT_NAME.TestExtensions/$PROJECT_NAME.TestExtensions.csproj

- name: Testing...
run: dotnet test --no-restore --verbosity normal
run: dotnet test -c Release --no-restore --verbosity normal tests/$PROJECT_NAME.Tests
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ 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
21 changes: 18 additions & 3 deletions Blazored.SessionStorage.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28531.58
# Visual Studio Version 17
VisualStudioVersion = 17.0.31717.71
MinimumVisualStudioVersion = 15.0.26124.0
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazored.SessionStorage", "src\Blazored.SessionStorage\Blazored.SessionStorage.csproj", "{EFA12DC3-35DE-449C-88F2-2BD7576CAF2C}"
EndProject
Expand All @@ -13,6 +13,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorServer", "samples\Bla
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9170D7A9-70CE-48E3-88A3-F11D2983103E}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
.github\workflows\ci-main.yml = .github\workflows\ci-main.yml
.github\workflows\ci-pr.yml = .github\workflows\ci-pr.yml
README.md = README.md
Expand All @@ -23,7 +24,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{B82A5126
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazored.SessionStorage.Tests", "tests\Blazored.SessionStorage.Tests\Blazored.SessionStorage.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.SessionStorage.TestExtensions", "src\Blazored.SessionStorage.TestExtensions\Blazored.SessionStorage.TestExtensions.csproj", "{528AE63D-0043-4A63-9151-92107397EE02}"
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
{528AE63D-0043-4A63-9151-92107397EE02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{528AE63D-0043-4A63-9151-92107397EE02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{528AE63D-0043-4A63-9151-92107397EE02}.Debug|x64.ActiveCfg = Debug|Any CPU
{528AE63D-0043-4A63-9151-92107397EE02}.Debug|x64.Build.0 = Debug|Any CPU
{528AE63D-0043-4A63-9151-92107397EE02}.Debug|x86.ActiveCfg = Debug|Any CPU
{528AE63D-0043-4A63-9151-92107397EE02}.Debug|x86.Build.0 = Debug|Any CPU
{528AE63D-0043-4A63-9151-92107397EE02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{528AE63D-0043-4A63-9151-92107397EE02}.Release|Any CPU.Build.0 = Release|Any CPU
{528AE63D-0043-4A63-9151-92107397EE02}.Release|x64.ActiveCfg = Release|Any CPU
{528AE63D-0043-4A63-9151-92107397EE02}.Release|x64.Build.0 = Release|Any CPU
{528AE63D-0043-4A63-9151-92107397EE02}.Release|x86.ActiveCfg = Release|Any CPU
{528AE63D-0043-4A63-9151-92107397EE02}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 2 additions & 2 deletions samples/bUnitExample/bUnitExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="bunit.core" Version="1.1.5" />
<PackageReference Include="bunit.web" Version="1.1.5" />
<PackageReference Include="bunit.web" Version="1.2.49" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
Expand All @@ -20,6 +19,7 @@
</ItemGroup>

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

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

namespace Bunit
{
[ExcludeFromCodeCoverage]
public static class BUnitSessionStorageTestExtensions

{
public static ISessionStorageService AddBlazoredSessionStorage(this TestContextBase context)
=> AddBlazoredSessionStorage(context, null);

public static ISessionStorageService AddBlazoredSessionStorage(this TestContextBase context, Action<SessionStorageOptions> configure)
{
if (context is null)
throw new ArgumentNullException(nameof(context));
throw new ArgumentNullException(nameof(context));

var sessionStorageOptions = new SessionStorageOptions();
configure?.Invoke(sessionStorageOptions);
sessionStorageOptions.JsonSerializerOptions.Converters.Add(new TimespanJsonConverter());

context.Services
.AddSingleton<IJsonSerializer, SystemTextJsonSerializer>()
.AddSingleton<IStorageProvider, InMemoryStorageProvider>()
.AddSingleton<ISessionStorageService, SessionStorageService>()
.AddSingleton<ISyncSessionStorageService, SessionStorageService>()
.Configure<SessionStorageOptions>(configureOptions =>
{
configure?.Invoke(configureOptions);
configureOptions.JsonSerializerOptions.Converters.Add(new TimespanJsonConverter());
});
var localStorageService = new SessionStorageService(new InMemoryStorageProvider(), new SystemTextJsonSerializer(sessionStorageOptions));
context.Services.AddSingleton<ISessionStorageService>(localStorageService);

return context.Services.GetService<ISessionStorageService>();
return localStorageService;
}
}
}
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.SessionStorage</Description>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>

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

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

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

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

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

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>
Blazored.SessionStorage.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001007527e122cc36dc13c695a4f43b7c2da3f631aed456ed309140c0d52262323e25d84bef7feddc8bd29cfe46ec652186cb10e059eedabf2ff000b977a2376a613dccfb092de6c243e0888db4c66a084124b2c1799bda4bbb2f70fed0382fc1cbdafa6dc0f4baccdc2cee55234f8a5ad76645c315523fee5352d9f01036e48b13e3
</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

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

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

namespace Blazored.SessionStorage.Testing
namespace Blazored.SessionStorage.TestExtensions
{
internal class InMemoryStorageProvider : IStorageProvider
{
Expand All @@ -12,7 +12,7 @@ internal class InMemoryStorageProvider : IStorageProvider
public void Clear()
=> _dataStore.Clear();

public ValueTask ClearAsync()
public ValueTask ClearAsync(CancellationToken? cancellationToken = null)
{
_dataStore.Clear();
return new ValueTask(Task.CompletedTask);
Expand All @@ -21,31 +21,31 @@ public ValueTask ClearAsync()
public bool ContainKey(string key)
=> _dataStore.ContainsKey(key);

public ValueTask<bool> ContainKeyAsync(string key)
public ValueTask<bool> ContainKeyAsync(string key, CancellationToken? cancellationToken = null)
=> new ValueTask<bool>(ContainKey(key));

public string GetItem(string key)
public string GetItem(string key)
=> _dataStore.ContainsKey(key) ? _dataStore[key] : default;

public ValueTask<string> GetItemAsync(string key)
public ValueTask<string> GetItemAsync(string key, CancellationToken? cancellationToken = null)
=> new ValueTask<string>(GetItem(key));

public string Key(int index)
=> index > _dataStore.Count - 1 ? default : _dataStore.ElementAt(index).Key;

public ValueTask<string> KeyAsync(int index)
public ValueTask<string> KeyAsync(int index, CancellationToken? cancellationToken = null)
=> new ValueTask<string>(Key(index));

public int Length()
=> _dataStore.Count;

public ValueTask<int> LengthAsync()
public ValueTask<int> LengthAsync(CancellationToken? cancellationToken = null)
=> new ValueTask<int>(Length());

public void RemoveItem(string key)
=> _dataStore.Remove(key);

public ValueTask RemoveItemAsync(string key)
public ValueTask RemoveItemAsync(string key, CancellationToken? cancellationToken = null)
{
RemoveItem(key);
return new ValueTask(Task.CompletedTask);
Expand All @@ -63,7 +63,7 @@ public void SetItem(string key, string data)
}
}

public ValueTask SetItemAsync(string key, string data)
public ValueTask SetItemAsync(string key, string data, CancellationToken? cancellationToken = null)
{
SetItem(key, data);
return new ValueTask(Task.CompletedTask);
Expand Down
Loading

0 comments on commit 0a1a428

Please sign in to comment.