public void TestGetResidentsOfPlanet() { var planetName = "Tatooine"; var resident1Url = "resident1Url"; var planetsJson = "{\"count\": 1,\"next\":\"\",\"previous\": null,\"results\":[{\"name\": \"" + planetName + "\",\"residents\": [\"" + resident1Url + "\"]}]}"; var residentJson = "{\"name\": \"Luke Skywalker\", \"height\": \"172\", \"mass\": \"77\", \"hair_color\": \"blond\", \"skin_color\": \"fair\", \"eye_color\": \"blue\", \"birth_year\": \"19BBY\", \"gender\": \"male\", \"homeworld\": \"https://swapi.co/api/planets/1/\", \"films\": [\"https://swapi.co/api/films/2/\"], \"species\": [\"https://swapi.co/api/species/1/\"], \"vehicles\": [\"https://swapi.co/api/vehicles/14/\"], \"starships\": [\"https://swapi.co/api/starships/12/\"]}"; _mockHttpService.JsonResponses["https://swapi.co/api/planets/"] = planetsJson; _mockHttpService.JsonResponses[resident1Url] = residentJson; var residents = _starWarsService.GetResidentsOfPlanet(planetName); Assert.AreEqual(residents.Count, 1); var resident = residents.Find(x => x.Name == "Luke Skywalker"); // Make sure json is translated to correct attributes Assert.AreEqual(resident.Height, "172"); Assert.AreEqual(resident.Weight, "77"); Assert.AreEqual(resident.HairColor, "blond"); Assert.AreEqual(resident.SkinColor, "fair"); Assert.AreEqual(resident.EyeColor, "blue"); Assert.AreEqual(resident.BirthYear, "19BBY"); Assert.AreEqual(resident.Gender, "male"); Assert.AreEqual(resident.Films.Count, 1); Assert.AreEqual(resident.Species.Count, 1); Assert.AreEqual(resident.Vehicles.Count, 1); Assert.AreEqual(resident.StarShips.Count, 1); }
public ActionResult GetResidentsOfPlanet(string planetName) { var residents = _starWarsService.GetResidentsOfPlanet(planetName); var model = Mapper.Map <List <ResidentSummary> >(residents) .OrderBy(x => x.Name).ToList(); return(View(model)); }