public async Task SendAsync_AddCorrectSDKTreackingHeader()
        {
            var assembly        = typeof(ContentManagementHttpClient).Assembly;
            var fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
            var sdkVersion      = fileVersionInfo.ProductVersion;
            var sdkPackageId    = assembly.GetName().Name;

            IHttpClient        httpClient         = Substitute.For <IHttpClient>();
            IDelay             delay              = Substitute.For <IDelay>();
            HttpRequestMessage mockRequestMessage = Substitute.For <HttpRequestMessage>();
            var successfulResponse = new HttpResponseMessage {
                StatusCode = HttpStatusCode.OK
            };

            httpClient.SendAsync(Arg.Is(mockRequestMessage)).Returns(successfulResponse);

            ContentManagementHttpClient client = new ContentManagementHttpClient(delay, httpClient);
            var response = await client.SendAsync(mockRequestMessage);

            IEnumerable <string> headerContent = new List <string>();

            mockRequestMessage.Headers.TryGetValues("X-KC-SDKID", out headerContent);
            Assert.True(mockRequestMessage.Headers.Contains("X-KC-SDKID"));
            Assert.Contains($"nuget.org;{sdkPackageId};{sdkVersion}", headerContent);
        }
Exemple #2
0
 public ContentManagementHttpClientTests()
 {
     _client = new ContentManagementHttpClient(delay, httpClient);
 }