Skip to content
This repository was archived by the owner on Dec 26, 2025. It is now read-only.

Commit 0a1a428

Browse files
authored
Moved test extensions to separate project
2 parents 9aad9bd + fbc31d4 commit 0a1a428

36 files changed

Lines changed: 231 additions & 193 deletions

.github/workflows/ci-main.yml

Lines changed: 27 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ env:
1111
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
1212
DOTNET_CLI_TELEMETRY_OPTOUT: true
1313
PROJECT_NAME: SessionStorage
14-
GITHUB_FEED: https://nuget.pkg.github.com/Blazored/
15-
GITHUB_USER: chrissainty
1614
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1715
NUGET_FEED: https://api.nuget.org/v3/index.json
1816
NUGET_KEY: ${{ secrets.NUGET_KEY }}
@@ -38,60 +36,24 @@ jobs:
3836
- name: Build
3937
run: dotnet build -c Release --no-restore src/Blazored.$PROJECT_NAME/Blazored.$PROJECT_NAME.csproj
4038

41-
- name: Test
42-
run: dotnet test -c Release
39+
- name: Build Test Extensions
40+
run: dotnet build -c Release --no-restore src/Blazored.$PROJECT_NAME.TestExtensions/Blazored.$PROJECT_NAME.TestExtensions.csproj
4341

44-
- name: Pack
45-
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
42+
- name: Test Local Storage
43+
run: dotnet test -c Release --no-restore --verbosity normal tests/Blazored.$PROJECT_NAME.Tests
4644

