using IoCConcepts.Domain;
using IoCConcepts.Repositories;
using NUnit.Framework;

namespace IoCConcepts.Tests {
    [TestFixture]
    public class CustomerServiceTests {
        [Test]
        public void CanEnrollANewCustomer() {
            // arrange
            var customerValidator = new FakeCustomerValidator();
            var creditCheck = new FakeCreditCheck();
            var repository = new FakeCustomerRepository();
            var customerService = new CustomerService(new[]{customerValidator}, creditCheck, repository);
            var customer = new Customer();

            // act
            customerService.EnrollCustomer(customer);

            // assert
            Assert.That(customerValidator.WasCalled);
            Assert.That(creditCheck.WasCalled);
            Assert.That(repository.WasCalled);
        }
    }

    public class FakeCustomerRepository : ICustomerRepository {
        public bool WasCalled;
        public void Save(Customer customer) {
            WasCalled = true;
        }
    }

    public class FakeCreditCheck : ICreditCheck {
        public bool WasCalled;

        public void Check(Customer customer) {
            WasCalled = true;
        }
    }

    public class FakeCustomerValidator : ICustomerValidator {
        public bool WasCalled;

        public void Validate(Customer customer) {
            WasCalled = true;
        }
    }
}