public void WhenCalled_ApiReturnsValidResponse_OwnerPetsDataIsNotNull() { // Arrange string resource = string.Empty; var Owners = new List <Owners>() { new Owners() { Age = 20, Gender = "Male", Name = "Sasank", Pets = new List <Pet>() { new Pet() { Name = "Tommy", Type = "Dog" } } } }; var restResponse = new RestResponse <List <Owners> >() { Data = Owners, StatusCode = HttpStatusCode.OK }; _moqClient.Setup(m => m.Execute <List <Owners> >(It.IsAny <IRestRequest>())).Returns(restResponse). Callback <IRestRequest>(rq => { resource = rq.Resource; }); //Act OwnerPetsData ownerPetsData = _petsDataAccess.RetrievePets(); // Assert Assert.AreEqual(0, ownerPetsData.Errors.Count); }
public PetsByGenderResponse RetreivePetsByType(string petType) { PetsByGenderResponse petsByGenderResponse = new PetsByGenderResponse(); List <PetsByGender> petsByGenderList = null; try { // Get data from Data Access OwnerPetsData ownerPetsData = _petsDataAccess.RetrievePets(); if (ownerPetsData != null && ownerPetsData?.Errors.Count == 0) { // Group pets by Owner gender Dictionary <string, List <List <Pet> > > petsGroupByOwnerGender = GroupPetsByOwnerGender(ownerPetsData); //Flatten pets under gender Dictionary <string, List <Pet> > flattenedPetsList = FlattenPetsByGenderList(petsGroupByOwnerGender); // Filter and sort pets by name petsByGenderList = FilterPetsByTypeandSortByName(flattenedPetsList, petType); petsByGenderResponse.PetsByGenderList = petsByGenderList; } else { // Map the errors to the response petsByGenderResponse.Errors = ownerPetsData.Errors; } } catch (Exception exception) { petsByGenderResponse.Errors.Add(new Error { ErrorMessage = exception.Message }); } return(petsByGenderResponse); }