47-
- name: Publish Sample Site
48-
run: dotnet publish -c Release samples/BlazorWebAssembly/BlazorWebAssembly.csproj
49-
50-
- name: Rewrite base href
51-
uses: SteveSandersonMS/ghaction-rewrite-base-href@v1
52-
with:
53-
html_path: samples/BlazorWebAssembly/bin/Release/net5.0/publish/wwwroot/index.html
54-
base_href: /${{ env.PROJECT_NAME }}/
55-
56-
- name: Deploy to Github Pages
57-
uses: JamesIves/github-pages-deploy-action@releases/v3
58-
with:
59-
ACCESS_TOKEN: $GITHUB_TOKEN
60-
BASE_BRANCH: main # The branch the action should deploy from.
61-
BRANCH: gh-pages # The branch the action should deploy to.
62-
FOLDER: samples/BlazorWebAssembly/bin/Release/net5.0/publish/wwwroot # The folder the action should deploy.
63-
SINGLE_COMMIT: true
64-
65-
- name: Upload Artifact
66-
uses: actions/upload-artifact@v2
67-
with:
68-
name: nupkg
69-
path: ./src/Blazored.${{ env.PROJECT_NAME }}/bin/Release/*.nupkg
70-
prerelease:
71-
needs: build
72-
if: github.event_name != 'release'
73-
runs-on: ubuntu-latest
74-
steps:
75-
- name: Download Artifact
76-
uses: actions/download-artifact@v1
77-
with:
78-
name: nupkg
79-
- name: Push to GitHub Feed
80-
run: |
81-
for f in ./nupkg/*.nupkg
82-
do
83-
curl -vX PUT -u "$GITHUB_USER:$GITHUB_TOKEN" -F package=@$f $GITHUB_FEED
84-
done
8545
deploy:
8646
needs: build
8747
if: github.event_name == 'release'
8848
runs-on: ubuntu-latest
8949
steps:
9050
- uses: actions/checkout@v2
51+
9152
- name: Setup .NET Core
9253
uses: actions/setup-dotnet@v1
9354
with:
9455
dotnet-version: ${{ env.NETCORE_VERSION }}
56+
9557
- name: Create Release NuGet package
9658
run: |
9759
arrTag=(${GITHUB_REF//\// })
@@ -100,11 +62,25 @@ jobs:
10062
VERSION="${VERSION//v}"
10163
echo Clean Version: $VERSION
10264
dotnet pack -v normal -c Release --include-symbols --include-source -p:PackageVersion=$VERSION -o nupkg src/Blazored.$PROJECT_NAME/Blazored.$PROJECT_NAME.*proj
103-
- name: Push to GitHub Feed
104-
run: |
105-
for f in ./nupkg/*.nupkg
106-
do
107-
curl -vX PUT -u "$GITHUB_USER:$GITHUB_TOKEN" -F package=@$f $GITHUB_FEED
108-
done
65+
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
66+
10967
- name: Push to NuGet Feed
110-
run: dotnet nuget push ./nupkg/*.nupkg --source $NUGET_FEED --skip-duplicate --api-key $NUGET_KEY
68+
run: dotnet nuget push ./nupkg/*.nupkg --source $NUGET_FEED --api-key $NUGET_KEY --skip-duplicate
69+
70+
- name: Publish Sample Site
71+
run: dotnet publish -c Release samples/BlazorWebAssembly/BlazorWebAssembly.csproj
72+
73+
- name: Rewrite base href
74+
uses: SteveSandersonMS/ghaction-rewrite-base-href@v1
75+
with:
76+
html_path: samples/BlazorWebAssembly/bin/Release/net5.0/publish/wwwroot/index.html
77+
base_href: /${{ env.PROJECT_NAME }}/
78+
79+
- name: Deploy to Github Pages
80+
uses: JamesIves/github-pages-deploy-action@releases/v3
81+
with:
82+
ACCESS_TOKEN: $GITHUB_TOKEN
83+
BASE_BRANCH: main # The branch the action should deploy from.
84+
BRANCH: gh-pages # The branch the action should deploy to.
85+
FOLDER: samples/BlazorWebAssembly/bin/Release/net5.0/publish/wwwroot # The folder the action should deploy.
86+
SINGLE_COMMIT: true

.github/workflows/ci-pr.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
branches: [ main ]
66

77
env:
8-
NETCORE_VERSION: '5.0.202'
8+
NETCORE_VERSION: '5.0.x'
99
PROJECT_NAME: Blazored.SessionStorage
1010

1111
jobs:
@@ -23,8 +23,11 @@ jobs:
2323
- name: Restoring packages...
2424
run: dotnet restore
2525

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

29+
- name: Build Session Storage Test Extensions
30+
run: dotnet build -c Release --no-restore src/$PROJECT_NAME.TestExtensions/$PROJECT_NAME.TestExtensions.csproj
31+
2932
- name: Testing...
30-
run: dotnet test --no-restore --verbosity normal
33+
run: dotnet test -c Release --no-restore --verbosity normal tests/$PROJECT_NAME.Tests

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ PublishScripts/
179179

180180
# NuGet Packages
181181
*.nupkg
182+
*.snupkg
183+
182184
# The packages folder can be ignored because of Package Restore
183185
**/[Pp]ackages/*
184186
# except build/, which is used as an MSBuild target.

Blazored.SessionStorage.sln

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.28531.58
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31717.71
55
MinimumVisualStudioVersion = 15.0.26124.0
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazored.SessionStorage", "src\Blazored.SessionStorage\Blazored.SessionStorage.csproj", "{EFA12DC3-35DE-449C-88F2-2BD7576CAF2C}"
77
EndProject
@@ -13,6 +13,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorServer", "samples\Bla
1313
EndProject
1414
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9170D7A9-70CE-48E3-88A3-F11D2983103E}"
1515
ProjectSection(SolutionItems) = preProject
16+
.gitignore = .gitignore
1617
.github\workflows\ci-main.yml = .github\workflows\ci-main.yml
1718
.github\workflows\ci-pr.yml = .github\workflows\ci-pr.yml
1819
README.md = README.md
@@ -23,7 +24,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{B82A5126
2324
EndProject
2425
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazored.SessionStorage.Tests", "tests\Blazored.SessionStorage.Tests\Blazored.SessionStorage.Tests.csproj", "{5A6A013E-325D-4A5F-B2FA-659B4FD2BDBC}"
2526
EndProject
26-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bUnitExample", "samples\bUnitExample\bUnitExample.csproj", "{10F6FB83-3135-4B73-B0EB-D008A31AE8FA}"
27+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "bUnitExample", "samples\bUnitExample\bUnitExample.csproj", "{10F6FB83-3135-4B73-B0EB-D008A31AE8FA}"
28+
EndProject
29+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazored.SessionStorage.TestExtensions", "src\Blazored.SessionStorage.TestExtensions\Blazored.SessionStorage.TestExtensions.csproj", "{528AE63D-0043-4A63-9151-92107397EE02}"
2730
EndProject
2831
Global
2932
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -95,6 +98,18 @@ Global
9598
{10F6FB83-3135-4B73-B0EB-D008A31AE8FA}.Release|x64.Build.0 = Release|Any CPU
9699
{10F6FB83-3135-4B73-B0EB-D008A31AE8FA}.Release|x86.ActiveCfg = Release|Any CPU
97100
{10F6FB83-3135-4B73-B0EB-D008A31AE8FA}.Release|x86.Build.0 = Release|Any CPU
101+
{528AE63D-0043-4A63-9151-92107397EE02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
102+
{528AE63D-0043-4A63-9151-92107397EE02}.Debug|Any CPU.Build.0 = Debug|Any CPU
103+
{528AE63D-0043-4A63-9151-92107397EE02}.Debug|x64.ActiveCfg = Debug|Any CPU
104+
{528AE63D-0043-4A63-9151-92107397EE02}.Debug|x64.Build.0 = Debug|Any CPU
105+
{528AE63D-0043-4A63-9151-92107397EE02}.Debug|x86.ActiveCfg = Debug|Any CPU
106+
{528AE63D-0043-4A63-9151-92107397EE02}.Debug|x86.Build.0 = Debug|Any CPU
107+
{528AE63D-0043-4A63-9151-92107397EE02}.Release|Any CPU.ActiveCfg = Release|Any CPU
108+
{528AE63D-0043-4A63-9151-92107397EE02}.Release|Any CPU.Build.0 = Release|Any CPU
109+
{528AE63D-0043-4A63-9151-92107397EE02}.Release|x64.ActiveCfg = Release|Any CPU
110+
{528AE63D-0043-4A63-9151-92107397EE02}.Release|x64.Build.0 = Release|Any CPU
111+
{528AE63D-0043-4A63-9151-92107397EE02}.Release|x86.ActiveCfg = Release|Any CPU
112+
{528AE63D-0043-4A63-9151-92107397EE02}.Release|x86.Build.0 = Release|Any CPU
98113
EndGlobalSection
99114
GlobalSection(SolutionProperties) = preSolution
100115
HideSolutionNode = FALSE

samples/bUnitExample/bUnitExample.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="bunit.core" Version="1.1.5" />
9-
<PackageReference Include="bunit.web" Version="1.1.5" />
8+
<PackageReference Include="bunit.web" Version="1.2.49" />
109
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
1110
<PackageReference Include="xunit" Version="2.4.1" />
1211
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
@@ -20,6 +19,7 @@
2019
</ItemGroup>
2120

2221
<ItemGroup>
22+
<ProjectReference Include="..\..\src\Blazored.SessionStorage.TestExtensions\Blazored.SessionStorage.TestExtensions.csproj" />
2323
<ProjectReference Include="..\BlazorWebAssembly\BlazorWebAssembly.csproj" />
2424
</ItemGroup>
2525

src/Blazored.SessionStorage/Testing/BUnitLocalStorageTestExtensions.cs renamed to src/Blazored.SessionStorage.TestExtensions/BUnitSessionStorageTestExtensions.cs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,34 @@
1+
using System;
2+
using System.Diagnostics.CodeAnalysis;
3+
using Blazored.SessionStorage;
14
using Blazored.SessionStorage.JsonConverters;
25
using Blazored.SessionStorage.Serialization;
36
using Blazored.SessionStorage.StorageOptions;
7+
using Blazored.SessionStorage.TestExtensions;
48
using Microsoft.Extensions.DependencyInjection;
5-
using System;
6-
using System.Diagnostics.CodeAnalysis;
7-
using Blazored.SessionStorage;
8-
using Blazored.SessionStorage.Testing;
99

1010
namespace Bunit
1111
{
1212
[ExcludeFromCodeCoverage]
1313
public static class BUnitSessionStorageTestExtensions
14+
1415
{
1516
public static ISessionStorageService AddBlazoredSessionStorage(this TestContextBase context)
1617
=> AddBlazoredSessionStorage(context, null);
1718

1819
public static ISessionStorageService AddBlazoredSessionStorage(this TestContextBase context, Action<SessionStorageOptions> configure)
1920
{
2021
if (context is null)
21-
throw new ArgumentNullException(nameof(context));
22+
throw new ArgumentNullException(nameof(context));
23+
24+
var sessionStorageOptions = new SessionStorageOptions();
25+
configure?.Invoke(sessionStorageOptions);
26+
sessionStorageOptions.JsonSerializerOptions.Converters.Add(new TimespanJsonConverter());
2227

23-
context.Services
24-
.AddSingleton<IJsonSerializer, SystemTextJsonSerializer>()
25-
.AddSingleton<IStorageProvider, InMemoryStorageProvider>()
26-
.AddSingleton<ISessionStorageService, SessionStorageService>()
27-
.AddSingleton<ISyncSessionStorageService, SessionStorageService>()
28-
.Configure<SessionStorageOptions>(configureOptions =>
29-
{
30-
configure?.Invoke(configureOptions);
31-
configureOptions.JsonSerializerOptions.Converters.Add(new TimespanJsonConverter());
32-
});
28+
var localStorageService = new SessionStorageService(new InMemoryStorageProvider(), new SystemTextJsonSerializer(sessionStorageOptions));
29+
context.Services.AddSingleton<ISessionStorageService>(localStorageService);
3330

34-
return context.Services.GetService<ISessionStorageService>();
31+
return localStorageService;
3532
}
3633
}
3734
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>netstandard2.1;net5.0</TargetFrameworks>
5+
6+
<Authors>Chris Sainty</Authors>
7+
<Company></Company>
8+
<Copyright>Copyright 2020 (c) Chris Sainty. All rights reserved.</Copyright>
9+
<Description>A testing library to provide helper extensions for Blazored.SessionStorage</Description>
10+
<IncludeSymbols>true</IncludeSymbols>
11+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
12+
13+
<!-- NuGet settings -->
14+
<PackageId>Blazored.SessionStorage.TestExtensions</PackageId>
15+
<PackageTags>Blazored;Blazor;Razor;Components;SessionStorage;Session Storage;ASP.NET Core;CSharp;Web</PackageTags>
16+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
17+
<PackageProjectUrl>https://github.com/Blazored/SessionStorage</PackageProjectUrl>
18+
<PackageIcon>icon.png</PackageIcon>
19+
<RepositoryType>git</RepositoryType>
20+
<RepositoryUrl>https://github.com/Blazored/SessionStorage</RepositoryUrl>
21+
22+
<!-- SourceLink settings -->
23+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
24+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
25+
<SignAssembly>true</SignAssembly>
26+
<AssemblyOriginatorKeyFile>Blazored.SessionStorage.snk</AssemblyOriginatorKeyFile>
27+
</PropertyGroup>
28+
29+
<ItemGroup>
30+
<None Include="..\Blazored.SessionStorage\icon.png" Pack="true" PackagePath="\" />
31+
</ItemGroup>
32+
33+
<ItemGroup>
34+
<PackageReference Include="bunit.core" Version="1.2.49" />
35+
</ItemGroup>
36+
37+
<ItemGroup>
38+
<ProjectReference Include="..\Blazored.SessionStorage\Blazored.SessionStorage.csproj" />
39+
</ItemGroup>
40+
41+
<ItemGroup>
42+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
43+
<_Parameter1>
44+
Blazored.SessionStorage.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001007527e122cc36dc13c695a4f43b7c2da3f631aed456ed309140c0d52262323e25d84bef7feddc8bd29cfe46ec652186cb10e059eedabf2ff000b977a2376a613dccfb092de6c243e0888db4c66a084124b2c1799bda4bbb2f70fed0382fc1cbdafa6dc0f4baccdc2cee55234f8a5ad76645c315523fee5352d9f01036e48b13e3
45+
</_Parameter1>
46+
</AssemblyAttribute>
47+
</ItemGroup>
48+
49+
<ItemGroup>
50+
<None Include="..\Blazored.SessionStorage\Blazored.SessionStorage.snk" Link="Blazored.SessionStorage.snk" />
51+
</ItemGroup>
52+
53+
</Project>
Binary file not shown.

src/Blazored.SessionStorage/Testing/InMemoryStorageProvider.cs renamed to src/Blazored.SessionStorage.TestExtensions/InMemoryStorageProvider.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using System;
21
using System.Collections.Generic;
32
using System.Linq;
3+
using System.Threading;
44
using System.Threading.Tasks;
55

6-
namespace Blazored.SessionStorage.Testing
6+
namespace Blazored.SessionStorage.TestExtensions
77
{
88
internal class InMemoryStorageProvider : IStorageProvider
99
{
@@ -12,7 +12,7 @@ internal class InMemoryStorageProvider : IStorageProvider
1212
public void Clear()
1313
=> _dataStore.Clear();
1414

15-
public ValueTask ClearAsync()
15+
public ValueTask ClearAsync(CancellationToken? cancellationToken = null)
1616
{
1717
_dataStore.Clear();
1818
return new ValueTask(Task.CompletedTask);
@@ -21,31 +21,31 @@ public ValueTask ClearAsync()
2121
public bool ContainKey(string key)
2222
=> _dataStore.ContainsKey(key);
2323

24-
public ValueTask<bool> ContainKeyAsync(string key)
24+
public ValueTask<bool> ContainKeyAsync(string key, CancellationToken? cancellationToken = null)
2525
=> new ValueTask<bool>(ContainKey(key));
2626

27-
public string GetItem(string key)
27+
public string GetItem(string key)
2828
=> _dataStore.ContainsKey(key) ? _dataStore[key] : default;
2929

30-
public ValueTask<string> GetItemAsync(string key)
30+
public ValueTask<string> GetItemAsync(string key, CancellationToken? cancellationToken = null)
3131
=> new ValueTask<string>(GetItem(key));
3232

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

36-
public ValueTask<string> KeyAsync(int index)
36+
public ValueTask<string> KeyAsync(int index, CancellationToken? cancellationToken = null)
3737
=> new ValueTask<string>(Key(index));
3838

3939
public int Length()
4040
=> _dataStore.Count;
4141

42-
public ValueTask<int> LengthAsync()
42+
public ValueTask<int> LengthAsync(CancellationToken? cancellationToken = null)
4343
=> new ValueTask<int>(Length());
4444

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

48-
public ValueTask RemoveItemAsync(string key)
48+
public ValueTask RemoveItemAsync(string key, CancellationToken? cancellationToken = null)
4949
{
5050
RemoveItem(key);
5151
return new ValueTask(Task.CompletedTask);
@@ -63,7 +63,7 @@ public void SetItem(string key, string data)
6363
}
6464
}
6565

66-
public ValueTask SetItemAsync(string key, string data)
66+
public ValueTask SetItemAsync(string key, string data, CancellationToken? cancellationToken = null)
6767
{
6868
SetItem(key, data);
6969
return new ValueTask(Task.CompletedTask);

0 commit comments

Comments
 (0)