﻿using AutoMapper;
using BranchSwitcher.Web.Configuration;
using BranchSwitcher.Web.Controllers;
using BranchSwitcher.Web.Models;
using BranchSwitcher.Web.Steps;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Moq;
using System.Collections.Generic;
using Xunit;
using SynNet.Steps;
using BranchSwitcher.Web.Test.Framework;

namespace BranchSwitcher.Web.Test.Controllers
{
    public class StepsEngineControllerTest
    {
		private readonly Mock<IOptions<BranchSwitcherConfiguration>> m_Config;
		private readonly Mock<IStepsExecutor> m_Executor;
		private readonly Mock<IMapper> m_Mapper;
		private readonly LooseMockFactory m_MockFactory;

		public StepsEngineControllerTest()
		{
			m_MockFactory = new LooseMockFactory();
			m_Executor = m_MockFactory.Create<IStepsExecutor>();
			m_Mapper = m_MockFactory.Create<IMapper>();
			m_Config = m_MockFactory.Create<IOptions<BranchSwitcherConfiguration>>();
		}

		[Fact]
		public void controller_returns_nocontent_if_executor_results_empty()
		{
			var options = new ExecutionOptionsModel();
			options.Steps = new List<StepExecutionModel>
			{
				new StepExecutionModel { StepName = "testname" }
			};

			m_Executor.Setup(e => e.Execute(
				It.IsAny<ExecutionOptions>()/*, It.IsAny<string>()*/)).Returns(new IStepResult[] { });

			var controller = new StepsEngineController(
				m_Executor.Object,
				m_Mapper.Object, m_Config.Object);

			var result = controller.Post(options);
			result.Should().BeOfType<NoContentResult>();
		}
    }
}
