Esempio n. 1
0
 public void _010_we_should_be_able_to_add_an_album_named_Raising_Snd_with_no_artists_into_our_API()
 {
     var raisingSand = new Album { Title = "Raising Snd", ReleaseDate = new DateTime(2007, 10, 23)};
     var response = _albumRestClient.Post(AlbumRelativePath, raisingSand);
     Assert.That(response.Success, Is.True);
     Assert.That(response.ResourceUri, Is.Not.Null);
 }
 // PUT http://localhost:4848/api/album/5
 public void PutAlbum(int id, Album albumToUpdate)
 {
     albumToUpdate.Id = id;
     var successfullyUpdated = AlbumDataService.Update(albumToUpdate);
     if (!successfullyUpdated)
     {
         throw new HttpResponseException(HttpStatusCode.NotFound);
     }
 }
Esempio n. 3
0
 public Album(Album albumToCopy)
     : this()
 {
     Id = albumToCopy.Id;
     Title = albumToCopy.Title;
     ReleaseDate = albumToCopy.ReleaseDate;
     foreach (var artistId in albumToCopy.ArtistIds)
     {
         ArtistIds.Add(artistId);
     }
 }
        public HttpResponseMessage PostAlbum(Album albumToCreate)
        {
            var createdAlbum =
                AlbumDataService.Create(
                    albumToCreate.Title,
                    albumToCreate.ReleaseDate,
                    albumToCreate.ArtistIds);

            var response = Request.CreateResponse(HttpStatusCode.Created, createdAlbum);

            string uri = Url.Link("DefaultApi", new { id = createdAlbum.Id });
            response.Headers.Location = new Uri(uri);
            return response;
        }
 /// <summary>
 /// Creates a new Album in the "DB" with a name of albumTitle, 
 /// a release date of releaseDate, and assigns an Id to the Album.
 /// </summary>
 /// <param name="albumTitle"></param>
 /// <param name="releaseDate"> </param>
 /// <param name="artistIds"> </param>
 /// <returns>The newly created Album</returns>
 public Album Create(string albumTitle, DateTime releaseDate, List<int> artistIds)
 {
     var newAlbum =
         new Album
             {
                 Id = NextId++,
                 Title = albumTitle,
                 ReleaseDate = releaseDate
             };
     if(artistIds != null)
     {
         foreach (var artistId in artistIds)
         {
             newAlbum.ArtistIds.Add(artistId);
         }
     }
     AddAlbumToDB(newAlbum);
     return newAlbum;
 }
Esempio n. 6
0
 protected bool Equals(Album other)
 {
     return Id == other.Id;
 }
Esempio n. 7
0
        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);
        }
 private static void UpdateAlbumFromDBWith(Album albumToUpdate)
 {
     AlbumDatabase[albumToUpdate.Id] = albumToUpdate;
 }
 private static void AddAlbumToDB(Album newAlbum)
 {
     AlbumDatabase.Add(newAlbum.Id, newAlbum);
 }
 /// <summary>
 /// Updates albumToUpdate in the "DB"
 /// </summary>
 /// <param name="albumToUpdate"></param>
 /// <returns>true if Album exists, false otherwise</returns>
 public bool Update(Album albumToUpdate)
 {
     if(!AlbumDatabase.ContainsKey(albumToUpdate.Id))
     {
         return false;
     }
     UpdateAlbumFromDBWith(albumToUpdate);
     return true;
 }