From 8b4a76b5134b62816aaabdba20ef6cd2bb48200b Mon Sep 17 00:00:00 2001 From: Benjamin Abt Date: Mon, 1 Apr 2024 21:37:41 +0200 Subject: [PATCH] add roslyn and fix some hints --- Directory.Packages.props | 22 +++++++++++++++---- ...harp.HttpUserAgentParser.AspNetCore.csproj | 17 +++++++++++++- ...arp.HttpUserAgentParser.MemoryCache.csproj | 19 ++++++++++++++-- ...erAgentParserDependencyInjectionOptions.cs | 17 +++++--------- .../HttpUserAgentInformation.cs | 2 -- .../HttpUserAgentPlatformInformation.cs | 21 ++++++------------ .../HttpUserAgentStatics.cs | 10 ++++----- .../MyCSharp.HttpUserAgentParser.csproj | 15 +++++++++++++ ...serAgentParser.AspNetCore.UnitTests.csproj | 17 +++++++++++++- ...erAgentParser.MemoryCache.UnitTests.csproj | 17 +++++++++++++- ...arp.HttpUserAgentParser.TestHelpers.csproj | 15 +++++++++++++ ...erAgentParserDependencyInjectionOptions.cs | 6 ++--- .../HttpUserAgentInformationTests.cs | 1 - ...Sharp.HttpUserAgentParser.UnitTests.csproj | 19 ++++++++++++++-- version.json | 16 +++++++------- 15 files changed, 159 insertions(+), 55 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index ae7a0d1..ea3fdaf 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -2,7 +2,7 @@ true - + @@ -10,13 +10,13 @@ - + - + @@ -37,5 +37,19 @@ runtime; build; native; contentfiles; analyzers - + + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + diff --git a/src/MyCSharp.HttpUserAgentParser.AspNetCore/MyCSharp.HttpUserAgentParser.AspNetCore.csproj b/src/MyCSharp.HttpUserAgentParser.AspNetCore/MyCSharp.HttpUserAgentParser.AspNetCore.csproj index 33de36b..c09b52c 100644 --- a/src/MyCSharp.HttpUserAgentParser.AspNetCore/MyCSharp.HttpUserAgentParser.AspNetCore.csproj +++ b/src/MyCSharp.HttpUserAgentParser.AspNetCore/MyCSharp.HttpUserAgentParser.AspNetCore.csproj @@ -16,11 +16,26 @@ - + + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + diff --git a/src/MyCSharp.HttpUserAgentParser.MemoryCache/MyCSharp.HttpUserAgentParser.MemoryCache.csproj b/src/MyCSharp.HttpUserAgentParser.MemoryCache/MyCSharp.HttpUserAgentParser.MemoryCache.csproj index 49b2866..c5e54a4 100644 --- a/src/MyCSharp.HttpUserAgentParser.MemoryCache/MyCSharp.HttpUserAgentParser.MemoryCache.csproj +++ b/src/MyCSharp.HttpUserAgentParser.MemoryCache/MyCSharp.HttpUserAgentParser.MemoryCache.csproj @@ -5,7 +5,7 @@ HTTP User Agent Parser Extensions for IMemoryCache net7.0;net8.0 - + true readme.md @@ -17,11 +17,26 @@ - + + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + diff --git a/src/MyCSharp.HttpUserAgentParser/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs b/src/MyCSharp.HttpUserAgentParser/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs index 06cfdd6..8fb66d3 100644 --- a/src/MyCSharp.HttpUserAgentParser/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs +++ b/src/MyCSharp.HttpUserAgentParser/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs @@ -7,19 +7,14 @@ namespace MyCSharp.HttpUserAgentParser.DependencyInjection; /// /// Options for dependency injection /// -public class HttpUserAgentParserDependencyInjectionOptions +/// +/// Creates a new instance of +/// +/// +public class HttpUserAgentParserDependencyInjectionOptions(IServiceCollection services) { /// /// Services container /// - public IServiceCollection Services { get; } - - /// - /// Creates a new instance of - /// - /// - public HttpUserAgentParserDependencyInjectionOptions(IServiceCollection services) - { - Services = services; - } + public IServiceCollection Services { get; } = services; } diff --git a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentInformation.cs b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentInformation.cs index cbbc9d6..1319154 100644 --- a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentInformation.cs +++ b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentInformation.cs @@ -27,13 +27,11 @@ public readonly struct HttpUserAgentInformation /// public string? Name { get; } - /// /// Version of Browser or Bot Name of user agent e.g. "79.0", "83.0.125.4" /// public string? Version { get; } - /// /// Device Type of user agent, e.g. "Android", "Apple iPhone" /// diff --git a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentPlatformInformation.cs b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentPlatformInformation.cs index 7045779..fef830a 100644 --- a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentPlatformInformation.cs +++ b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentPlatformInformation.cs @@ -7,30 +7,23 @@ namespace MyCSharp.HttpUserAgentParser; /// /// Information about the user agent platform /// -public readonly struct HttpUserAgentPlatformInformation +/// +/// Creates a new instance of +/// +public readonly struct HttpUserAgentPlatformInformation(Regex regex, string name, HttpUserAgentPlatformType platformType) { /// /// Regex-pattern that matches this user agent string /// - public Regex Regex { get; } + public Regex Regex { get; } = regex; /// /// Name of the platform /// - public string Name { get; } + public string Name { get; } = name; /// /// Specific platform type aka family /// - public HttpUserAgentPlatformType PlatformType { get; } - - /// - /// Creates a new instance of - /// - public HttpUserAgentPlatformInformation(Regex regex, string name, HttpUserAgentPlatformType platformType) - { - Regex = regex; - Name = name; - PlatformType = platformType; - } + public HttpUserAgentPlatformType PlatformType { get; } = platformType; } diff --git a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentStatics.cs b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentStatics.cs index bf68952..7b6d456 100644 --- a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentStatics.cs +++ b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentStatics.cs @@ -22,8 +22,8 @@ public static class HttpUserAgentStatics /// /// Platforms /// - public static readonly HashSet Platforms = new() - { + public static readonly HashSet Platforms = + [ new(CreateDefaultPlatformRegex("windows nt 10.0"), "Windows 10", HttpUserAgentPlatformType.Windows), new(CreateDefaultPlatformRegex("windows nt 6.3"), "Windows 8.1", HttpUserAgentPlatformType.Windows), new(CreateDefaultPlatformRegex("windows nt 6.2"), "Windows 8", HttpUserAgentPlatformType.Windows), @@ -66,7 +66,7 @@ public static class HttpUserAgentStatics new(CreateDefaultPlatformRegex("gnu"), "GNU/Linux", HttpUserAgentPlatformType.Linux), new(CreateDefaultPlatformRegex("unix"), "Unknown Unix OS", HttpUserAgentPlatformType.Unix), new(CreateDefaultPlatformRegex("symbian"), "Symbian OS", HttpUserAgentPlatformType.Symbian), - }; + ]; /// /// Regex defauls for browser mappings @@ -211,7 +211,7 @@ public static class HttpUserAgentStatics /// Robots /// public static readonly (string Key, string Value)[] Robots = - { + [ ( "googlebot", "Googlebot" ), ( "googleweblight", "Google Web Light" ), ( "PetalBot", "PetalBot"), @@ -254,7 +254,7 @@ public static readonly (string Key, string Value)[] Robots = ( "SEOkicks", "SEOkicks"), ( "seoscanners.net", "SEO Scanners"), ( "Sistrix", "Sistrix" ) - }; + ]; /// /// Tools diff --git a/src/MyCSharp.HttpUserAgentParser/MyCSharp.HttpUserAgentParser.csproj b/src/MyCSharp.HttpUserAgentParser/MyCSharp.HttpUserAgentParser.csproj index 83fb84e..43add95 100644 --- a/src/MyCSharp.HttpUserAgentParser/MyCSharp.HttpUserAgentParser.csproj +++ b/src/MyCSharp.HttpUserAgentParser/MyCSharp.HttpUserAgentParser.csproj @@ -21,6 +21,21 @@ + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + diff --git a/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.csproj b/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.csproj index f979669..7831f35 100644 --- a/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.csproj +++ b/tests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests/MyCSharp.HttpUserAgentParser.AspNetCore.UnitTests.csproj @@ -5,9 +5,24 @@ net7.0;net8.0 + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + - + diff --git a/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.csproj b/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.csproj index ebbb18b..65fa6e2 100644 --- a/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.csproj +++ b/tests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests/MyCSharp.HttpUserAgentParser.MemoryCache.UnitTests.csproj @@ -5,7 +5,22 @@ net7.0;net8.0 - + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + + diff --git a/tests/MyCSharp.HttpUserAgentParser.TestHelpers/MyCSharp.HttpUserAgentParser.TestHelpers.csproj b/tests/MyCSharp.HttpUserAgentParser.TestHelpers/MyCSharp.HttpUserAgentParser.TestHelpers.csproj index 2f4810e..8429490 100644 --- a/tests/MyCSharp.HttpUserAgentParser.TestHelpers/MyCSharp.HttpUserAgentParser.TestHelpers.csproj +++ b/tests/MyCSharp.HttpUserAgentParser.TestHelpers/MyCSharp.HttpUserAgentParser.TestHelpers.csproj @@ -12,4 +12,19 @@ + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + diff --git a/tests/MyCSharp.HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs b/tests/MyCSharp.HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs index ffb6699..ae03ea3 100644 --- a/tests/MyCSharp.HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs +++ b/tests/MyCSharp.HttpUserAgentParser.UnitTests/DependencyInjection/HttpUserAgentParserDependencyInjectionOptions.cs @@ -10,13 +10,13 @@ namespace MyCSharp.HttpUserAgentParser.UnitTests.DependencyInjection; public class UserAgentParserDependencyInjectionOptionsTests { - private readonly IServiceCollection scMock = Substitute.For(); + private readonly IServiceCollection _scMock = Substitute.For(); [Fact] public void Ctor_Should_Set_Property() { - HttpUserAgentParserDependencyInjectionOptions options = new(scMock); + HttpUserAgentParserDependencyInjectionOptions options = new(_scMock); - options.Services.Should().BeEquivalentTo(scMock); + options.Services.Should().BeEquivalentTo(_scMock); } } diff --git a/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs b/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs index 3c11fa3..675294a 100644 --- a/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs +++ b/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationTests.cs @@ -22,7 +22,6 @@ public void Parse(string userAgent) [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62")] public void CreateForRobot(string userAgent) { - HttpUserAgentInformation ua = HttpUserAgentInformation.CreateForRobot(userAgent, "Chrome"); ua.UserAgent.Should().Be(userAgent); diff --git a/tests/MyCSharp.HttpUserAgentParser.UnitTests/MyCSharp.HttpUserAgentParser.UnitTests.csproj b/tests/MyCSharp.HttpUserAgentParser.UnitTests/MyCSharp.HttpUserAgentParser.UnitTests.csproj index 8162c30..ce2a835 100644 --- a/tests/MyCSharp.HttpUserAgentParser.UnitTests/MyCSharp.HttpUserAgentParser.UnitTests.csproj +++ b/tests/MyCSharp.HttpUserAgentParser.UnitTests/MyCSharp.HttpUserAgentParser.UnitTests.csproj @@ -5,9 +5,9 @@ net7.0;net8.0 - + - + @@ -22,6 +22,21 @@ + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + diff --git a/version.json b/version.json index 8c23c13..8417f92 100644 --- a/version.json +++ b/version.json @@ -2,18 +2,18 @@ "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", "version": "3.0", "nugetPackageVersion": { - "semVer": 1 // optional. Set to either 1 or 2 to control how the NuGet package version string is generated. Default is 1. + "semVer": 1 // optional. Set to either 1 or 2 to control how the NuGet package version string is generated. Default is 1. }, "publicReleaseRefSpec": [ - "^refs/heads/main$", // we release out of main + "^refs/heads/main$" // we release out of main ], "cloudBuild": { - "buildNumber": { - "enabled": true - } + "buildNumber": { + "enabled": true + } }, "release": { - "versionIncrement" : "build", - "firstUnstableTag": "preview" + "versionIncrement": "build", + "firstUnstableTag": "preview" } - } +}