﻿using BranchSwitcher.Web.Models;
using BranchSwitcher.Web.Test.Framework;
using FluentAssertions;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using Xunit;

namespace BranchSwitcher.Web.Test.Controllers
{
    public class StepsEngineControllerIntegrationTest
    {
		private readonly TestServer m_Server;
		private readonly HttpClient m_Client;

		public StepsEngineControllerIntegrationTest()
		{
			m_Server = new TestServer(new WebHostBuilder().UseStartup<Startup>());
			m_Client = m_Server.CreateClient().AcceptJson();
		}

		[Fact]
		public async void controller_returns_badrequest_if_modelstate_invalid()
		{
			ExecutionOptionsModel model = null;
			var response = await m_Client.PostAsJsonAsync("/api/stepsengine", model);
			response.StatusCode.Should().Be(HttpStatusCode.BadRequest);

			model = new ExecutionOptionsModel();
			model.Steps = new List<StepExecutionModel>();
			response = await m_Client.PostAsJsonAsync("/api/stepsengine", model);
			response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
		}
	}
}
