Skip to content

Commit 82fde2e

Browse files
committed
Initial Commit.
1 parent dd404a9 commit 82fde2e

13 files changed

Lines changed: 384 additions & 12 deletions

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
ko_fi: tensiondev

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "nuget" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "monthly"

.github/workflows/dotnet.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: .NET
2+
3+
on:
4+
push:
5+
branches: [ "**" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: windows-latest
13+
14+
strategy:
15+
matrix:
16+
dotnet: [ '8.0.x' ]
17+
name: .NET ${{ matrix.dotnet }}
18+
19+
steps:
20+
- name: Set up JDK 17
21+
uses: actions/setup-java@v4
22+
with:
23+
java-version: 17
24+
distribution: 'zulu' # Alternative distribution options are available.
25+
- uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
28+
- name: Setup .NET
29+
uses: actions/setup-dotnet@v4
30+
with:
31+
dotnet-version: ${{ matrix.dotnet }}
32+
- name: Cache SonarQube Cloud packages
33+
uses: actions/cache@v4
34+
with:
35+
path: ~\sonar\cache
36+
key: ${{ runner.os }}-sonar
37+
restore-keys: ${{ runner.os }}-sonar
38+
- name: Cache SonarQube Cloud scanner
39+
id: cache-sonar-scanner
40+
uses: actions/cache@v4
41+
with:
42+
path: .\.sonar\scanner
43+
key: ${{ runner.os }}-sonar-scanner
44+
restore-keys: ${{ runner.os }}-sonar-scanner
45+
- name: Install SonarQube Cloud scanner
46+
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
47+
shell: powershell
48+
run: |
49+
New-Item -Path .\.sonar\scanner -ItemType Directory
50+
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
51+
- name: Restore dependencies
52+
run: dotnet restore
53+
- name: SonarCloudPrepare
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
56+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
57+
run: .\.sonar\scanner\dotnet-sonarscanner begin /k:"TensionDev_UUID.Serialization.SystemTextJson" /o:"tensiondev" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.scanner.scanAll=false /d:sonar.cs.opencover.reportsPaths=**/coverage.opencover.xml
58+
- name: Build
59+
run: dotnet build --no-restore
60+
- name: Test
61+
run: dotnet test --no-build --verbosity normal --collect "XPlat Code Coverage;Format=opencover"
62+
- name: SonarCloudAnalyze
63+
env:
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
65+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
66+
run: .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
67+
68+
test:
69+
70+
strategy:
71+
matrix:
72+
dotnet: [ '8.0.x' ]
73+
os: [macos-latest, ubuntu-latest, windows-latest]
74+
75+
runs-on: ${{ matrix.os }}
76+
77+
name: .NET ${{ matrix.dotnet }} on ${{ matrix.os }}
78+
79+
steps:
80+
- uses: actions/checkout@v4
81+
with:
82+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
83+
- name: Setup .NET
84+
uses: actions/setup-dotnet@v4
85+
with:
86+
dotnet-version: ${{ matrix.dotnet }}
87+
- name: Restore dependencies
88+
run: dotnet restore
89+
- name: Build
90+
run: dotnet build --no-restore
91+
- name: Test
92+
run: dotnet test --no-build --verbosity normal --collect "XPlat Code Coverage;Format=opencover"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: Package Release
4+
5+
# Controls when the workflow will run
6+
on:
7+
# Triggers the workflow on push events but only for the tags
8+
push:
9+
tags:
10+
- v[0-9]+.[0-9]+.[0-9]+
11+
- v[0-9]+.[0-9]+.[0-9]+-alpha
12+
- v[0-9]+.[0-9]+.[0-9]+-beta
13+
14+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
15+
jobs:
16+
# This workflow contains a single job called "build"
17+
build:
18+
# The type of runner that the job will run on
19+
runs-on: ubuntu-latest
20+
21+
# Steps represent a sequence of tasks that will be executed as part of the job
22+
steps:
23+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
24+
- uses: actions/checkout@v4
25+
26+
- name: Setup .NET 8
27+
uses: actions/setup-dotnet@v3
28+
with:
29+
dotnet-version: 8.0.x
30+
source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
31+
env:
32+
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
33+
34+
- name: Restore dependencies
35+
run: dotnet restore
36+
37+
- name: Build
38+
run: dotnet build --no-restore
39+
40+
- name: Build Release
41+
run: dotnet build --configuration Release --no-restore
42+
43+
- name: Pack
44+
run: dotnet pack --configuration Release
45+
46+
- name: Push NuGet
47+
run: dotnet nuget push "TensionDev.UUID.Serialization.SystemTextJson/bin/Release/*.nupkg" --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_TOKEN }} --no-symbols --skip-duplicate

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# TensionDev.UUID.Serialization.SystemTextJson
2+
3+
# Changelog
4+
All notable changes to this project will be documented in this file.
5+
6+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
7+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8+
9+
## [Unreleased]
10+
11+
### Added
12+
- Added UuidSystemTextJsonConverter for Json serialization and deserialization.
File renamed without changes.

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
# TensionDev.UUID.Serialization.SystemTextJson
1+
# TensionDev.UUID.Serialization.SystemTextJson
2+
3+
[![.NET](https://github.com/TensionDev/UUID.Serialization.SystemTextJson/actions/workflows/dotnet.yml/badge.svg)](https://github.com/TensionDev/UUID.Serialization.SystemTextJson/actions/workflows/dotnet.yml)
4+
[![Package Release](https://github.com/TensionDev/UUID.Serialization.SystemTextJson/actions/workflows/package-release.yml/badge.svg)](https://github.com/TensionDev/UUID.Serialization.SystemTextJson/actions/workflows/package-release.yml)
5+
[![CodeQL](https://github.com/TensionDev/UUID.Serialization.SystemTextJson/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/TensionDev/UUID.Serialization.SystemTextJson/actions/workflows/github-code-scanning/codeql)
6+
7+
TensionDev.UUID.Serialization.SystemTextJson is a .NET library for serializing and deserializing with Universally Unique Identifiers (UUIDs) using System.Text.Json.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<IsTestProject>true</IsTestProject>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
14+
<PackageReference Include="Moq" Version="4.18.4" />
15+
<PackageReference Include="xunit" Version="2.9.3" />
16+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
17+
<PrivateAssets>all</PrivateAssets>
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
</PackageReference>
20+
<PackageReference Include="coverlet.collector" Version="6.0.4">
21+
<PrivateAssets>all</PrivateAssets>
22+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23+
</PackageReference>
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<ProjectReference Include="..\TensionDev.UUID.Serialization.SystemTextJson\TensionDev.UUID.Serialization.SystemTextJson.csproj" />
28+
</ItemGroup>
29+
30+
</Project>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using Moq;
2+
using System;
3+
using System.Buffers;
4+
using System.Text;
5+
using System.Text.Json;
6+
using Xunit;
7+
8+
namespace TensionDev.UUID.Serialization.SystemTextJson.Tests
9+
{
10+
public class TestUuidSystemTextJsonConverter : IDisposable
11+
{
12+
private bool disposedValue;
13+
14+
private readonly UuidSystemTextJsonConverter _converter;
15+
16+
public TestUuidSystemTextJsonConverter()
17+
{
18+
_converter = new UuidSystemTextJsonConverter();
19+
}
20+
21+
[Theory]
22+
[InlineData(true)]
23+
[InlineData(false)]
24+
public void TestWrite(bool useNullOptions)
25+
{
26+
// Arrange
27+
using var ms = new MemoryStream();
28+
using var writer = new Utf8JsonWriter(ms);
29+
Uuid value = new Uuid();
30+
JsonSerializerOptions? options = useNullOptions ? null : new JsonSerializerOptions();
31+
32+
// Act
33+
_converter.Write(writer, value, options);
34+
writer.Flush();
35+
string actual = Encoding.UTF8.GetString(ms.ToArray());
36+
37+
// Assert
38+
string expected = JsonSerializer.Serialize(value.ToString());
39+
Assert.Equal(expected, actual);
40+
}
41+
42+
[Fact]
43+
public void TestRead()
44+
{
45+
// Arrange
46+
// Use a canonical all-zero UUID representation which is commonly accepted by UUID parsers.
47+
const string input = "00000000-0000-0000-0000-000000000000";
48+
string jsonText = "\"" + input + "\"";
49+
byte[] json = Encoding.UTF8.GetBytes(jsonText);
50+
var reader = new Utf8JsonReader(json);
51+
reader.Read();
52+
53+
// Act
54+
Uuid result = _converter.Read(ref reader, typeof(Uuid), new JsonSerializerOptions());
55+
56+
// Assert
57+
// Compare textual forms to avoid depending on reference equality or unknown equality semantics of Uuid.
58+
Assert.Equal(input, result.ToString());
59+
}
60+
61+
protected virtual void Dispose(bool disposing)
62+
{
63+
if (!disposedValue)
64+
{
65+
if (disposing)
66+
{
67+
// TODO: dispose managed state (managed objects)
68+
}
69+
70+
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
71+
// TODO: set large fields to null
72+
disposedValue = true;
73+
}
74+
}
75+
76+
// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
77+
// ~TestUuidSystemTextJsonConverter()
78+
// {
79+
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
80+
// Dispose(disposing: false);
81+
// }
82+
83+
public void Dispose()
84+
{
85+
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
86+
Dispose(disposing: true);
87+
GC.SuppressFinalize(this);
88+
}
89+
}
90+
}

TensionDev.UUID.Serialization.SystemTextJson.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ VisualStudioVersion = 18.3.11505.172 d18.3
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TensionDev.UUID.Serialization.SystemTextJson", "TensionDev.UUID.Serialization.SystemTextJson\TensionDev.UUID.Serialization.SystemTextJson.csproj", "{40C7D986-0424-4923-868C-21353C49D32F}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TensionDev.UUID.Serialization.SystemTextJson.Tests", "TensionDev.UUID.Serialization.SystemTextJson.Tests\TensionDev.UUID.Serialization.SystemTextJson.Tests.csproj", "{B73FC2D5-9124-4A7C-9831-C62118ADE7D1}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
1517
{40C7D986-0424-4923-868C-21353C49D32F}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{40C7D986-0424-4923-868C-21353C49D32F}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{40C7D986-0424-4923-868C-21353C49D32F}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{B73FC2D5-9124-4A7C-9831-C62118ADE7D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{B73FC2D5-9124-4A7C-9831-C62118ADE7D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{B73FC2D5-9124-4A7C-9831-C62118ADE7D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{B73FC2D5-9124-4A7C-9831-C62118ADE7D1}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)