// Used to call AGL json web service http://agl-developer-test.azurewebsites.net/people.json public async Task <PetOwnersViewModel> GetPetOwnerAsync() { var petOwnersViewModel = new PetOwnersViewModel(); //GET Method try { HttpResponseMessage response = await _httpClient.GetAsync(RequestUri); petOwnersViewModel.StatusCode = response.StatusCode; if (response.IsSuccessStatusCode) { var json = await response.Content.ReadAsStringAsync(); var petOwners = JsonConvert.DeserializeObject <List <PetOwner> >(json); petOwnersViewModel.PetOwners = petOwners; } else { petOwnersViewModel.PetOwners = new List <PetOwner>(); } } catch (HttpRequestException ex) { petOwnersViewModel.Exception = ex; } catch (Exception ex) { petOwnersViewModel.Exception = ex; } return(petOwnersViewModel); }
public async Task ValidatePetsFromOwners() { var petOwnersViewModel = new PetOwnersViewModel() { PetOwners = _petOwners }; _mockRepository.Setup(x => x.BaseAddress).Returns("http://agl-developer-test.azurewebsites.net/"); _mockRepository.Setup(x => x.RequestUri).Returns("people.json"); _mockRepository.Setup(x => x.GetPetOwnerAsync()).ReturnsAsync(petOwnersViewModel); var sut = new HomeController(_mockConfiguration.Object, _mockRepository.Object, null); var result = await sut.Index(); var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsType <PetsViewModels>(viewResult.Model); Assert.Equal(6, model.PetsViewModelAgl.PetsFromMaleOwner.Count); Assert.Equal(4, model.PetsViewModelAgl.PetsFromFemaleOwner.Count); }