Exemplo n.º 1
0
        public async Task <PeopleResponse> GetPeople(string url = null)
        {
            if (!string.IsNullOrWhiteSpace(url))
            {
                url = url.Replace("http:", "https:");
            }
            else
            {
                var baseUrl = GetBaseApiUrl();
                url = $"{baseUrl}people";
            }

            _logger.LogInformation($"Star Wars People API: {url}");

            PeopleResponse response = await _http.GetFromJsonAsync <PeopleResponse>(url);

            if (LogVerbose)
            {
                var json = JsonSerializer.Serialize <PeopleResponse>(response, new JsonSerializerOptions {
                    WriteIndented = true
                });
                _logger.LogInformation($"PeopleResponse: {json}");
            }

            _appState.PersonStore.SetPeopleResponse(response);

            return(response);
        }
Exemplo n.º 2
0
        public void GetAll_should_handle_exception()
        {
            // Arrange
            BaseMock.ShouldThrowException = true;
            PeopleResponse expected = new()
            {
                Status = new BaseResponse {
                    Code = Code.UnknownError, ErrorMessage = "An error orccured while loading people data"
                }
            };
            LogData expectedLog = new()
            {
                CallSide         = nameof(PeopleService),
                CallerMethodName = nameof(_peopleService.GetAll),
                CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                Request          = new Empty(),
                Response         = new Exception("Test exception")
            };

            // Act
            PeopleResponse actual = _peopleService.GetAll(new Empty(), null).Result;

            // Assert
            Assert.AreEqual(expected.Status.Code, actual.Status.Code, "Code as expected");
            Assert.AreEqual(expected.Status.ErrorMessage, actual.Status.ErrorMessage, "Error message as expected");
            CollectionAssert.AreEqual(expected.Data, actual.Data, "Data as expected");
            _loggerMock.Verify(mocks => mocks.AddErrorLog(expectedLog), Times.Once);
        }

        [Test]
        public async Task <PeopleResponse> GetPeople()
        {
            string url = WebServiceConstant.People;

            AuthenticationHeaderValue token = new AuthenticationHeaderValue("bearer", Settings.GeneralSettings);

            conection.ClientHttp().DefaultRequestHeaders.Authorization = token;
            PeopleResponse response = new PeopleResponse();

            try
            {
                var result = await conection.ClientHttp().GetAsync(url);

                if (result.IsSuccessStatusCode)
                {
                    string content = await result.Content.ReadAsStringAsync();

                    if (content != null)
                    {
                        response           = JsonConvert.DeserializeObject <PeopleResponse>(content);
                        response.IsCorrect = true;
                        return(response);
                    }
                }

                return(response);
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }

            return(response);
        }
Exemplo n.º 4
0
        public async Task <PeopleResponse> GetPeople()
        {
            PeopleResponse peopleResponse = new PeopleResponse();
            string         endpoint       = Configurations.UsersEndPoint;
            var            response       = await HttpClientBaseService.GetAsync(endpoint);

            if (response.Content == null)
            {
                return((PeopleResponse)Convert.ChangeType(response, typeof(PeopleResponse)));
            }
            else
            {
                string data = await response.Content.ReadAsStringAsync();

                if (string.IsNullOrEmpty(data))
                {
                    return(new PeopleResponse
                    {
                    });
                }

                var result = JsonConvert.DeserializeObject <IList <People> >(data);
                peopleResponse.People = result;
                return(peopleResponse);
            }
        }
Exemplo n.º 5
0
        public IActionResult GetAll()
        {
            Empty request = new();

            try
            {
                PeopleResponse response = _peopleClient.GetAll(request);
                LogData        logData  = new()
                {
                    CallSide         = nameof(PeopleController),
                    CallerMethodName = nameof(GetAll),
                    CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                    Request          = request,
                    Response         = response
                };
                _logger.AddLog(logData);
                return(Ok(response));
            }
            catch (Exception ex)
            {
                LogData logData = new()
                {
                    CallSide         = nameof(PeopleController),
                    CallerMethodName = nameof(GetAll),
                    CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                    Request          = request,
                    Response         = ex
                };
                _logger.AddErrorLog(logData);
                return(InternalServerError());
            }
        }
        public async Task <IActionResult> GetAllPeople()
        {
            var model    = new PeopleResponse();
            var response = await _peopleClient.GetPeopleInfo();

            model.results  = response.results;
            model.next     = response.next;
            model.previous = response.previous;
            return(View(model));
        }
        public async Task <IActionResult> ChangePagePeople(string url)
        {
            var UrlStrippedToPageInfo = url.Substring(url.Length - 14);
            var model    = new PeopleResponse();
            var response = await _peopleClient.GetPeopleInfo(UrlStrippedToPageInfo);

            model.results  = response.results;
            model.previous = response.previous;
            model.next     = response.next;
            return(View("GetAllPeople", model));
        }
