Beispiel #1
0
        public async Task SendAsync_SendsMessageOnSuccessReturnsResponse()
        {
            var successfulMessage  = new HttpRequestMessage();
            var successfulResponse = new HttpResponseMessage {
                StatusCode = System.Net.HttpStatusCode.OK
            };

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

            var response = await _client.SendAsync(successfulMessage);

            await httpClient.Received().SendAsync(successfulMessage);

            Assert.Equal(successfulResponse, response);
        }
        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);
        }