commit 4a541ca04b00c1f24133fad5a740b35ca0c05163 Author: poprhythm Date: Sun May 10 02:49:16 2026 +0000 Initial commit — AllMusicGuide scraper and music metadata tagger diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4608639 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +bin/ +obj/ +packages/ +_ReSharper*/ +*.suo +*.user +.vs/ diff --git a/Client.AllMusicGuide.Tests/Client.AllMusicGuide.Tests.csproj b/Client.AllMusicGuide.Tests/Client.AllMusicGuide.Tests.csproj new file mode 100644 index 0000000..72eb5ba --- /dev/null +++ b/Client.AllMusicGuide.Tests/Client.AllMusicGuide.Tests.csproj @@ -0,0 +1,112 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {52212AC5-FABA-4ED5-A6A3-5D221BC59D8B} + Library + Properties + MusicMetaTagger.Client.AllMusicGuide.Tests + MusicMetaTagger.Client.AllMusicGuide.Tests + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\NSubstitute.1.4.3.0\lib\NET40\NSubstitute.dll + + + ..\packages\NUnit.2.6.2\lib\nunit.framework.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {A86C05AB-9720-4D6E-AC5E-9CDE6364945A} + Client.AllMusicGuide + + + {EDA98A07-0BF5-4FEE-B341-D8A6A7E581F5} + Core + + + + + + copy /z "$(ProjectDir)RemoteDataAccess\Parser\Documents\*" "$(TargetDir)" + + + \ No newline at end of file diff --git a/Client.AllMusicGuide.Tests/EqualityTester.cs b/Client.AllMusicGuide.Tests/EqualityTester.cs new file mode 100644 index 0000000..e8b15c3 --- /dev/null +++ b/Client.AllMusicGuide.Tests/EqualityTester.cs @@ -0,0 +1,271 @@ +using System; +using System.Collections; +using System.Globalization; + +namespace MusicMetaTagger.Client.AllMusicGuide.Tests +{ + /// + /// A static unit testing helper class that can test two objects + /// to see if they are equal. + /// + /// + /// This class does not rely on Object.Equals to insure that reference types + /// are equal. Instead, it compares all public properties of + /// reference types recursively (eventually arriving at value types). If the properties are the same, + /// then the objects are assuemd to be equal. This may be changed + /// to an optional behavior later on (if anyone has a need for that kind of thing). + /// + /// MBH + /// 11/29/04 + public class EqualityTester + { + /// + /// When set to true, DateTime objects may differ by < 1 second and still + /// be considered equal. + /// + private static bool _fuzzyDateMatching; + + /// + /// This is a hack to insure 100% test coverage + /// + static EqualityTester() + { + new EqualityTester(); + } + + /// + /// This is a static class, so it cannot be instantiated directly + /// + private EqualityTester() + { + } + + /// + /// When set to true, DateTime objects may differ by < 1 second and still + /// be considered equal. + /// + public static bool FuzzyDateMatching + { + get { return _fuzzyDateMatching; } + set { _fuzzyDateMatching = value; } + } + + /// + /// Asserts that the result of enumerating two IEnumerable objects + /// are identical. + /// + /// The first IEnumerable object + /// The second IEnumerable object + private static void AssertIEnumerablesEqual(object o1, object o2) + { + var enumerator1 = ((IEnumerable) o1).GetEnumerator(); + var enumerator2 = ((IEnumerable) o2).GetEnumerator(); + + var enumerator1Valid = enumerator1.MoveNext(); + var enumerator2Valid = enumerator2.MoveNext(); + + while (enumerator1Valid && enumerator2Valid) + { + //The two values from the enumerators + + var value1 = enumerator1.Current; + + var value2 = enumerator2.Current; + + AssertEqual(value1, value2); + + enumerator1Valid = enumerator1.MoveNext(); + enumerator2Valid = enumerator2.MoveNext(); + } + + //If an enumerator is still valid, that means it had more items in it than the other + if (enumerator1Valid) + throw (new NotSupportedException("The first IEnumerable object had more items in it than the second.")); + + if (enumerator2Valid) + throw (new NotSupportedException("The second IEnumerable object had more items in it than the first.")); + } + + /// + /// Asserts that two reference-types are equal by comparing their properties. + /// + /// The first object. + /// The second object. + /// + private static void AssertReferencesEqual(object o1, object o2) + { + //At this point, it really shouldn't be possible for two things to be of differing types, so no check is performed. + + var t = o1.GetType(); + + //Strings are a special case + if (t == typeof (string)) + { + //If the strings aren't equal, fail + if (!o1.Equals(o2)) + { + throw (new NotSupportedException("Strings are not equal: '" + o1 + "' != '" + o2 + "'")); + } + } + + if (t.GetInterface("IEnumerable") != null || t.IsArray) + AssertIEnumerablesEqual(o1, o2); + + //Assert that all public properties are equal + var properties = t.GetProperties(); + + var isICollection = t.GetInterface("ICollection") != null; + + foreach (var property in properties) + { + //If this is a collection, skip the SyncRoot property since + //that can vary even if collections have identicial members + if (isICollection && property.Name == "SyncRoot") + continue; + + //Skip Capacity on ICollections, too, since that can change + if (isICollection && property.Name == "Capacity") + continue; + + var getMethod = property.GetGetMethod(); + + if (getMethod.GetParameters().Length > 0) + //this property is an indexer and cannot be checked. If the object implemeneted + //IEnumerable, it was probably checked above. + continue; + + { + var value1 = getMethod.Invoke(o1, new object[] {}); + + var value2 = getMethod.Invoke(o2, new object[] {}); + + //See if either result is null + if (value1 == null || value2 == null) + { + //If either one is null, they both better be or the test failed. + if (value1 != null || value2 != null) + throw (new NotSupportedException("Object property accessor returned one null, one not-null for " + getMethod.Name)); + continue; + } + + if (value1.GetType().IsValueType) + { + try + { + AssertValuesEqual(value1, value2); + } + catch (NotSupportedException ex) + { + var errorMessage = String.Format("Property '{0}' failed equality check. The inner exception is the reason.", + property.Name); + throw (new NotSupportedException(errorMessage, ex)); + } + } + //Don't recurse down the array graph, it's self referencing and will overflow the stack. + else if (!(t.IsArray && value1.GetType().IsArray)) + { + try + { + AssertReferencesEqual(value1, value2); + } + catch (NotSupportedException ex) + { + var errorMessage = String.Format("Property '{0}' failed equality check. The inner exception is the reason.", + property.Name); + throw (new NotSupportedException(errorMessage, ex)); + } + } + } + } + } + + /// + /// Asserts that two value types are equal. + /// + /// The first value. + /// The second value + /// Thrown if the values aren't equal. + private static void AssertValuesEqual(object o1, object o2) + { + if (o1 is DateTime) + { + AssertDateTimesEqual((DateTime) o1, (DateTime) o2); + } + else if (!o1.Equals(o2)) + throw (new NotSupportedException(String.Format("Values not equal: '{0}' != '{1}'", o1, o2))); + } + + /// + /// Asserts that two DateTime objects are equal. + /// + /// + /// + private static void AssertDateTimesEqual(DateTime dateTime1, DateTime dateTime2) + { + if (_fuzzyDateMatching) + { + if (dateTime1 - dateTime2 > TimeSpan.FromSeconds(1) || dateTime1 - dateTime2 < TimeSpan.FromSeconds(-1)) + throw (new NotSupportedException( + String.Format("DateTime's differ by more than 1 second with fuzzy matching enabled: '{0}' != '{1}'.", dateTime1, + dateTime2))); + } + else if (dateTime1 != dateTime2) + throw (new NotSupportedException(String.Format("Values not equal: '{0}' != '{1}'", dateTime1.ToString(CultureInfo.InvariantCulture), + dateTime2.ToString(CultureInfo.InvariantCulture)))); + } + + /// + /// Asserts that all public properties on the specified objects + /// are equal. + /// + /// The first object + /// The second object + /// Thrown if the two objects are of different types, indicating an internal error. + /// Thrown if the objects aren't equal. + /// + /// o1 and o2 must be of the same type. + /// + public static void AssertEqual(object o1, object o2) + { + if (o1 == null || o2 == null) + { + //Both values better be null... + if (o1 != null || o2 != null) + throw (new NotSupportedException("One value type was null while the other was not.")); + return; + } + + if (o1.GetType() != o2.GetType()) + throw (new InvalidOperationException("AssertEqual called with objects of differing types: " + o1.GetType().Name + + ", " + o2.GetType().Name)); + + var t = o1.GetType(); + + if (t.IsValueType) + AssertValuesEqual(o1, o2); + else + AssertReferencesEqual(o1, o2); + } + + /// + /// Recursively tests that all public properties on the specified objects are equal. + /// + /// + /// + /// Thrown if the two objects are not of the same type. + /// true if the objects are equal, false otherwise. + public static bool AreEqual(object o1, object o2) + { + try + { + AssertEqual(o1, o2); + } + catch (NotSupportedException) + { + return false; + } + + return true; + } + } +} \ No newline at end of file diff --git a/Client.AllMusicGuide.Tests/Properties/AssemblyInfo.cs b/Client.AllMusicGuide.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..901fd6f --- /dev/null +++ b/Client.AllMusicGuide.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("MusicMetaTagger.Client.AllMusicGuide.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MusicMetaTagger.Client.AllMusicGuide.Tests")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("fa867999-d234-453f-bbed-d2f85dd65b83")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Client.AllMusicGuide.Tests/RemoteDataAccess/Client/WebXmlClientTests.cs b/Client.AllMusicGuide.Tests/RemoteDataAccess/Client/WebXmlClientTests.cs new file mode 100644 index 0000000..7214a66 --- /dev/null +++ b/Client.AllMusicGuide.Tests/RemoteDataAccess/Client/WebXmlClientTests.cs @@ -0,0 +1,64 @@ +using System; +using MusicMetaTagger.Client.AllMusicGuide.RemoteDataAccess.Client; +using NUnit.Framework; + +namespace MusicMetaTagger.Client.AllMusicGuide.Tests.RemoteDataAccess.Client +{ + [TestFixture] + public class WebXmlClientTests + { + [Test, Explicit] + public void GetTestHtml() + { + var songClient = new SongClient(); + songClient.Read("hey-jude-mt0002046073").Save("Song-HeyJude.xml"); + + var albumClient = new AlbumClient(); + albumClient.Read("abbey-road-mw0000192938").Save("Album-AbbeyRoad.xml"); + albumClient.Read("girls-can-tell-mw0000624315").Save("Album-GirlsCanTell.xml"); + albumClient.Read("kill-the-moonlight-mw0000222379").Save("Album-KillTheMoonlight.xml"); + albumClient.Read("magnolia-original-motion-picture-score-mw0000605476").Save("Album-MagnoliaScore.xml"); + albumClient.Read("pulp-fiction-mw0000118528").Save("Album-PulpFiction.xml"); + albumClient.Read("re-ac-tor-mw0000717742").Save("Album-Reactor.xml"); + albumClient.Read("wipers-box-set-mw0000541566").Save("Album-WipersBoxSet.xml"); + albumClient.Read("miike-snow-mw0000818771").Save("Album-MiikeSnow.xml"); + albumClient.Read("superwolf-mw0000363531").Save("Album-Superwolf.xml"); + albumClient.Read("dark-was-the-night-red-hot-compilation-mw0000807845").Save("Album-DarkWasTheNight.xml"); + albumClient.Read("true-love-waits-christopher-oriley-plays-radiohead-mw0000631718").Save("Album-TrueLoveWaits.xml"); + + var albumResultClient = new AlbumResultPageClient(); + albumResultClient.Read("abbey road").Save("AlbumResults-AbbeyRoad.xml"); + + var artistClient = new ArtistClient(); + artistClient.Read("the-beatles-mn0000754032").Save("Artist-Beatles.xml"); + artistClient.Read("spoon-mn0000131038").Save("Artist-Spoon.xml"); + artistClient.Read("neil-young-mn0000379125").Save("Artist-NeilYoung.xml"); + artistClient.Read("wipers-mn0000485791").Save("Artist-Wipers.xml"); + artistClient.Read("bonnie-prince-billy-mn0000094764").Save("Artist-BonniePrinceBilly.xml"); + + var artistDiscographyAlbumPageClient = new ArtistDiscographyAlbumPageClient(); + artistDiscographyAlbumPageClient.Read("spoon-mn0000131038").Save("ArtistAlbums-Spoon.xml"); + + var artistDiscographyCompilationPageClient = new ArtistDiscographyCompilationPageClient(); + artistDiscographyCompilationPageClient.Read("the-beatles-mn0000754032").Save("ArtistCompilations-Beatles.xml"); + artistDiscographyCompilationPageClient.Read("wipers-mn0000485791").Save("ArtistCompilations-Wipers.xml"); + + var artistDiscographyEpSinglesPageClient = new ArtistDiscographyEpSinglesPageClient(); + artistDiscographyEpSinglesPageClient.Read("the-beatles-mn0000754032").Save("ArtistSingles-Beatles.xml"); + + var artistResultPageClient = new ArtistResultPageClient(); + artistResultPageClient.Read("spoon").Save("ArtistResults-Spoon.xml"); + + var songResultsPageClient = new SongResultPageClient(); + songResultsPageClient.Read("Hey, Snow White").Save("SongResults-HeySnowWhite.xml"); + } + + [Test, Explicit] + public void HtmlScraperTest() + { + var url = new Uri("http://www.google.com"); + var xml = WebXmlClient.GetHtmlXml(url); + Assert.IsNotNull(xml); + } + } +} \ No newline at end of file diff --git a/Client.AllMusicGuide.Tests/RemoteDataAccess/Client/XmlClientBaseTests.cs b/Client.AllMusicGuide.Tests/RemoteDataAccess/Client/XmlClientBaseTests.cs new file mode 100644 index 0000000..c80548e --- /dev/null +++ b/Client.AllMusicGuide.Tests/RemoteDataAccess/Client/XmlClientBaseTests.cs @@ -0,0 +1,26 @@ +using System.Xml; +using MusicMetaTagger.Client.AllMusicGuide.RemoteDataAccess.Client; +using NUnit.Framework; + +namespace MusicMetaTagger.Client.AllMusicGuide.Tests.RemoteDataAccess.Client +{ + public class GoogleXmlClient : XmlClientBase + { + public override XmlDocument Read(string criteria) + { + return ReadFromCriteria("http://google.com/?q={0}", criteria); + } + } + + [TestFixture] + public class XmlClientBaseTests + { + [Test, Explicit] + public void ReadsDocument() + { + var client = new GoogleXmlClient(); + var xmlDocument = client.Read("banana"); + Assert.That(xmlDocument.InnerText.Contains("banana")); + } + } +} diff --git a/Client.AllMusicGuide.Tests/RemoteDataAccess/MusicGuideScraperTests.cs b/Client.AllMusicGuide.Tests/RemoteDataAccess/MusicGuideScraperTests.cs new file mode 100644 index 0000000..f0b5743 --- /dev/null +++ b/Client.AllMusicGuide.Tests/RemoteDataAccess/MusicGuideScraperTests.cs @@ -0,0 +1,52 @@ +using System; +using MusicMetaTagger.Client.AllMusicGuide.RemoteDataAccess; +using MusicMetaTagger.Client.AllMusicGuide.RemoteDataAccess.Scraper; +using NUnit.Framework; + +namespace MusicMetaTagger.Client.AllMusicGuide.Tests.RemoteDataAccess +{ + [TestFixture] + public class MusicGuideScraperTests + { + private MusicGuideScraper _musicGuideScraper; + + [SetUp] + public void SetUp() + { + _musicGuideScraper = new MusicGuideScraper( + new AlbumScraper(), new AlbumResultPageScraper(), + new ArtistScraper(), new ArtistResultPageScraper(), new ArtistDiscographyScraper(), + new SongResultPageScraper(), new SongScraper()); + } + + [Test, Explicit] + public void SearchArtist_SmokeTest() + { + var artistResults = _musicGuideScraper.SearchArtist("Beech Boys"); + foreach (var artistResult in artistResults) + { + Console.WriteLine("{0}, {1}, {2}", artistResult.ArtistName, artistResult.ResultOrder, artistResult.YearsActive); + } + } + + [Test, Explicit] + public void SearchAlbum_SmokeTest() + { + var albumResults = _musicGuideScraper.SearchAlbum("smile sessions"); + foreach (var albumResult in albumResults) + { + Console.WriteLine("{0}, {1}, {2}", albumResult.ArtistName, albumResult.ResultOrder, albumResult.AlbumTitle); + } + } + + [Test, Explicit] + public void SearchSong_SmokeTest() + { + var albumResults = _musicGuideScraper.SearchSong("...and the World Laughs With You"); + foreach (var albumResult in albumResults) + { + Console.WriteLine("{0}, {1}, {2}", albumResult.ArtistName, albumResult.SongTitle, albumResult.ResultOrder); + } + } + } +} diff --git a/Client.AllMusicGuide.Tests/RemoteDataAccess/Parser/AlbumParserTests.cs b/Client.AllMusicGuide.Tests/RemoteDataAccess/Parser/AlbumParserTests.cs new file mode 100644 index 0000000..f46449f --- /dev/null +++ b/Client.AllMusicGuide.Tests/RemoteDataAccess/Parser/AlbumParserTests.cs @@ -0,0 +1,106 @@ +using System; +using System.Xml; +using MusicMetaTagger.Client.AllMusicGuide.RemoteDataAccess.Parser; +using NUnit.Framework; + +namespace MusicMetaTagger.Client.AllMusicGuide.Tests.RemoteDataAccess.Parser +{ + [TestFixture] + public class AlbumParserTests + { + [Test] + public void IsSoundtrack() + { + var pf = new XmlDocument(); + pf.Load("Album-PulpFiction.xml"); + var pulpFiction = new AlbumParser().Parse(pf); + + Assert.IsTrue(pulpFiction.Soundtrack); + Assert.That(pulpFiction.ArtistName, Is.EqualTo("Various Artists")); + Assert.That(pulpFiction.ArtistId, Is.Null); + } + + [Test] + public void ParsesScore() + { + var mag = new XmlDocument(); + mag.Load("Album-MagnoliaScore.xml"); + var album = new AlbumParser().Parse(mag); + Assert.IsNotNull(album); + } + + [Test] + public void ParsesMultipleArtists() + { + var xml = new XmlDocument(); + xml.Load("Album-Superwolf.xml"); + var superwolf = new AlbumParser().Parse(xml); + + Assert.That(superwolf.ArtistName, Is.EqualTo("Bonnie \"Prince\" Billy")); + Assert.That(superwolf.ArtistId, Is.EqualTo("mn0000094764")); + } + + [Test] + public void ParsesTrueLoveWaits() + { + var xml = new XmlDocument(); + xml.Load("Album-TrueLoveWaits.xml"); + var trueLoveWaits = new AlbumParser().Parse(xml); + + Assert.That(trueLoveWaits.ArtistName, Is.EqualTo("Christopher O'Riley")); + Assert.That(trueLoveWaits.ArtistId, Is.EqualTo("mn0000043765")); + Assert.That(trueLoveWaits.Tracks.Count, Is.EqualTo(15)); + } + + [Test] + public void PopulateTest() + { + var ar = new XmlDocument(); + ar.Load("Album-AbbeyRoad.xml"); + var abbeyRoad = new AlbumParser().Parse(ar); + + Assert.AreEqual("Abbey Road", abbeyRoad.Title); + Assert.AreEqual("September 26, 1969", abbeyRoad.ReleaseDate); + Assert.AreEqual("http://cps-static.rovicorp.com/3/JPG_250/MI0002/910/MI0002910443.jpg", abbeyRoad.CoverUrl); + Assert.That(abbeyRoad.Styles.Count, Is.GreaterThan(1)); + Assert.IsTrue(abbeyRoad.Moods.Count > 0); + Assert.IsTrue(abbeyRoad.Review.Length > 0); + Assert.IsTrue(abbeyRoad.Themes.Count > 0); + Assert.AreEqual("The Beatles", abbeyRoad.ArtistName); + Assert.AreEqual("Richie Unterberger", abbeyRoad.Reviewer); + Assert.AreEqual("mn0000754032", abbeyRoad.ArtistId); + Assert.AreEqual("mw0000192938", abbeyRoad.AlbumId); + Assert.AreEqual(10, abbeyRoad.Rating); + Assert.Less(1, abbeyRoad.Review.Length); + Assert.IsFalse(abbeyRoad.Soundtrack); + + // track check + Assert.That(abbeyRoad.Tracks.Count, Is.EqualTo(17)); + var firstTrack = abbeyRoad.Tracks[0]; + + Assert.AreEqual(1, firstTrack.TrackNumber); + Assert.AreEqual("mt0010100291", firstTrack.TrackId); + Assert.IsTrue(firstTrack.Pick); + Assert.AreEqual(firstTrack.TrackLength, new TimeSpan(0, 4, 19)); + Assert.AreEqual(abbeyRoad.AlbumId, firstTrack.AlbumId); + Assert.AreEqual("mn0000754032", firstTrack.PerformerIds[0]); + + + var gct = new XmlDocument(); + gct.Load("Album-GirlsCanTell.xml"); + var girlsCanTell = new AlbumParser().Parse(gct); + + Assert.IsTrue(girlsCanTell.Pick); + } + + [Test] + public void SerializationTest() + { + var ar = new XmlDocument(); + ar.Load("Album-AbbeyRoad.xml"); + var abbeyRoad = new AlbumParser().Parse(ar); + + SerializationTester.AssertBinarySerializable(abbeyRoad); + } + } +} \ No newline at end of file diff --git a/Client.AllMusicGuide.Tests/RemoteDataAccess/Parser/AlbumResultTests.cs b/Client.AllMusicGuide.Tests/RemoteDataAccess/Parser/AlbumResultTests.cs new file mode 100644 index 0000000..8ca8621 --- /dev/null +++ b/Client.AllMusicGuide.Tests/RemoteDataAccess/Parser/AlbumResultTests.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic; +using System.Xml; +using MusicMetaTagger.Client.AllMusicGuide.RemoteDataAccess.Parser; +using MusicMetaTagger.Core.Model; +using NUnit.Framework; + +namespace MusicMetaTagger.Client.AllMusicGuide.Tests.RemoteDataAccess.Parser +{ + [TestFixture] + public class AlbumResultTests + { + private IList _albumResults; + + [SetUp] + public void SetUp() + { + var doc = new XmlDocument(); + doc.Load("AlbumResults-AbbeyRoad.xml"); + _albumResults = new AlbumResultPageParser().Parse(doc); + } + + [Test] + public void AlbumResultsTestSuite() + { + Assert.IsTrue(_albumResults.Count > 0); + var resultInfo = _albumResults[0]; + Assert.AreEqual("The Beatles", resultInfo.ArtistName); + Assert.AreEqual(1, resultInfo.ResultOrder); + Assert.AreEqual("mw0000192938", resultInfo.AlbumId); + Assert.AreEqual("Pop/Rock", resultInfo.Genre); + Assert.AreEqual(1969, resultInfo.Year); + Assert.AreEqual("Abbey Road", resultInfo.AlbumTitle); + + Assert.AreNotEqual("The Beatles", _albumResults[1].ArtistName); + } + + [Test] + public void AssertSerializableTest() + { + SerializationTester.AssertBinarySerializable(_albumResults); + } + } +} \ No newline at end of file diff --git a/Client.AllMusicGuide.Tests/RemoteDataAccess/Parser/ArtistDiscographyPageParserTests.cs b/Client.AllMusicGuide.Tests/RemoteDataAccess/Parser/ArtistDiscographyPageParserTests.cs new file mode 100644 index 0000000..0566749 --- /dev/null +++ b/Client.AllMusicGuide.Tests/RemoteDataAccess/Parser/ArtistDiscographyPageParserTests.cs @@ -0,0 +1,100 @@ +using System.Xml; +using MusicMetaTagger.Client.AllMusicGuide.RemoteDataAccess.Parser; +using MusicMetaTagger.Core.Model; +using NUnit.Framework; + +namespace MusicMetaTagger.Client.AllMusicGuide.Tests.RemoteDataAccess.Parser +{ + [TestFixture] + public class ArtistDiscographyPageParserTests + { + private XmlDocument _albumsDoc; + private XmlDocument _compilationsDoc; + private XmlDocument _singlesDoc; + private ArtistDiscographyPageParser _parser; + + [SetUp] + public void SetUp() + { + _albumsDoc = new XmlDocument(); + _albumsDoc.Load("ArtistAlbums-Spoon.xml"); + _compilationsDoc = new XmlDocument(); + _compilationsDoc.Load("ArtistCompilations-Beatles.xml"); + _singlesDoc = new XmlDocument(); + _singlesDoc.Load("ArtistSingles-Beatles.xml"); + _parser = new ArtistDiscographyPageParser(); + } + + [Test] + public void Album_DiscographyTestSuite() + { + var discography = _parser.Parse(_albumsDoc); + Assert.That(discography.Count, Is.EqualTo(8)); + + var seriesOfSneaks = discography.Find(a => a.AlbumTitle == "Series of Sneaks"); + var girlsCanTell = discography.Find(a => a.AlbumTitle == "Girls Can Tell"); + + // picks + Assert.That(!seriesOfSneaks.Pick); + Assert.That(girlsCanTell.Pick); + + // rating + Assert.That(seriesOfSneaks.Rating, Is.EqualTo(7)); + Assert.That(girlsCanTell.Rating, Is.EqualTo(8)); + + // id + Assert.That(seriesOfSneaks.AlbumId, Is.EqualTo("mw0000226059")); + Assert.That(girlsCanTell.AlbumId, Is.EqualTo("mw0000624315")); + + // year + Assert.That(seriesOfSneaks.Year, Is.EqualTo(1998)); + Assert.That(girlsCanTell.Year, Is.EqualTo(2001)); + + // type + Assert.That(seriesOfSneaks.ReleaseType, Is.EqualTo(ReleaseType.Album)); + Assert.That(girlsCanTell.ReleaseType, Is.EqualTo(ReleaseType.Album)); + + // artist name + Assert.That(seriesOfSneaks.ArtistName, Is.EqualTo("Spoon")); + Assert.That(seriesOfSneaks.ArtistId, Is.EqualTo("mn0000131038")); + } + + [Test] + public void Singles_DiscographyTestSuite() + { + var discography = _parser.Parse(_singlesDoc); + Assert.That(discography.Count, Is.EqualTo(52)); + + var allMyLoving = discography.Find(a => a.AlbumTitle.StartsWith("All My Loving")); + var something = discography.Find(a => a.AlbumTitle == "Something"); + var yesterday = discography.Find(a => a.AlbumTitle == "Yesterday"); + + // Release Type + Assert.That(allMyLoving.ReleaseType, Is.EqualTo(ReleaseType.EP)); + Assert.That(something.ReleaseType, Is.EqualTo(ReleaseType.Single)); + Assert.That(yesterday.ReleaseType, Is.EqualTo(ReleaseType.Single)); + } + + [Test] + public void Compilations_DiscographyTestSuite() + { + var discography = _parser.Parse(_compilationsDoc); + Assert.That(discography.Count, Is.EqualTo(197)); + + var theEarlyBeatles = discography.Find(a => a.AlbumTitle == "The Early Beatles"); + var pastMastersVol1 = discography.Find(a => a.AlbumTitle == "Past Masters, Vol. 1"); + var one = discography.Find(a => a.AlbumTitle == "1"); + var monoBoxSet = discography.Find(a => a.AlbumTitle == "The Beatles: Mono Box Set"); + + // Release Type + Assert.That(theEarlyBeatles.ReleaseType, Is.EqualTo(ReleaseType.Compilation)); + Assert.That(pastMastersVol1.ReleaseType, Is.EqualTo(ReleaseType.Compilation)); + Assert.That(one.ReleaseType, Is.EqualTo(ReleaseType.Compilation)); + Assert.That(monoBoxSet.ReleaseType, Is.EqualTo(ReleaseType.BoxSet)); + + // Pick + Assert.That(pastMastersVol1.Pick, Is.False); + Assert.That(one.Pick, Is.True); + } + } +} \ No newline at end of file diff --git a/Client.AllMusicGuide.Tests/RemoteDataAccess/Parser/ArtistParserTests.cs b/Client.AllMusicGuide.Tests/RemoteDataAccess/Parser/ArtistParserTests.cs new file mode 100644 index 0000000..35f88b3 --- /dev/null +++ b/Client.AllMusicGuide.Tests/RemoteDataAccess/Parser/ArtistParserTests.cs @@ -0,0 +1,31 @@ +using System.Xml; +using MusicMetaTagger.Client.AllMusicGuide.RemoteDataAccess.Parser; +using MusicMetaTagger.Core.Model; +using NUnit.Framework; + +namespace MusicMetaTagger.Client.AllMusicGuide.Tests.RemoteDataAccess.Parser +{ + [TestFixture] + public class ArtistParserTests + { + private Artist _artist; + + [SetUp] + public void SetUp() + { + var artistDoc = new XmlDocument(); + artistDoc.Load("Artist-Spoon.xml"); + + _artist = new ArtistParser().Parse(artistDoc); + } + + [Test] + public void ArtistInfoTestSuite() + { + Assert.AreEqual("mn0000131038", _artist.ArtistId); + Assert.AreEqual("Pop/Rock", _artist.Genre); + Assert.Less(1, _artist.Styles.Count); + SerializationTester.AssertBinarySerializable(_artist); + } + } +} \ No newline at end of file diff --git a/Client.AllMusicGuide.Tests/RemoteDataAccess/Parser/ArtistResultTests.cs b/Client.AllMusicGuide.Tests/RemoteDataAccess/Parser/ArtistResultTests.cs new file mode 100644 index 0000000..abe9d5f --- /dev/null +++ b/Client.AllMusicGuide.Tests/RemoteDataAccess/Parser/ArtistResultTests.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; +using System.Xml; +using MusicMetaTagger.Client.AllMusicGuide.RemoteDataAccess.Parser; +using MusicMetaTagger.Core.Model; +using NUnit.Framework; + +namespace MusicMetaTagger.Client.AllMusicGuide.Tests.RemoteDataAccess.Parser +{ + [TestFixture] + public class ArtistResultTests + { + private List _artistResults; + + [SetUp] + public void SetUp() + { + var doc = new XmlDocument(); + doc.Load("ArtistResults-Spoon.xml"); + var artistParser = new ArtistResultPageParser(); + _artistResults = artistParser.Parse(doc); + } + + [Test] + public void ArtistResultsTestSuite() + { + Assert.That(_artistResults.Count, Is.GreaterThan(1)); + + var artistResultInfo = _artistResults[0]; + Assert.AreEqual("Spoon", artistResultInfo.ArtistName); + Assert.AreEqual(1, artistResultInfo.ResultOrder); + Assert.AreEqual("Pop/Rock", artistResultInfo.Genre); + Assert.AreEqual("1990s - 2010s", artistResultInfo.YearsActive); + + Assert.That(_artistResults[2].Genre, Is.Not.StringContaining("Pop/Rock")); + + SerializationTester.AssertBinarySerializable(_artistResults); + } + } +} \ No newline at end of file diff --git a/Client.AllMusicGuide.Tests/RemoteDataAccess/Parser/Documents/Album-AbbeyRoad.xml b/Client.AllMusicGuide.Tests/RemoteDataAccess/Parser/Documents/Album-AbbeyRoad.xml new file mode 100644 index 0000000..6962c2f --- /dev/null +++ b/Client.AllMusicGuide.Tests/RemoteDataAccess/Parser/Documents/Album-AbbeyRoad.xml @@ -0,0 +1,1133 @@ + + + + + + + + + + + + + + + + + + + + Abbey Road - The Beatles : Songs, Reviews, Credits, Awards : AllMusic + + + + + +
+ +
+
+ +
+
+ + + +
+

+ Abbey Road by The Beatles on AllMusic +

+ +
+ Abbey Road
+
+
+