Exemplo n.º 8
0
        public void GetAll_should_return_people_from_db()
        {
            // Arrange
            PeopleResponse expected = new()
            {
                Status = new BaseResponse {
                    Code = Code.Success, ErrorMessage = string.Empty
                }
            };

            _person1.Contacts = null;
            _person1.Photos   = null;
            expected.Data.Add(new PersonData
            {
                Id         = _person1.Id,
                LastName   = _person1.LastName,
                Name       = _person1.Name,
                SecondName = _person1.SecondName,
                BornedOn   = Timestamp.FromDateTime(_person1.BornedOn.ToUniversalTime()),
                CreatedOn  = Timestamp.FromDateTime(_person1.CreatedOn.ToUniversalTime()),
            });
            expected.Data.Add(new PersonData
            {
                Id         = _person2.Id,
                LastName   = _person2.LastName,
                Name       = _person2.Name,
                SecondName = _person2.SecondName,
                BornedOn   = Timestamp.FromDateTime(_person2.BornedOn.ToUniversalTime()),
                CreatedOn  = Timestamp.FromDateTime(_person2.CreatedOn.ToUniversalTime()),
            });

            LogData expectedLog = new()
            {
                CallSide         = nameof(PeopleService),
                CallerMethodName = nameof(_peopleService.GetAll),
                CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                Request          = new Empty(),
                Response         = expected
            };

            // Act
            PeopleResponse actual = _peopleService.GetAll(new Empty(), null).Result;

            // Assert
            Assert.AreEqual(expected.Status.Code, actual.Status.Code, "Code as expected");
            Assert.AreEqual(expected.Status.ErrorMessage, actual.Status.ErrorMessage, "Error message as expected");
            CollectionAssert.AreEqual(expected.Data, actual.Data, "Data as expected");
            _loggerMock.Verify(mocks => mocks.AddLog(expectedLog), Times.Once);
        }

        [Test]
Exemplo n.º 9
0
        public void DeserializePeopleResponse()
        {
            string         json     = TestData["PeopleResponse.json"];
            PeopleResponse response = NewtonsoftJsonSerializer
                                      .Create(JsonNamingStrategy.CamelCase)
                                      .Deserialize <PeopleResponse>(json);

            DateTime expectedDate0 = new DateTime(2017, 08, 05, 17, 03, 51).AddTicks(7279382);
            DateTime expectedDate1 = new DateTime(2017, 07, 22, 12, 55, 43).AddTicks(7301922);
            DateTime expectedDate2 = new DateTime(2013, 07, 01, 15, 10, 28).AddTicks(4600000);

            Assert.IsInstanceOf(typeof(IStringable), response);
            Assert.AreEqual(3, response.TotalCount);

            Assert.IsNotEmpty(response.People);
            Assert.AreEqual(3, response.People.Length);

            Assert.IsFalse(response.People[0].IsKnown);
            Assert.IsTrue(response.People[0].IsFavorite);
            Assert.IsTrue(response.People[0].IsFollowedByCaller);
            Assert.IsTrue(response.People[0].IsFollowingCaller);
            Assert.IsFalse(response.People[0].IsUnfollowingFeed);
            Assert.AreEqual(2580478784034343, response.People[0].Xuid);
            Assert.AreEqual(expectedDate0, response.People[0].AddedDateTimeUtc);
            Assert.IsNotNull(response.People[0].SocialNetworks);
            Assert.IsEmpty(response.People[0].SocialNetworks);

            Assert.IsFalse(response.People[1].IsKnown);
            Assert.IsTrue(response.People[1].IsFavorite);
            Assert.IsTrue(response.People[1].IsFollowedByCaller);
            Assert.IsTrue(response.People[1].IsFollowingCaller);
            Assert.IsFalse(response.People[1].IsUnfollowingFeed);
            Assert.AreEqual(2535771801919068, response.People[1].Xuid);
            Assert.AreEqual(expectedDate1, response.People[1].AddedDateTimeUtc);
            Assert.IsNotNull(response.People[1].SocialNetworks);
            Assert.IsEmpty(response.People[1].SocialNetworks);

            Assert.IsFalse(response.People[2].IsKnown);
            Assert.IsTrue(response.People[2].IsFavorite);
            Assert.IsTrue(response.People[2].IsFollowedByCaller);
            Assert.IsTrue(response.People[2].IsFollowingCaller);
            Assert.IsFalse(response.People[2].IsUnfollowingFeed);
            Assert.AreEqual(2508565379774180, response.People[2].Xuid);
            Assert.AreEqual(expectedDate2, response.People[2].AddedDateTimeUtc);
            Assert.IsNotNull(response.People[2].SocialNetworks);
            Assert.IsNotEmpty(response.People[2].SocialNetworks);
            Assert.AreEqual(1, response.People[2].SocialNetworks.Length);
            Assert.AreEqual("LegacyXboxLive", response.People[2].SocialNetworks[0]);
        }
