-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UserAgentValue arch board feedback (#27364)
* API for setting a dynamic UserAgent string
- Loading branch information
1 parent
26fd2e3
commit 0915f13
Showing
13 changed files
with
147 additions
and
91 deletions.
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
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
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 was deleted.
Oops, something went wrong.
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
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
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,66 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
using Azure.Core.Pipeline; | ||
using Azure.Core.TestFramework; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.Core.Tests | ||
{ | ||
public class TelemetryDetailsTests | ||
{ | ||
private const string appId = "MyApplicationId"; | ||
|
||
[Test] | ||
public void CtorInitializesValue([Values(null, appId)] string applicationId) | ||
{ | ||
var target = new TelemetryDetails(typeof(TelemetryDetailsTests).Assembly, applicationId); | ||
|
||
var assembly = Assembly.GetAssembly(GetType()); | ||
AssemblyInformationalVersionAttribute versionAttribute = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>(); | ||
string version = versionAttribute.InformationalVersion; | ||
int hashSeparator = version.IndexOfOrdinal('+'); | ||
if (hashSeparator != -1) | ||
{ | ||
version = version.Substring(0, hashSeparator); | ||
} | ||
if (applicationId == null) | ||
{ | ||
Assert.AreEqual( | ||
target.ToString(), | ||
$"azsdk-net-Core.Tests/{version} ({RuntimeInformation.FrameworkDescription}; {RuntimeInformation.OSDescription})"); | ||
} | ||
else | ||
{ | ||
Assert.AreEqual( | ||
target.ToString(), | ||
$"{applicationId} azsdk-net-Core.Tests/{version} ({RuntimeInformation.FrameworkDescription}; {RuntimeInformation.OSDescription})"); | ||
} | ||
} | ||
|
||
[Test] | ||
public void CtorPopulatesProperties([Values(null, appId)] string applicationId) | ||
{ | ||
var target = new TelemetryDetails(typeof(TelemetryDetailsTests).Assembly, applicationId); | ||
|
||
Assert.AreEqual(typeof(TelemetryDetailsTests).Assembly, target.Assembly); | ||
Assert.AreEqual(applicationId, target.ApplicationId); | ||
} | ||
|
||
[Test] | ||
public void AppliesToMessage() | ||
{ | ||
var target = new TelemetryDetails(typeof(TelemetryDetailsTests).Assembly); | ||
var message = new HttpMessage(new MockRequest(), ResponseClassifier.Shared); | ||
|
||
target.Apply(message); | ||
|
||
message.TryGetInternalProperty(typeof(UserAgentValueKey), out var obj); | ||
string actualValue = obj as string; | ||
|
||
Assert.AreEqual(target.ToString(), actualValue); | ||
} | ||
} | ||
} |
Oops, something went wrong.