using System;
using System.Configuration;
using System.Linq;
using LeafWeb.Core.Remote;
using LeafWeb.Core.Utility;
using NUnit.Framework;

namespace LeafWeb.Core.Tests.Remote
{
	[TestFixture]
	public class PiscalSshClientTests
	{
		private readonly PiscalLeafInputFile _testInput =
			new PiscalLeafInputFile
			{
				Filename = "blah",
				LeafInputId = 1,
				Contents = "test".GetBytes(),
				DirectoryName = "TestDirectory2"
			};

		private readonly string _piscalConnectionString =
			ConfigurationManager.ConnectionStrings["PiscalServer"].ConnectionString;

		[Test]
		public void SubmitLeafInputFile()
		{
			var client = new PiscalSshClient(_piscalConnectionString);
			client.RunLeafInputFile(_testInput);
		}

		[Test]
		public void GetLeafInputStatus()
		{
			var client = new PiscalSshClient(_piscalConnectionString);
			var leafInputStatus = client.GetLeafInputFileStatus(_testInput);
			Console.WriteLine(leafInputStatus);
		}

		[Test]
		public void RetrieveLeafOutput()
		{
			var client = new PiscalSshClient(_piscalConnectionString);
			var result = client.RetrieveLeafOutput(_testInput).ToList();
			Console.WriteLine(string.Join(", ", result.Select(o => o.Filename)));
			//Console.WriteLine(result[0].Contents.GetString());
		}
	}
}
