コード例 #1
0
        public void AddVersionInfo(string productName, string productVersion)
        {
            var dataSender           = new SpanDataSender(new TelemetryConfiguration().WithApiKey("123456"));
            var fieldInfo            = dataSender.GetType().GetField("_userAgent", BindingFlags.NonPublic | BindingFlags.Instance);
            var userAgentValueBefore = fieldInfo.GetValue(dataSender);

            var expectedUserAgentValue = userAgentValueBefore?.ToString();

            if (!string.IsNullOrEmpty(productName) && !string.IsNullOrEmpty(productVersion))
            {
                expectedUserAgentValue = userAgentValueBefore + " " + $@"{productName}/{productVersion}";
            }

            dataSender.AddVersionInfo(productName, productVersion);

            var userAgentValueAfter = fieldInfo.GetValue(dataSender);

            Assert.AreEqual(expectedUserAgentValue, userAgentValueAfter);
        }