﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using SSCore;
using SSService.Db;
using SSService.Inventory.Domain;
using SSService.Inventory.Repository;
using SSService.Inventory.Service;
using SSService.Inventory.Service.Interfaces;
using System;
using System.Collections.Generic;

namespace SSServiceTest
{
    /// <summary>
    /// Service test for Color Source
    /// </summary>
    [TestClass]
    public class InvColorSourceServiceTest
    {
        private IInvColorSourceService _serviceMock;

        #region Initialization

        [TestInitialize]
        public void Init()
        {
            _serviceMock = GetServiceMock();
        }

        private IInvColorSourceService GetServiceMock()
        {
            Mock<InventoryDbContext> inventoryDbContextMock = new Mock<InventoryDbContext>();

            var getInvColorSourceMock = new List<InvColorSource>
            {
                new InvColorSource {
                    Id = Guid.Parse("5D28E1AD-FD80-4436-912F-70DB11785C7C"),
                    ColorName = "Black"
                },
                new InvColorSource {
                    Id = Guid.Parse("D0EDA75A-BEB8-4E55-B9AC-D5348DF80585"),
                    ColorName = "Red"
                }
            };

            inventoryDbContextMock.Setup(db => db.InvColorSources).Returns(MockHelper.GetMockedDbSet<InvColorSource>(getInvColorSourceMock).Object);

            return new InvColorSourceService(new InvColorSourceRepository(inventoryDbContextMock.Object));
        }

        private IInvColorSourceService GetServiceForZeroResultMock()
        {
            Mock<InventoryDbContext> inventoryDbContextMock = new Mock<InventoryDbContext>();

            var getInvColorSourceMock = new List<InvColorSource>
            { 
            };

            inventoryDbContextMock.Setup(db => db.InvColorSources).Returns(MockHelper.GetMockedDbSet<InvColorSource>(getInvColorSourceMock).Object);

            return new InvColorSourceService(new InvColorSourceRepository(inventoryDbContextMock.Object));
        }
         
        #endregion

        #region GetColors

        /// <summary>
        /// Positive Test
        /// </summary>
        [TestMethod]
        public void Service_GetColors_WithoutParam_ReturnSomeData()
        {
            var resultList = _serviceMock.GetColors();
            Assert.IsNotNull(resultList, "The result list should be not null!");
            Assert.AreEqual(resultList.Count, 2, "The count of result list is not equal to 2!"); 
        }

        /// <summary>
        /// Negavite Test
        /// </summary>
        [TestMethod]
        public void Service_GetColors_WithoutParam_ReturnZeroData()
        {
            var localServiceMock = GetServiceForZeroResultMock();
            var resultList = localServiceMock.GetColors();
            Assert.IsNotNull(resultList, "The result list should be not null!");
            Assert.AreEqual(resultList.Count, 0, "The count of result list is not equal to 0!");

        }

        #endregion

        #region GetColorById
        /// <summary>
        /// Posotive Test
        /// </summary>
        [TestMethod]
        public void Service_GetColorById_IdIsExists_ReturnOneData()
        {
            var id = Guid.Parse("5D28E1AD-FD80-4436-912F-70DB11785C7C");
            var result = _serviceMock.GetColorById(id);
            Assert.IsNotNull(result, "The result should be not null!");
            Assert.AreEqual(result.Id, id, "The Id of the result is not similar!");
        }

        /// <summary>
        /// Posotive Test
        /// </summary>
        [TestMethod]
        public void Service_GetCategoryById_IdIsNotExists_ReturnZeroData()
        {
            var id = Guid.Parse("1D28E1AD-FD80-4436-912F-70DB11785C7C");
            var result = _serviceMock.GetColorById(id);
            Assert.IsNull(result, "The result should be null!"); 
        }
        #endregion
    }
}
