コード例 #1
0
        public HttpResponseMessage GetSongById(string id)
        {
            logger.Info("Retrieving song with id " + id);

            var possibleSong = playlist.GetById(id);

            if (possibleSong.HasValue)
            {
                logger.Info("Song found by id");
                return(this.Request.CreateResponse(HttpStatusCode.OK, playlist.GetById(id)));
            }
            else
            {
                logger.Warn("Song not found by id");
                return(this.Request.CreateResponse(HttpStatusCode.NotFound));
            }
        }
コード例 #2
0
        public void AddAndRetrieveSong()
        {
            var savedSongId = musicPlaylist.Add(_registerSongRequest);

            var savedSong = musicPlaylist.GetById(savedSongId);

            Assert.AreEqual(savedSong.HasValue, true);
            Assert.AreEqual(savedSong.Value.Artist, "::artist::");
            Assert.AreEqual(savedSong.Value.Title, "::title::");
            Assert.IsTrue(savedSong.Value.Genres.SequenceEqual(new List <string>()
            {
                "pop"
            }));
        }
コード例 #3
0
        /// <summary>
        /// Registers a song.
        /// </summary>
        /// <param name="request">The song request to register.</param>
        /// <returns>The registered song.</returns>
        public Song AddSong(RegisterSongRequest request)
        {
            Song result;

            try
            {
                var songId = playlist.Add(request);
                result = playlist.GetById(songId).GetValueOrDefault(new Song());
            }
            catch (SongAlreadyExistsException e)
            {
                result = new Song();
            }
            catch (Exception e)
            {
                logger.Error(e.ToString());
                System.Diagnostics.Trace.Write(e.ToString());
                result = new Song();
            }

            return(result);
        }