public List<Release> GetReleaseInformationFromXmlForArtistId(XmlDocument xmlDoc, string artistId) { var nsm = new XmlNamespaceManager(xmlDoc.NameTable); nsm.AddNamespace("mbz", "http://musicbrainz.org/ns/mmd-2.0#"); XmlNodeList nodes = xmlDoc.SelectNodes("//mbz:metadata/mbz:release-list/mbz:release", nsm); List<Release> releases = new List<Release>(); foreach (XmlNode node in nodes) { Release release = new Release(); release.ReleaseId = node.Attributes["id"].Value; release.Title = node.SelectSingleNode("mbz:title", nsm).InnerText; release.Status = node.SelectSingleNode("mbz:status", nsm).InnerText; // label is optional if (node.SelectSingleNode("mbz:label-info-list/mbz:label-info/mbz:label/mbz:name", nsm) != null) release.Label = node.SelectSingleNode("mbz:label-info-list/mbz:label-info/mbz:label/mbz:name", nsm).InnerText; release.NumberOfTracks = System.Int32.Parse(node.SelectSingleNode("mbz:medium-list/mbz:track-count", nsm).InnerText ?? "0"); // get the other collaborating artists if any List<NameCredit> nameCredits = new List<NameCredit>(); XmlNodeList creditArtists = node.SelectNodes("mbz:artist-credit/mbz:name-credit/mbz:artist", nsm); foreach (XmlNode creditArtist in creditArtists) { string id = creditArtist.Attributes["id"].Value; // not need to add self as a colaborating artist on one's own release if (id != artistId) { var otherArtist = new NameCredit(); otherArtist.Id = id; otherArtist.Name = creditArtist.SelectSingleNode("mbz:name", nsm).InnerText; nameCredits.Add(otherArtist); } } release.NameCredits = nameCredits; releases.Add(release); } return releases; }
public void ShouldContainReleaseWith_releaseId_title_status_label_NoTracks_ForTestXML() { //arange XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(_path); List<Release> releases = new List<Release>(); MusicBrainzReleaseParser mbzParser = new MusicBrainzReleaseParser(); //act releases = mbzParser.GetReleaseInformationFromXmlForArtistId(xmlDoc, _artistId); //assert Release expectedRelease = new Release(); expectedRelease.Title = "Dharohar Project, Laura Marling and Mumford & Sons"; expectedRelease.Status = "Official"; expectedRelease.ReleaseId = "4cf8c4b7-2471-46cd-8865-f2a744f26e8d"; expectedRelease.Label = "Glassnote Records"; expectedRelease.NumberOfTracks = 4; // too tired to implement IComprarer -> just bruteforced Release actualRelese = new Release(); actualRelese = releases[0]; bool areValuesEqual = expectedRelease.Title == actualRelese.Title && expectedRelease.Status == actualRelese.Status && expectedRelease.ReleaseId == actualRelese.ReleaseId && expectedRelease.Label == actualRelese.Label && expectedRelease.NumberOfTracks == actualRelese.NumberOfTracks; Assert.AreEqual(true, areValuesEqual); }