﻿using System.Collections.Generic;
using Dodo.Tools.WebApi.Samples.Services;
using Moq;
using Moq.Language.Flow;
using NUnit.Framework;

namespace Dodo.Tools.WebApi.Tests
{
	public class WebApiClientFactoryTestsBase
	{
		protected WebApiClient WebApiClient;
		protected Mock<IHttpRequestSender> HttpRequestSenderMock;

		[SetUp]
		public void SetUp()
		{
			HttpRequestSenderMock = new Mock<IHttpRequestSender>();
			WebApiClient = new WebApiClient();

			HttpRequestSenderMock.Setup(x => x.PostVoid(It.IsAny<string>(), It.IsAny<Dictionary<string, object>>())).Callback(
				(string url, Dictionary<string, object> values) => { });
		}


		#region helpers

		protected IReturnsResult<IHttpRequestSender> Given_PostResponse<T>(T response)
		{
			return HttpRequestSenderMock.Setup(x =>
					x.Post<T>(It.IsAny<string>(), It.IsAny<Dictionary<string, object>>()))
				.Returns(response);
		}

		protected ITestService GetClient(string baseUrl = "")
		{
			return WebApiClient.For<ITestService>()
				.WithBaseUrl(baseUrl)
				.Build();
		}

		#endregion
	}
}