Ejemplo n.º 1
0
        /// <summary>
        ///     Adds services which fulfil the various data repository contracts for the application
        /// </summary>
        public static IServiceCollection AddAppDataRepositories(this IServiceCollection services)
        {
            var userRepository    = new InMemoryUserRepository();
            var accountRepository = new InMemoryBankAccountRepository();

            return(services
                   .AddSingleton <IUserRepository>(userRepository)
                   .AddSingleton <IBankAccountRepository>(accountRepository));
        }
Ejemplo n.º 2
0
        public void GetAccountByIdHandlesAccountNotFound()
        {
            const int requestedAccountId = 1;

            var repository = new InMemoryBankAccountRepository();

            var locatedAccount = repository.GetAccountById(requestedAccountId);

            Assert.That(locatedAccount, Is.Null);
        }
Ejemplo n.º 3
0
        public void GetAccountByBankIdAndAccountNumberHandleAccountNotFound()
        {
            const string requestedBankId        = "TestBank";
            const string requestedAccountNumber = "12346578";

            var repository = new InMemoryBankAccountRepository();

            var locatedAccount = repository.GetAccountByBankIdAndAccountNumber(requestedBankId, requestedAccountNumber);

            Assert.That(locatedAccount, Is.Null);
        }
Ejemplo n.º 4
0
        public void GetAccountByBankIdAndAccountNumberCanLocateAccount()
        {
            const int    userId        = 1;
            const string bankId        = "TestBank";
            const string accountNumber = "12346578";

            var repository = new InMemoryBankAccountRepository();

            var createdAccount = repository.CreateAccount(userId, bankId, accountNumber);
            var locatedAccount = repository.GetAccountByBankIdAndAccountNumber(bankId, accountNumber);

            Assert.That(createdAccount, Is.EqualTo(locatedAccount));
        }
Ejemplo n.º 5
0
        public void CreateAccountGeneratesUniqueIds()
        {
            const int    userId         = 1;
            const string bankId         = "TestBank";
            const string accountNumber1 = "12346578";
            const string accountNumber2 = "12346579";

            var repository = new InMemoryBankAccountRepository();

            var createdAccount1 = repository.CreateAccount(userId, bankId, accountNumber1);
            var createdAccount2 = repository.CreateAccount(userId, bankId, accountNumber2);

            Assert.That(createdAccount1.Id, Is.Not.EqualTo(createdAccount2.Id));
        }
Ejemplo n.º 6
0
        public void CreateAccountCanAddAccount()
        {
            const int    userId        = 1;
            const string bankId        = "TestBank";
            const string accountNumber = "12346578";

            var repository = new InMemoryBankAccountRepository();

            var createdAccount = repository.CreateAccount(userId, bankId, accountNumber);

            Assert.That(createdAccount, Is.Not.Null);
            Assert.That(createdAccount.Id, Is.GreaterThan(0));
            Assert.That(createdAccount.UserId, Is.EqualTo(userId));
            Assert.That(createdAccount.BankId, Is.EqualTo(bankId));
            Assert.That(createdAccount.AccountNumber, Is.EqualTo(accountNumber));
        }
Ejemplo n.º 7
0
        public void GetAllAccountsByUserIdReturnsAllCreatedAccounts()
        {
            const int    userId1        = 1;
            const int    userId2        = 2;
            const string bankId         = "TestBank";
            const string accountNumber1 = "12346578";
            const string accountNumber2 = "12346579";
            const string accountNumber3 = "12346570";

            var repository = new InMemoryBankAccountRepository();

            var createdAccount1 = repository.CreateAccount(userId1, bankId, accountNumber1);
            var createdAccount2 = repository.CreateAccount(userId1, bankId, accountNumber2);
            var createdAccount3 = repository.CreateAccount(userId2, bankId, accountNumber3);

            var allAccounts = repository.GetAllAccountsByUserId(userId1).ToList();

            Assert.That(allAccounts.Count, Is.EqualTo(2));
            Assert.That(allAccounts, Contains.Item(createdAccount1));
            Assert.That(allAccounts, Contains.Item(createdAccount2));
            Assert.That(allAccounts, Does.Not.Contain(createdAccount3));
        }
Ejemplo n.º 8
0
        public void CreateAccountRejectsDuplicateAccountDetails()
        {
            const int    userId         = 1;
            const string bankId1        = "TestBank1";
            const string bankId2        = "TestBank2";
            const string accountNumber1 = "12346578";
            const string accountNumber2 = "12346579";

            var repository = new InMemoryBankAccountRepository();

            repository.CreateAccount(userId, bankId1, accountNumber1);

            Assert.DoesNotThrow(
                () => repository.CreateAccount(userId, bankId1, accountNumber2)
                );

            Assert.DoesNotThrow(
                () => repository.CreateAccount(userId, bankId2, accountNumber1)
                );

            Assert.Throws <InvalidOperationException>(
                () => repository.CreateAccount(userId, bankId1, accountNumber1)
                );
        }