-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
233: Feature/Analytics r=brunoocasali a=brunoocasali - Create the `Version` class - Load the current version from the csproj data through the `GetType>Assembly>GetName>Version` (I don’t really know if this could have some potential of not working in some cases, let me know that). > The Github Action for some reason stopped working, I fixed the version of the .net in order to fix the problem. Related to meilisearch/integration-guides#150 Co-authored-by: Bruno Casali <brunoocasali@gmail.com>
- Loading branch information
Showing
3 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace Meilisearch | ||
{ | ||
/// <summary> | ||
/// Information regarding an API key for the Meilisearch server. | ||
/// </summary> | ||
public class Version | ||
{ | ||
/// <summary> | ||
/// Extracts version from Meilisearch.csproj. | ||
/// </summary> | ||
/// <returns>Returns a formatted version.</returns> | ||
public string GetQualifiedVersion() | ||
{ | ||
return $"Meilisearch .NET (v{this.GetVersion()})"; | ||
} | ||
|
||
/// <summary> | ||
/// Extracts the "major.minor.build" version from Meilisearch.csproj. | ||
/// </summary> | ||
/// <returns>Returns a version from the GetType as String.</returns> | ||
public string GetVersion() | ||
{ | ||
return this.GetType().Assembly.GetName().Version.ToString(3); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 .NET (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); | ||
} | ||
} | ||
} |