Skip to content

Commit 901af1a

Browse files
committed
Add hard-coded Version.cs for telemetry
1 parent 4c354c7 commit 901af1a

3 files changed

Lines changed: 8 additions & 37 deletions

File tree

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Reflection;
21
using System.Runtime.CompilerServices;
32
using System.Text;
43

@@ -10,21 +9,12 @@ internal abstract class Utils
109
{
1110
/// <summary>
1211
/// Creates a Base64-encoded JSON string containing the SDK agent name and version.
13-
/// The version is retrieved from the assembly of <see cref="AuthenticationBuilderExtensions" />.
1412
/// </summary>
1513
/// <returns>A Base64-encoded JSON string with agent name and version.</returns>
1614
public static string CreateAgentString()
1715
{
18-
Version? sdkVersion = typeof(AuthenticationBuilderExtensions).GetTypeInfo().Assembly.GetName().Version;
1916
var agentJson =
20-
$"{{\"name\":\"aspnetcore-api\",\"version\":\"{BuildVersionString(sdkVersion)}\"}}";
17+
$"{{\"name\":\"aspnetcore-api\",\"version\":\"{Version.Current}\"}}";
2118
return Convert.ToBase64String(Encoding.UTF8.GetBytes(agentJson));
2219
}
23-
24-
internal static string BuildVersionString(Version? sdkVersion)
25-
{
26-
return sdkVersion != null
27-
? $"{sdkVersion.Major}.{sdkVersion.Minor}.{sdkVersion.Build}"
28-
: "0.0.0";
29-
}
3020
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Auth0.AspNetCore.Authentication.Api;
2+
3+
internal static class Version
4+
{
5+
public const string Current = "1.0.0-beta.6";
6+
}

tests/Auth0.AspNetCore.Authentication.Api.UnitTests/UtilsTests.cs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public void CreateAgentString_ReturnsBase64EncodedJson_With_Correct_Name_And_Ver
1010
var agentString = Utils.CreateAgentString();
1111
var decoded = Encoding.UTF8.GetString(Convert.FromBase64String(agentString));
1212
decoded.Should().Contain("\"name\":\"aspnetcore-api\"");
13-
decoded.Should().MatchRegex("\"version\":\"\\d+\\.\\d+\\.\\d+\"");
13+
decoded.Should().Contain($"\"version\":\"{Version.Current}\"");
1414
}
1515

1616
[Fact]
@@ -20,29 +20,4 @@ public void CreateAgentString_Returns_Valid_Base64_String()
2020
Action act = () => Convert.FromBase64String(agentString);
2121
act.Should().NotThrow();
2222
}
23-
24-
[Fact]
25-
public void CreateAgentString_Returns_Json_With_Default_Version_If_Assembly_Version_Is_Null()
26-
{
27-
// Simulate null version by using a test double if possible, otherwise check for "0.0.0" fallback
28-
// Since static method and type, we can only check for the fallback value in the output
29-
var agentString = Utils.CreateAgentString();
30-
var decoded = Encoding.UTF8.GetString(Convert.FromBase64String(agentString));
31-
decoded.Should().MatchRegex("\"version\":\"\\d+\\.\\d+\\.\\d+\"");
32-
}
33-
34-
[Fact]
35-
public void BuildVersionString_ReturnsCorrectString_When_Version_Is_Not_Null()
36-
{
37-
var version = new Version(1, 2, 3);
38-
var result = Utils.BuildVersionString(version);
39-
result.Should().Be("1.2.3");
40-
}
41-
42-
[Fact]
43-
public void BuildVersionString_Returns_Zero_Version_When_Version_Is_Null()
44-
{
45-
var result = Utils.BuildVersionString(null);
46-
result.Should().Be("0.0.0");
47-
}
4823
}

0 commit comments

Comments
 (0)