public void MusicRecordTest1() { MusicRecord record2 = new MusicRecord("MyMusic", new Artist("Madonna", "Sony", "America"), 25.45, 1999, MusicRecord._genre.pop); Assert.AreEqual(record2.Artist.ArtistName, "Madonna"); Assert.AreNotEqual(record2.YearOfPublication, 2001); }
public void Put(int id, [FromBody] MusicRecord value) { MusicRecord newRecord = RecordsList.Find(i => i.Id == id); newRecord.Artist = value.Artist; newRecord.Duration = value.Duration; newRecord.Title = value.Title; newRecord.YearOfPublication = value.YearOfPublication; }
public void AddRecordTest() { int initCount = manager.GetAllRecords().Count; MusicRecord testOb = new MusicRecord("Oxygen", "Three foot crunch", 2011, 200, false); manager.AddRecord(testOb); Assert.AreEqual(initCount + 1, manager.GetAllRecords().Count); }
public IActionResult AddRecord([FromBody] MusicRecord musicRecord) { if (musicRecord == null) { return(BadRequest()); } string response = _manager?.AddRecord(musicRecord); return(Ok(response)); }
public void PutTest() { MusicRecord m1 = new MusicRecord(0, "Lightning", "Splat", 760, 1995); _controller.Put(1, m1); Assert.AreEqual(m1.Title, _controller.List[0].Title); Assert.AreEqual(m1.Artist, _controller.List[0].Artist); Assert.AreEqual(m1.Duration, _controller.List[0].Duration); Assert.AreEqual(m1.YearOfPublication, _controller.List[0].YearOfPublication); }
public int DeleteRecord(string artist, string title) { MusicRecord recordToDelete = MusicRecords.Find(x => x.Title == title && x.Artist == artist); if (recordToDelete == null) { return(0); } MusicRecords.Remove(recordToDelete); return(1); }
public int UpdateRecord(string artist, string title, MusicRecord musicRecord) { MusicRecord recordToUpdate = MusicRecords.Find(x => x.Title == title && x.Artist == artist); if (recordToUpdate == null) { return(0); } MusicRecords.Remove(recordToUpdate); MusicRecords.Add(musicRecord); return(1); }
public void PutRecordTest() { IList <MusicRecord> beforeTestList = new List <MusicRecord>(manager.GetAllRecords()); MusicRecord testRecord = new MusicRecord("testTitle", "testArtist", 7357, 123, false); manager.UpdateRecord("Muse", "Uprising", testRecord); IList <MusicRecord> afterTestList = new List <MusicRecord>(manager.GetAllRecords()); Assert.IsTrue(beforeTestList.Contains(testRecord) == false); Assert.IsTrue(afterTestList.Contains(testRecord)); }
public void Put(string title, [FromBody] MusicRecord value) { if (value != null) { MusicRecord record = Get(title); if (record != null) { record.Artist = value.Artist; record.YearOfPublication = value.YearOfPublication; record.Duration = value.Duration; record.NumberOfTracks = value.NumberOfTracks; } } }
public void RestSearchTest() { MusicRecordQuery query = new MusicRecordQuery(); query.Title = "Dead"; MusicRecord record = new MusicRecord(0, "Dead Rock", "Gorm", 500, 1926); _controller.List.Add(record); IEnumerable <MusicRecord> filteredRecords = _controller.Search(query); Assert.AreEqual(record.Title, filteredRecords.ElementAt(0).Title); query.YearOfPublication = 1950; filteredRecords = _controller.Search(query); Assert.AreEqual(0, filteredRecords.Count()); }
void ITagRequestHandler.UpdateRecord( IEnumerable <BaseData> data, MusicRecord record, double newDouble) { if (data.Count() == 0) { throw new InvalidOperationException( $"Found 0 records to modify for MusicRecord {record.ToString()}"); } foreach (BaseData datum in data) { datum.Weight = newDouble; } }
void ITagRequestHandler.UpdateRecord( IEnumerable <BaseData> data, MusicRecord record, bool newBool) { if (data.Count() == 0) { throw new InvalidOperationException( $"Found 0 records to modify for MusicRecord {record.ToString()}"); } //BaseData firstDatum = data.First(); switch (record) { default: throw new Exception( $"Wrong field type submitted. Submitted {newBool.GetType().ToString()} for " + $"field {record.ToString()}."); } }
private void UpdateRecord(MusicRecord record, TagData tag) { switch (record) { case MusicRecord.SongTitle: case MusicRecord.ArtistName: case MusicRecord.AlbumTitle: case MusicRecord.TrackTitle: case MusicRecord.Filename: if (tag is TagDataString stringTagData) { RequestHandler.UpdateRecord(Data, record, stringTagData.NewValue); } break; case MusicRecord.AlbumYear: case MusicRecord.TrackNumber: case MusicRecord.DiscNumber: if (tag is TagDataInt intTagData) { RequestHandler.UpdateRecord(Data, record, intTagData.NewInt); } break; case MusicRecord.RecordingType: if (tag is TagDataEnum recordingTypeTagData) { RequestHandler.UpdateRecord(Data, record, recordingTypeTagData.NewInt); } break; case MusicRecord.MAX: default: throw new Exception($"Invalid MusicRecord for Updating: {record}"); } }
public void Post([FromBody] MusicRecord value) { int id = list[^ 1].Id + 1;
public void TitleNullException() { MusicRecord record1 = new MusicRecord("", new Artist("Madonna", "Sony", "America"), 25.45, 1999, MusicRecord._genre.pop); }
public void Post([FromBody] MusicRecord value) { Records.Add(value); }
void ITagRequestHandler.UpdateRecord( IEnumerable <BaseData> data, MusicRecord record, int newInt) { if (data.Count() == 0) { throw new InvalidOperationException( $"Found 0 records to modify for MusicRecord {record.ToString()}"); } BaseData firstDatum = data.First(); switch (record) { case MusicRecord.TrackNumber: if (firstDatum is Recording) { //Updating the track number of a track recordingCommands.UpdateTrackNumber(data.Cast <Recording>(), newInt); } else { throw new LibraryContextException( $"Bad Context ({firstDatum}) for RecordUpdate ({record.ToString()})"); } break; case MusicRecord.AlbumYear: if (firstDatum is Album) { //Updating the year that an album was produced albumCommands.UpdateYear(data.Cast <Album>(), newInt); } else if (firstDatum is Recording) { //Updating the year that an album was produced recordingCommands.UpdateYear(data.Cast <Recording>(), newInt); } else { throw new LibraryContextException( $"Bad Context ({firstDatum}) for RecordUpdate ({record.ToString()})"); } break; case MusicRecord.DiscNumber: if (firstDatum is Recording) { //Updating the disc that a track appeared on recordingCommands.UpdateDiscNumber(data.Cast <Recording>(), newInt); } else { throw new LibraryContextException( $"Bad Context ({firstDatum}) for RecordUpdate ({record.ToString()})"); } break; case MusicRecord.RecordingType: if (firstDatum is Recording) { //Update RecordingType recordingCommands.UpdateRecordingType(data.Cast <Recording>(), (RecordingType)newInt); } else { throw new LibraryContextException( $"Bad Context ({firstDatum}) for RecordUpdate ({record.ToString()})"); } break; default: throw new Exception( $"Wrong field type submitted. Submitted {newInt.GetType().ToString()} for " + $"field {record.ToString()}."); } }
public IActionResult UpdateRecord([FromQuery] string artist, [FromQuery] string title, [FromBody] MusicRecord musicRecord) { if (String.IsNullOrEmpty(artist) || String.IsNullOrEmpty(title) || musicRecord == null) { return(BadRequest()); } int result = _manager.UpdateRecord(artist, title, musicRecord); if (result == 0) { return(NotFound("No record to update")); } return(Ok(result)); }
/// <summary> /// Make sure to translate the ID to the right context before calling this method. /// </summary> /// <param name="context"></param> /// <param name="id"></param> /// <param name="record"></param> /// <param name="newString"></param> /// <exception cref="LibraryContextException"/> void ITagRequestHandler.UpdateRecord( IEnumerable <BaseData> data, MusicRecord record, string newString) { if (data.Count() == 0) { throw new InvalidOperationException( $"Found 0 records to modify for MusicRecord {record.ToString()}"); } BaseData firstDatum = data.First(); switch (record) { case MusicRecord.SongTitle: if (firstDatum is Song) { //Renaming (or Consolidating) Songs songCommands.UpdateSongTitle(data.Cast <Song>(), newString); } else if (firstDatum is Recording) { //Splitting, Renaming, And/Or Consolidating Tracks by Song Title recordingCommands.UpdateSongTitle(data.Cast <Recording>(), newString); } else { throw new LibraryContextException( $"Bad Context ({firstDatum}) for RecordUpdate ({record.ToString()})"); } break; case MusicRecord.ArtistName: if (firstDatum is Artist) { //Renaming and collapsing Artists artistCommands.UpdateArtistName(data.Cast <Artist>(), newString); } else if (firstDatum is Recording) { //Assinging Songs to a different artist recordingCommands.UpdateArtistName(data.Cast <Recording>(), newString); } else { throw new LibraryContextException( $"Bad Context ({firstDatum}) for RecordUpdate ({record.ToString()})"); } break; case MusicRecord.AlbumTitle: if (firstDatum is Album) { //Renaming and collapsing Albums albumCommands.UpdateAlbumTitle(data.Cast <Album>(), newString); } else if (firstDatum is Recording) { //Assigning a track to a different album recordingCommands.UpdateAlbumTitle(data.Cast <Recording>(), newString); } else { throw new LibraryContextException( $"Bad Context ({firstDatum}) for RecordUpdate ({record.ToString()})"); } break; case MusicRecord.TrackTitle: if (firstDatum is Recording) { //Renaming and collapsing Albums recordingCommands.UpdateRecordingTitle(data.Cast <Recording>(), newString); } else { throw new LibraryContextException( $"Bad Context ({firstDatum}) for RecordUpdate ({record.ToString()})"); } break; default: throw new Exception( $"Wrong field type submitted. Submitted {newString.GetType().ToString()} for " + $"field {record.ToString()}."); } }
public string AddRecord(MusicRecord musicRecord) { MusicRecords.Add(musicRecord); return($"Record added: {musicRecord.Title} - {musicRecord.Artist}"); }