using System;
using System.Diagnostics;
using LeafWeb.Core.Entities;
using LeafWeb.Core.Parsers;
using LeafWeb.Core.Utility;
using NUnit.Framework;

namespace LeafWeb.Core.Tests.Parsers
{
	[TestFixture]
	public class LeafGasComparisonParserTests
	{
		private const string ContentDirectory = @"Parsers\LeafOutputData\";

		[Test]
		public void Parse_Valid()
		{
			var fileInfo = FileUtility.GetContentFile(ContentDirectory, "leafgascomparison.csv");

			LeafGasComparison[] leafGasComparisons;
			using (var parser = new LeafGasComparisonParser(fileInfo))
				leafGasComparisons = parser.Parse();

			Assert.That(leafGasComparisons.Length, Is.EqualTo(6));
		}

		[Test]
		public void Parse_MatchCurveId()
		{
			var fileInfo = FileUtility.GetContentFile(ContentDirectory, "multiple_leafgascomparison.csv");

			LeafGasComparison[] leafGasComparisons;
			using (var parser = new LeafGasComparisonParser(fileInfo))
				leafGasComparisons = parser.Parse();

			Assert.That(leafGasComparisons.Length, Is.GreaterThan(6));

			using (var parser = new LeafGasComparisonParser(fileInfo))
				leafGasComparisons = parser.Parse("522Jen1.csv");

			Assert.That(leafGasComparisons.Length, Is.EqualTo(6));
		}

		[Test]
		public void ExtractCurveIds_Single()
		{
			var fileInfo = FileUtility.GetContentFile(ContentDirectory, "leafgascomparison.csv");

			string[] curveIds;
			using (var parser = new LeafGasComparisonParser(fileInfo))
				curveIds = parser.ExtractCurveIds();

			Assert.That(curveIds.Length, Is.EqualTo(1));
		}

		[Test]
		public void ExtractCurveIds_Multiple()
		{
			var fileInfo = FileUtility.GetContentFile(ContentDirectory, "multiple_leafgascomparison.csv");

			string[] curveIds;
			using (var parser = new LeafGasComparisonParser(fileInfo))
				curveIds = parser.ExtractCurveIds();

			Assert.That(curveIds.Length, Is.EqualTo(3));
		}

		//[Test, Explicit]
		public void Parse_Timer()
		{
			var smallFileInfo = FileUtility.GetContentFile(ContentDirectory, "leafgascomparison.csv");
			var largeFileInfo = FileUtility.GetContentFile(@"c:\temp\", "20160411095955C3_leafgascomparison.csv");
			var timer = new Stopwatch();

			timer.Start();
			using (var parser = new LeafGasComparisonParser(smallFileInfo))
				parser.Parse();
			timer.Stop();

			Console.WriteLine($"{timer.ElapsedMilliseconds}");

			timer.Reset();
			timer.Start();
			using (var parser = new LeafGasComparisonParser(largeFileInfo))
				parser.Parse();
			timer.Stop();

			Console.WriteLine($"{timer.ElapsedMilliseconds}");
		}
	}
}
