diff --git a/Microsoft.Azure.Cosmos/Directory.Build.props b/Microsoft.Azure.Cosmos/Directory.Build.props index 147bda06f3..f2d197eaac 100644 --- a/Microsoft.Azure.Cosmos/Directory.Build.props +++ b/Microsoft.Azure.Cosmos/Directory.Build.props @@ -2,7 +2,7 @@ 3.2.0 - 3.2.1 + 3.3.0 1.0.0-preview $([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../')) diff --git a/Microsoft.Azure.Cosmos/src/UserAgentContainer.cs b/Microsoft.Azure.Cosmos/src/UserAgentContainer.cs index c9109fe5e4..ccf66c9a6b 100644 --- a/Microsoft.Azure.Cosmos/src/UserAgentContainer.cs +++ b/Microsoft.Azure.Cosmos/src/UserAgentContainer.cs @@ -4,52 +4,29 @@ namespace Microsoft.Azure.Cosmos { - using System.Text; - /// /// Contains information about the user environment and helps identify requests. /// internal class UserAgentContainer : Documents.UserAgentContainer { - internal const string Delimiter = " "; - internal new static readonly string baseUserAgent; - private const int maxSuffixLength = 64; - private string suffix; + private static readonly string cosmosBaseUserAgent; static UserAgentContainer() { EnvironmentInformation environmentInformation = new EnvironmentInformation(); - UserAgentContainer.baseUserAgent = environmentInformation.ToString(); + UserAgentContainer.cosmosBaseUserAgent = environmentInformation.ToString(); } public UserAgentContainer() + : base() { - this.UserAgent = UserAgentContainer.baseUserAgent; - this.UserAgentUTF8 = Encoding.UTF8.GetBytes(this.UserAgent); } - public new string UserAgent { get; private set; } - - public new byte[] UserAgentUTF8 { get; private set; } - - public new string Suffix + internal override string BaseUserAgent { get { - return this.suffix; - } - set - { - this.suffix = value; - - // Take only the first 64 characters of the user-agent. - if (this.suffix.Length > maxSuffixLength) - { - this.suffix = this.suffix.Substring(0, 64); - } - - this.UserAgent = UserAgentContainer.baseUserAgent + UserAgentContainer.Delimiter + this.suffix; - this.UserAgentUTF8 = Encoding.UTF8.GetBytes(this.UserAgent); + return UserAgentContainer.cosmosBaseUserAgent; } } } diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs index 0d89c0baee..922dd3388f 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/HeadersValidationTests.cs @@ -443,13 +443,26 @@ public void ValidateCustomUserAgentHeader() const string suffix = " MyCustomUserAgent/1.0"; ConnectionPolicy policy = new ConnectionPolicy(); policy.UserAgentSuffix = suffix; - var expectedUserAgent = Cosmos.UserAgentContainer.baseUserAgent + Cosmos.UserAgentContainer.Delimiter + suffix; + var expectedUserAgent = new Cosmos.UserAgentContainer().BaseUserAgent + suffix; Assert.AreEqual(expectedUserAgent, policy.UserAgentContainer.UserAgent); byte[] expectedUserAgentUTF8 = Encoding.UTF8.GetBytes(expectedUserAgent); CollectionAssert.AreEqual(expectedUserAgentUTF8, policy.UserAgentContainer.UserAgentUTF8); } + [TestMethod] + public void ValidateCustomUserAgentContainer() + { + const string suffix = " MyCustomUserAgent/1.0"; + UserAgentContainer userAgentContainer = new Cosmos.UserAgentContainer(); + userAgentContainer.Suffix = suffix; + string expectedUserAgent = new Cosmos.UserAgentContainer().BaseUserAgent + suffix; + Assert.AreEqual(expectedUserAgent, userAgentContainer.UserAgent); + + byte[] expectedUserAgentUTF8 = Encoding.UTF8.GetBytes(expectedUserAgent); + CollectionAssert.AreEqual(expectedUserAgentUTF8, userAgentContainer.UserAgentUTF8); + } + [TestMethod] public void ValidateVersionHeader() { diff --git a/changelog.md b/changelog.md index 42343dabe8..13c603d88c 100644 --- a/changelog.md +++ b/changelog.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#835](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/835) Fixed a bug that caused sortedRanges exceptions - [#846](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/846) Statistics not getting populated correctly on CosmosException. - [#857](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/857) Fixed reusability of the Bulk support across Container instances +- [#860](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/860) Fixed base user agent string ## [3.2.0](https://www.nuget.org/packages/Microsoft.Azure.Cosmos/3.2.0) - 2019-09-17