public void UserAgent_is_known()
        {
            var userAgent = new UserAgentBuilder(
                Platform.Analyze(),
                Sdk.Anaylze(),
                SourceLanguage.Analyze(this.GetType().Assembly)).GetUserAgent();

            userAgent.ShouldNotContain("unknown");

            this.output.WriteLine($"UserAgent: {userAgent}");
        }
        public void GetApplicationComponent_ShouldNotBeEmpty()
        {
            var actual = UserAgentBuilder.GetApplicationComponent();

            actual.Should().NotBeEmpty();
        }
Exemple #3
0
        public void ReturnSanitizedFrameworkDescriptionWhenContainsBrackets(string rawString, string sanitizedString)
        {
            var frameworkInfo = UserAgentBuilder.Sanitize(rawString);

            frameworkInfo.Should().Be(sanitizedString);
        }
 public void SetUp()
 {
     subject = new UserAgentBuilder();
 }
        /// <summary>
        /// Sends the given History object to the cloud.
        /// </summary>
        /// <param name="history">History object to send.</param>
        public async Task <ResponseMessage> SendHistory(History history)
        {
            try
            {
                Logger.Trace("SendHistory");
                System.Net.Http.HttpClient apiConnection = new System.Net.Http.HttpClient();
                apiConnection.DefaultRequestHeaders.Add(Constants.XApiKey, Configuration.ApiKey);
                apiConnection.DefaultRequestHeaders.Add(Constants.Xiid, SdkData.DeviceId);
                apiConnection.DefaultRequestHeaders.Add(Constants.AdvertisementIdentifierHeader,
                                                        string.IsNullOrEmpty(Configuration.UserId) ? Windows.System.UserProfile.AdvertisingManager.AdvertisingId : Configuration.UserId);
                apiConnection.DefaultRequestHeaders.TryAddWithoutValidation(Constants.XUserAgent, UserAgentBuilder.BuildUserAgentJson());
                string serializeObject = JsonConvert.SerializeObject(history);
                var    content         = new StringContent(serializeObject, Encoding.UTF8, "application/json");

                System.Net.Http.HttpResponseMessage responseMessage = await apiConnection.PostAsync(new Uri(Configuration.LayoutUri), content);

                Logger.Trace("SendHistory HttpCode: {0}", responseMessage.StatusCode);
                if (responseMessage.IsSuccessStatusCode)
                {
                    LastCallResult = NetworkResult.Success;
                    return(new ResponseMessage()
                    {
                        Content = responseMessage.Content.ToString(),
                        Header = responseMessage.Headers.ToString(),
                        StatusCode = Convert(responseMessage.StatusCode),
                        IsSuccess = responseMessage.IsSuccessStatusCode
                    });
                }
                LastCallResult = NetworkResult.UnknownError;
                return(new ResponseMessage()
                {
                    StatusCode = Convert(responseMessage.StatusCode), IsSuccess = responseMessage.IsSuccessStatusCode
                });
            }
            catch (Exception ex)
            {
                Logger.Error("SendHistory Error", ex);
                LastCallResult = NetworkResult.NetworkError;
                return(new ResponseMessage()
                {
                    IsSuccess = false
                });
            }
        }