﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using BusinessLogic.Implementation.EntityFramework;
using System;
using System.Collections.Generic;
using Domain;
using Domain.Entities;
using System.Configuration;

namespace Repository.Tests
{
    [TestClass()]
    public class OperationTypeRepositoryTests
    {
        private EFOperationTypeRepository _operationTypeRepository = new EFOperationTypeRepository(new SalaryManagerDbContext(
                ConfigurationManager.ConnectionStrings["SalaryManagerDBConnection"].ConnectionString));


        [TestMethod()]
        public void CreateOperationTypeTest()
        {
            OperationType operationType = _operationTypeRepository.CreateOperationType("Логарифмическая", 10);
            OperationType operationType1 = _operationTypeRepository.GetOperationType("Логарифмическая");
            Assert.IsNotNull(operationType1);
        }

        [TestMethod()]
        public void GetOperationTypeByIdTest()
        {
            OperationType operationType = _operationTypeRepository.GetOperationType("Логарифмическая");
            Assert.IsNotNull(operationType);
        }

        [TestMethod()]
        public void GetOperationTypeByNameTest()
        {
            OperationType operationType = _operationTypeRepository.GetOperationType("Логарифмическая");
            Assert.IsNotNull(operationType);
        }

        [TestMethod()]
        public void UpdateOperationTypeTest()
        {
            OperationType operationType1 = _operationTypeRepository.GetOperationType("Логарифмическая");
            decimal before = operationType1.Base_Amount;
            operationType1.Base_Amount++;
            _operationTypeRepository.UpdateOperationType(operationType1);
            OperationType operationType2 = _operationTypeRepository.GetOperationType("Логарифмическая");
            Assert.IsNotNull(operationType2);
            Assert.AreEqual((operationType2.Base_Amount - before), 1);
        }

        [TestMethod()]
        public void DeleteOperationTypeTest()
        {
            OperationType operationType1 = _operationTypeRepository.GetOperationType("Логарифмическая");
            _operationTypeRepository.DeleteOperationType(operationType1);

            OperationType operationType2 = _operationTypeRepository.GetOperationType("Логарифмическая");
            Assert.IsNull(operationType2);
        }

        [TestMethod()]
        public void GetOperationTypesTest()
        {
            IEnumerable<OperationType> operationTypes = _operationTypeRepository.GetOperationTypes();
            Assert.IsNotNull(operationTypes);
        }
    }
}