using System.IO;
using JamesKovacs.IoCArticle.IoCContainer.Domain;
using JamesKovacs.IoCArticle.IoCContainer.Repositories;
using MbUnit.Framework;
using Rhino.Mocks;

namespace JamesKovacs.IoCArticle.IoCContainer.Tests.Unit.Repositories {
    [TestFixture]
    public class AuditingInvoiceRepositoryTests {
        private MockRepository mockery;

        [SetUp]
        public void Setup() {
            mockery = new MockRepository();
        }

        [Test]
        public void CanAuditSave() {
            Invoice invoice = new Invoice();
            IInvoiceRepository mockRepository = mockery.DynamicMock<IInvoiceRepository>();
            IAuditWriter auditWriter = mockery.DynamicMock<IAuditWriter>();

            using(mockery.Record()) {
                mockRepository.Save(invoice);
                auditWriter.WriteEntry(string.Empty);
                LastCall.IgnoreArguments();
            }

            using(mockery.Playback()) {
                IInvoiceRepository auditor = new AuditingInvoiceRepository(mockRepository, auditWriter);
                auditor.Save(invoice);
            }
        }
    }
}