﻿using System;
using System.Collections.Generic;
using Moq;
using NUnit.Framework;
using RetroApi.Database;
using RetroApi.Models;
using RetroApi.Services;

namespace RetroApi.UnitTests.Services
{
    [TestFixture]
    public class HappinessMetricsServiceTests
    {
        private HappinessMetricsService _testObject;

        private Mock<IRepository<HappinessMetric>> _mockRepository;

        [SetUp]
        public void SetUp()
        {
            _mockRepository = new Mock<IRepository<HappinessMetric>>();
            _testObject = new HappinessMetricsService(_mockRepository.Object);
        }

        [Test]
        public void PostHappinessMetric_AddsTimeStampToHappinessMetric_AndReturnsFromRepository()
        {
            var testStartTime = DateTime.Now;
            var happinessMetric = new HappinessMetric
            {
                Happiness = 1
            };
            var expected = new HappinessMetric();

            _mockRepository.Setup(x => x.Add(It.Is<HappinessMetric>(hm => 
            hm.Timestamp > testStartTime && hm.Happiness == happinessMetric.Happiness)))
                .Returns(expected);

            var actual = _testObject.PostHappinessMetric(happinessMetric);

            Assert.That(actual, Is.SameAs(expected));
        }

        [Test]
        public void GetHappinessMetric_ReturnsValuesFromRepository()
        {
            var expected = new List<HappinessMetric>
            {
                new HappinessMetric()
            };

            _mockRepository.Setup(x => x.GetAll()).Returns(expected);
            var actual = _testObject.GetHappinessMetrics();
            Assert.That(actual, Is.SameAs(expected));
        }
    }
}