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

            // Act
            sut.AddTransactionToAccount("Trading Account", 100m);

            // Assert
        }
        public void AddingTransactionToAccountDelegatesToAccountInstance()
        {
            // Arrange
            var sut = new AccountService();

            // Act
            sut.AddTransactionToAccount("Trading Account", 200m);

            // Assert
            Assert.Fail();
        }
        public void CanCreateAGoldAccount()
        {
            // Arrange
            var accountRepository = new Mock<IAccountRepository>();
            var sut = new AccountService(accountRepository.Object);

            // Act
            sut.CreateAccount(RewardCardType.Gold);

            // Assert
            accountRepository.Verify(ar => ar.NewAccount(It.IsAny<AccountBase>()));
        }
        public void AddingTransactionToAccountDelegatesToAccountInstance()
        {
            // Arrange
            var account = new Account();
            var fakeRepository = new FakeAccountRepository(account);
            var sut = new AccountService(fakeRepository);

            // Act
            sut.AddTransactionToAccount("Trading Account", 200m);

            // Assert
            Assert.AreEqual(200m, account.Balance);
        }
        public void AccountExceptionsAreWrappedInThrowServiceException()
        {
            // Arrange
            var account = new Mock<Account>();
            account.Setup(a => a.AddTransaction(100m)).Throws<DomainException>();
            var mockRepository = new Mock<IAccountRepository>();
            mockRepository.Setup(r => r.GetByName("Trading Account")).Returns(account.Object);
            var sut = new AccountService(mockRepository.Object);

            // Act
            sut.AddTransactionToAccount("Trading Account", 100m);

            // Assert
        }
        public void AddingTransactionToAccountDelegatesToAccountInstance()
        {
            // Arrange
            var account = new Mock<Account>();
            account.Setup(a => a.AddTransaction(200m)).Verifiable();
            var mockRepository = new Mock<IAccountRepository>();
            mockRepository.Setup(r => r.GetByName("Trading Account")).Returns(account.Object);
            var sut = new AccountService(mockRepository.Object);

            // Act
            sut.AddTransactionToAccount("Trading Account", 200m);

            // Assert
            account.Verify();
        }
        public void AccountExceptionsAreWrappedInThrowServiceException()
        {
            // Arrange
            var account = new Mock<Account>();
            account.Setup(a => a.AddTransaction(100m)).Throws<DomainException>();
            var mockRepository = new Mock<IAccountRepository>();
            mockRepository.Setup(r => r.GetByName("Trading Account")).Returns(account.Object);
            var sut = new AccountService(mockRepository.Object);

            // Act
            try
            {
                sut.AddTransactionToAccount("Trading Account", 100m);
            }
            catch(ServiceException serviceException)
            {
                // Assert
                Assert.IsInstanceOfType(serviceException.InnerException, typeof(DomainException));
            }
        }
 public void Setup()
 {
     mockAccount = new Mock<Account>();
     mockRepository = new Mock<IAccountRepository>();
     sut = new AccountService(mockRepository.Object);
 }