using System;
using NUnit.Framework;
using NSubstitute;
using WebApiExample2.Business;
using WebApiExample2.Data.Model;
using WebApiExample2.Controllers;


namespace WebApiUnitTests
{
    public class BookControllerTest
    {
        /*
         * 
         * The following method tests the GET method
         * of the BooksController. It attempts to retrieve
         * a book with id=1. Note that the BookService has been
         * implemented as a mock using the NSubstitute package
         * 
         */
         
        [Test] 
        public void TestGet()
        {
            //Substitute the book service with a mock
            var bookService = Substitute.For<IBookService>();
            
            //Initialize the controller and inject mock
            var controller = new BooksController(bookService);

            //Call GET with id=1
            var bookActionResult = controller.Get(1);
            
            //Check that the GetBook() method of the mock book service
            //has been called with the correct parameter value
            bookService.Received().GetBook(1);
        }
    }
}
