Esempio n. 1
0
        private static async Task <StartupResponse> GetStartupAsync()
        {
            try
            {
                Uri    baseUri = new Uri(Config.Global.CustomStartupUrl ?? "https://startup.mobile.yandex.net/");
                string str1    = "analytics/startup?query_hosts=1&".GlueGetList(await ServiceData.GetStartupParameters(), true);
                if (Critical.GetUuid() != null)
                {
                    str1 = str1 + "&uuid=" + Critical.GetUuid();
                }
                Uri        requestUri = new Uri(baseUri, str1 + "&deviceid=" + Critical.GetDeviceId());
                HttpClient httpClient = new HttpClient();
                httpClient.DefaultRequestHeaders.Add("user-agent", ServiceData.UserAgent);
                httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
                using (HttpResponseMessage response = await httpClient.GetAsync(requestUri, CancellationToken.None))
                {
                    if (!response.IsSuccessStatusCode)
                    {
                        string str2 = await response.Content.ReadAsStringAsync();

                        return((StartupResponse)null);
                    }
                    using (Stream stream = await response.Content.ReadAsStreamAsync())
                    {
                        StartupResponse startupResponse1 = stream == null ? (StartupResponse)null : new DataContractJsonSerializer(typeof(StartupResponse)).ReadObject(stream) as StartupResponse;
                        if (startupResponse1 == null)
                        {
                            return((StartupResponse)null);
                        }
                        StartupResponse startupResponse2 = startupResponse1;
                        DateTimeOffset? date             = response.Headers.Date;
                        DateTimeOffset? local            = date;
                        DateTime        dateTime         = local.HasValue ? local.GetValueOrDefault().DateTime : DateTime.UtcNow;
                        startupResponse2.ServerDateTime   = dateTime;
                        startupResponse1.ServerTimeOffset = startupResponse1.ServerDateTime.ToUniversalTime() - DateTime.UtcNow;
                        return(startupResponse1);
                    }
                }
            }
            catch (Exception)
            {
                return((StartupResponse)null);
            }
        }
Esempio n. 2
0
        public static async Task <bool> RefreshStartupAsync()
        {
            StartupResponse startupAsync = await LiteClient.GetStartupAsync();

            if (startupAsync == null)
            {
                return(Config.Global.ReportUrl != null);
            }
            if (startupAsync.DeviceId != null)
            {
                Critical.SetDeviceId(startupAsync.DeviceId);
            }
            if (startupAsync.Uuid != null)
            {
                Critical.SetUuid(startupAsync.Uuid);
            }
            Config.Global.ReportUrl = startupAsync.ReportUrl;
            return(true);
        }
Esempio n. 3
0
        public async Task GetByIdAsyncWhenNoStartupFoundReturnsStartupNotFoundResponse()
        {
            // Arrange
            var mockStartupRepository = GetDefaultIStartupRepositoryInstance();
            var mockUnitOfWork        = GetDefaultIUnitOfWorkInstance();
            var startupId             = 1;

            mockStartupRepository.Setup(r => r.FindById(startupId))
            .Returns(Task.FromResult <Domain.Models.Startup>(null));

            var service = new StartupService(mockStartupRepository.Object, mockUnitOfWork.Object);

            // Act
            StartupResponse result = await service.GetByIdAsync(startupId);

            var message = result.Message;

            // Assert
            message.Should().Be("Startup not found");
        }