From 4e6b5611b01744b7caef2bf39377d7289e5f3623 Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Thu, 3 Feb 2022 19:58:35 -0300 Subject: [PATCH 1/3] Create a Version class to help the upcoming analytics integration --- src/Meilisearch/Version.cs | 26 +++++++++++++++ tests/Meilisearch.Tests/VersionTests.cs | 43 +++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/Meilisearch/Version.cs create mode 100644 tests/Meilisearch.Tests/VersionTests.cs diff --git a/src/Meilisearch/Version.cs b/src/Meilisearch/Version.cs new file mode 100644 index 00000000..3e15cf86 --- /dev/null +++ b/src/Meilisearch/Version.cs @@ -0,0 +1,26 @@ +namespace Meilisearch +{ + /// + /// Information regarding an API key for the Meilisearch server. + /// + public class Version + { + /// + /// Extracts version from Meilisearch.csproj. + /// + /// Returns a formatted version. + public string GetQualifiedVersion() + { + return $"Meilisearch (v{this.GetVersion()})"; + } + + /// + /// Extracts the "major.minor.build" version from Meilisearch.csproj. + /// + /// Returns a version from the GetType as String. + public string GetVersion() + { + return this.GetType().Assembly.GetName().Version.ToString(3); + } + } +} diff --git a/tests/Meilisearch.Tests/VersionTests.cs b/tests/Meilisearch.Tests/VersionTests.cs new file mode 100644 index 00000000..cc5436c9 --- /dev/null +++ b/tests/Meilisearch.Tests/VersionTests.cs @@ -0,0 +1,43 @@ +namespace Meilisearch.Tests +{ + using System.IO; + using System.Xml; + using Xunit; + + public class VersionTests + { + private Version version; + + public VersionTests() + { + this.version = new Version(); + } + + [Fact] + public void GetQualifiedVersion() + { + var qualifiedVersion = this.version.GetQualifiedVersion(); + var version = this.version.GetVersion(); + + Assert.Equal(qualifiedVersion, $"Meilisearch (v{version})"); + } + + [Fact] + public void GetSimpleVersionFromCsprojFile() + { + // get the current version defined in the csproj file + var xmldoc = new XmlDocument(); + var currentDir = Directory.GetParent(Directory.GetCurrentDirectory()).FullName; + var path = Path.Combine(currentDir, @"../../../../src/Meilisearch/Meilisearch.csproj"); + xmldoc.Load(path); + var mgr = new XmlNamespaceManager(xmldoc.NameTable); + mgr.AddNamespace("x", "http://schemas.microsoft.com/developer/msbuild/2003"); + var versionFromCsproj = xmldoc.FirstChild.FirstChild.SelectSingleNode("Version").InnerText; + + var value = this.version.GetVersion(); + + Assert.NotNull(value); + Assert.Equal(versionFromCsproj, value); + } + } +} From 953d52de4f09579e36c98a2167832a545231d4c8 Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Fri, 4 Feb 2022 20:48:02 -0300 Subject: [PATCH 2/3] Fix GitHub Action by specifying a specific .net version --- .github/workflows/tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c76df7bf..6a1723cd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,7 +21,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 3.1.101 + dotnet-version: "3.1.x" - name: Meilisearch (latest version) setup with Docker run: docker run -d -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --no-analytics=true --master-key=masterKey - name: Install dependencies @@ -38,6 +38,8 @@ jobs: - uses: actions/checkout@v2 - name: Setup .NET Core uses: actions/setup-dotnet@v1 + with: + dotnet-version: "3.1.x" - name: Install dotnet-format run: dotnet tool install -g dotnet-format - name: Check with dotnet-format From c1bdea0da861ddc7ee1f5aa10c67ab0f55db38d4 Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Tue, 8 Feb 2022 09:40:50 -0300 Subject: [PATCH 3/3] Add .NET to the qualified name --- src/Meilisearch/Version.cs | 2 +- tests/Meilisearch.Tests/VersionTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Meilisearch/Version.cs b/src/Meilisearch/Version.cs index 3e15cf86..7421374d 100644 --- a/src/Meilisearch/Version.cs +++ b/src/Meilisearch/Version.cs @@ -11,7 +11,7 @@ public class Version /// Returns a formatted version. public string GetQualifiedVersion() { - return $"Meilisearch (v{this.GetVersion()})"; + return $"Meilisearch .NET (v{this.GetVersion()})"; } /// diff --git a/tests/Meilisearch.Tests/VersionTests.cs b/tests/Meilisearch.Tests/VersionTests.cs index cc5436c9..65b8fdd9 100644 --- a/tests/Meilisearch.Tests/VersionTests.cs +++ b/tests/Meilisearch.Tests/VersionTests.cs @@ -19,7 +19,7 @@ public void GetQualifiedVersion() var qualifiedVersion = this.version.GetQualifiedVersion(); var version = this.version.GetVersion(); - Assert.Equal(qualifiedVersion, $"Meilisearch (v{version})"); + Assert.Equal(qualifiedVersion, $"Meilisearch .NET (v{version})"); } [Fact]