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);
		}
	}
}