public void _010_we_should_be_able_to_add_an_artist_named_Prince_from_our_API() { var prince = new Artist { Name = "Prince" }; var response = _restClient.Post(ArtistRelativePath, prince); Assert.That(response.Success, Is.True); Assert.That(response.ResourceUri, Is.Not.Null); }
// PUT http://localhost:4848/api/artist/5 public void PutArtist(int id, Artist artistToUpdate) { artistToUpdate.Id = id; var successfullyUpdated = ArtistDataService.Update(artistToUpdate); if (!successfullyUpdated) { throw new HttpResponseException(HttpStatusCode.NotFound); } }
// POST http://localhost:4848/api/artist public HttpResponseMessage PostProduct(Artist artistToCreate) { var createdArtist = ArtistDataService.Create(artistToCreate.Name); var response = Request.CreateResponse(HttpStatusCode.Created, createdArtist); string uri = Url.Link("DefaultApi", new {id = createdArtist.Id}); response.Headers.Location = new Uri(uri); return response; }
/// <summary> /// Creates a new Artist in the "DB" with a name of artistName and /// assigns an Id to the Artist. /// </summary> /// <param name="artistName"></param> /// <returns></returns> public Artist Create(string artistName) { var newArtist = new Artist { Id = NextId++, Name = artistName }; AddArtistToDB(newArtist); return newArtist; }
private static void UpdateArtistFromDBWith(Artist artistToUpdate) { ArtistDatabase[artistToUpdate.Id] = artistToUpdate; }
private static void AddArtistToDB(Artist newArtist) { ArtistDatabase.Add(newArtist.Id, newArtist); }
/// <summary> /// Updates artistToUpdate in the "DB" /// </summary> /// <param name="artistToUpdate"></param> /// <returns>true if artist exists, false otherwise</returns> public bool Update(Artist artistToUpdate) { if(!ArtistDatabase.ContainsKey(artistToUpdate.Id)) { return false; } UpdateArtistFromDBWith(artistToUpdate); return true; }
public void _500_we_should_be_able_to_add_a_few_artists_and_albums_into_our_API() { var newArtist = new Artist { Name = "Robert Plant" }; var response = _artistRestClient.Post(ArtistRelativePath, newArtist); Assert.That(response.Success, Is.True); Assert.That(response.ResourceUri, Is.Not.Null); var robertPlantId = int.Parse(response.ResourceParsedId); newArtist = new Artist { Name = "Alison Krauss" }; response = _artistRestClient.Post(ArtistRelativePath, newArtist); Assert.That(response.Success, Is.True); Assert.That(response.ResourceUri, Is.Not.Null); var alisonKraussId = int.Parse(response.ResourceParsedId); var newAlbum = new Album { Title = "Raising Sand", ReleaseDate = new DateTime(2007, 10, 23), ArtistIds = new List<int> {robertPlantId, alisonKraussId} }; response = _albumRestClient.Post(AlbumRelativePath, newAlbum); Assert.That(response.Success, Is.True); Assert.That(response.ResourceUri, Is.Not.Null); newAlbum = new Album { Title = "Pictures at Eleven", ReleaseDate = new DateTime(1982, 6, 28), ArtistIds = new List<int> { robertPlantId } }; response = _albumRestClient.Post(AlbumRelativePath, newAlbum); Assert.That(response.Success, Is.True); Assert.That(response.ResourceUri, Is.Not.Null); }
public void _500_we_should_be_able_to_add_a_few_artists_into_our_API() { var newArtist = new Artist { Name = "Prince" }; var response = _restClient.Post(ArtistRelativePath, newArtist); Assert.That(response.Success, Is.True); Assert.That(response.ResourceUri, Is.Not.Null); newArtist = new Artist { Name = "U2" }; response = _restClient.Post(ArtistRelativePath, newArtist); Assert.That(response.Success, Is.True); Assert.That(response.ResourceUri, Is.Not.Null); newArtist = new Artist { Name = "Snoop Lion" }; response = _restClient.Post(ArtistRelativePath, newArtist); Assert.That(response.Success, Is.True); Assert.That(response.ResourceUri, Is.Not.Null); newArtist = new Artist { Name = "Nirvana" }; response = _restClient.Post(ArtistRelativePath, newArtist); Assert.That(response.Success, Is.True); Assert.That(response.ResourceUri, Is.Not.Null); }