using System;

using Domain;
using Services;
using RepositoryInterfaces;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Moq;

namespace ServiceTests
{
    [TestClass]
    public class AccountServiceTests
    {
        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void CannotCreateAccountServiceWithNullAccountRepository()
        {
            // Przygotuj.    

            // Wykonaj.
            new AccountService(null);

            // Zweryfikuj.
        }

        [TestMethod]
        public void AddingTransactionToAccountDelegatesToAccountInstance()
        {
            // Przygotuj.
            var account = new Mock<Account>();
            account.Setup(a => a.AddTransaction(200m)).Verifiable();
            var mockRepository = new Mock<IAccountRepository>();
            mockRepository.Setup(r => r.GetByName("Konto firmowe")).Returns(account.Object);
            var sut = new AccountService(mockRepository.Object);

            // Wykonaj.
            sut.AddTransactionToAccount("Konto firmowe", 200m);

            // Zweryfikuj.
            account.Verify();
        }

        [TestMethod]
        public void DoNotThrowWhenAccountIsNotFound()
        {
            // Przygotuj.
            var mockRepository = new Mock<IAccountRepository>();
            var sut = new AccountService(mockRepository.Object);

            // Wykonaj.
            sut.AddTransactionToAccount("Konto firmowe", 100m);

            // Zweryfikuj.
        }
    }
}
