﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using Snapplicator.Areas.Wiki.Controllers;
using Snapplicator.Areas.Wiki.Models;
using Snapplicator.Areas.Wiki.Services;

namespace Snapplicator.Tests.Areas.Wiki.Controllers
{
    [TestFixture]
    public class ArticleControllerTests
    {
        public class TestPackage : BaseTestPackage
        {
            public Mock<IWikiArticleService> WikiArticleServiceMock { get; set; }
            public ArticleController ArticleController { get; set; }

            public TestPackage()
            {
                WikiArticleServiceMock = new Mock<IWikiArticleService>();
                ArticleController = new ArticleController(WikiArticleServiceMock.Object);
            }
        }

        [Test]
        public void View_Should_Pass_Title_To_GetArticleByTitle()
        {
            var pkg = new TestPackage();
            var title = "Test";
            pkg.WikiArticleServiceMock.Setup(x => x.GetArticleByTitle(title)).Returns(new WikiArticle {Title = title, Body = ""});

            pkg.ArticleController.View(title);

            pkg.WikiArticleServiceMock.Verify(x => x.GetArticleByTitle(title), Times.Once);
        }

        [Test]
        public void Create_Post_Should_Pass_Article_To_CreateArticle()
        {
            var pkg = new TestPackage();
            var article = new WikiArticle
            {
                Id = pkg.Random.Next(100)
            };
            pkg.WikiArticleServiceMock.Setup(x => x.CreateArticle(article)).Returns(article);

            pkg.ArticleController.Create(article);

            pkg.WikiArticleServiceMock.Verify(x => x.CreateArticle(article), Times.Once);
        }
    }
}