Exemplo n.º 10
0
        public async Task GetPopleServiceDoesNotReturnInformation()
        {
            var response = new PeopleResponse()
            {
                People = new List <People>()
            };

            peopleService.Setup(_ => _.GetPeople()).ReturnsAsync(response);

            // Action
            var actual = await model.GetPeople();

            // Assert
            Assert.True(!response.People.Any());
        }
Exemplo n.º 11
0
        public async Task <List <People> > GetAllHumanPeople()
        {
            var requestUrl = CreateRequestUri(string.Format(System.Globalization.CultureInfo.InvariantCulture, "people/"));

            PeopleResponse peopleResponse;

            peopleResponse = new PeopleResponse();
            peopleResponse = await GetAsync <PeopleResponse>(requestUrl);

            peopleResponse.CarregarProximaPagina();

            //List<People> listPeople = new List<People>();

            return(peopleResponse.ObterListaAgregadaPessoas().Where(x => x.species.Contains("https://swapi.co/api/species/1/")).ToList());
        }
Exemplo n.º 12
0
        public void GetAll_should_return_response_from_grpc_client()
        {
            // Arrange
            Empty request = new();

            PeopleResponse response = new()
            {
                Status = new BaseResponse
                {
                    Code         = Code.Success,
                    ErrorMessage = string.Empty
                }
            };

            response.Data.Add(new PersonData
            {
                Id         = 1,
                BornedOn   = Timestamp.FromDateTime(_dateTimeUtil.GetCurrentDateTime()),
                CreatedOn  = Timestamp.FromDateTime(_dateTimeUtil.GetCurrentDateTime()),
                LastName   = "Test",
                Name       = "Test",
                SecondName = "Test"
            });
            BaseMock.Response = response;

            LogData expectedLog = new()
            {
                CallSide         = nameof(PeopleController),
                CallerMethodName = nameof(_peopleController.GetAll),
                CreatedOn        = _dateTimeUtil.GetCurrentDateTime(),
                Request          = request,
                Response         = response
            };

            // Act
            ObjectResult   actual     = _peopleController.GetAll() as ObjectResult;
            PeopleResponse actualData = actual.Value as PeopleResponse;

            // Assert
            Assert.AreEqual(200, actual.StatusCode, "StatusCode as expected");
            Assert.AreEqual(response, actualData, "Response data as expected");
            _peopleClientMock.Verify(m => m.GetAll(request, null, null, new CancellationToken()), Times.Once);
            _loggerMock.Verify(m => m.AddLog(expectedLog), Times.Once);
        }

        [Test]
Exemplo n.º 13
0
        public async Task GetPeopleAsync()
        {
            try
            {
                PeopleResponse _PeopleResponse = await _PeopleModel.GetPeople();

                if (_PeopleResponse != null && _PeopleResponse.People != null && _PeopleResponse.People.Any())
                {
                    people = _PeopleResponse.People;
                    DrawPeople();
                }

                progressDialog.Visibility = ViewStates.Gone;
                content.Visibility        = ViewStates.Visible;
            }
            catch (Exception exeption)
            {
                Console.Write($"GetPeopleAsync: {exeption}");
            }
        }
Exemplo n.º 14
0
        public async Task <PeopleResponse> GetPeople()
        {
            PeopleResponse response = new PeopleResponse();

            if (_documentsDataBase.ExistPeople())
            {
                response.People = _documentsDataBase.GetPeople();
            }
            else
            {
                response = await _peopleService.GetPeople();

                if (response != null && response.People != null && response.People.Any())
                {
                    SavePeople(response.People);
                }
            }

            return(response);
        }
Exemplo n.º 15
0
        public async Task <List <People> > GetAllPeople()
        {
            var requestUrl = CreateRequestUri(string.Format(System.Globalization.CultureInfo.InvariantCulture,
                                                            "people/"));

            PeopleResponse peopleResponse;

            peopleResponse = new PeopleResponse();
            peopleResponse = await GetAsync <PeopleResponse>(requestUrl);

            peopleResponse.CarregarProximaPagina();

            //List<People> listPeople = new List<People>();
            //listPeople = peopleResponse.ObterListaAgregadaPessoas().;
            //listPeople.AddRange(peopleResponse.results);

            //} while (peopleResponse.next != null);

            //return listPeople.OrderByDescending(x => x.films.Count).ThenBy(x => x.name).ToList();
            return(peopleResponse.ObterListaAgregadaPessoas().OrderByDescending(x => x.films.Count).ThenBy(x => x.name).ToList());
        }
Exemplo n.º 16
0
        public async Task GetPeopleFromTheServiceSuccessful()
        {
            var people = new List <People>
            {
                new People {
                    Id = 1, Name = "any", Email = "*****@*****.**"
                }
            };

            var response = new PeopleResponse()
            {
                People = people
            };

            peopleService.Setup(_ => _.GetPeople()).ReturnsAsync(response);

            // Action
            var actual = await model.GetPeople();

            // Assert
            Assert.True(response.People.Any());
        }
Exemplo n.º 17
0
 public void SetPeopleResponse(PeopleResponse response)
 {
     People         = response.Results;
     PeopleResponse = response;
 }