public async Task CreateBankAccountTest()
        {
            var result = await _controller.CreateBankAccount();

            var contentResult = result as CreatedAtRouteNegotiatedContentResult <BankAccount>;

            Assert.IsNotNull(contentResult);
            Assert.AreEqual(3, _fakeContext.BankAccounts.Count());
            Assert.AreEqual(_fakeContext.BankAccounts.ElementAt(2), contentResult.Content);
        }
예제 #2
0
        public void CreateBankAccount_Should_CreateBankAccount_And_ReturnBankAccountDto_When_ModelStateIsValid()
        {
            // Arrange
            var bankAccountCreation = new BankAccountCreationDto
            {
                AccountType = AccountType.Checking,
                Currency    = Currency.Eur,
                CustomerId  = 1
            };

            var bankAccountNumber = new BankAccountNumber
            {
                CountryCode        = "PL",
                CheckDigits        = "61",
                NationalBankCode   = "1080",
                BranchCode         = "000",
                NationalCheckDigit = 1,
                AccountNumber      = 0,
                AccountNumberText  = "0000000000000000",
                Iban          = "PL61108000010000000000000000",
                IbanSeparated = "PL 61 1080 0001 0000 0000 0000 0000"
            };

            var expectedBankAccount = new BankAccountDto
            {
                AccountType        = (AccountType)bankAccountCreation.AccountType,
                Currency           = (Currency)bankAccountCreation.Currency,
                CountryCode        = bankAccountNumber.CountryCode,
                CheckDigits        = bankAccountNumber.CheckDigits,
                NationalBankCode   = bankAccountNumber.NationalBankCode,
                BranchCode         = bankAccountNumber.BranchCode,
                NationalCheckDigit = bankAccountNumber.NationalCheckDigit,
                AccountNumber      = bankAccountNumber.AccountNumber,
                AccountNumberText  = bankAccountNumber.AccountNumberText,
                Iban          = bankAccountNumber.Iban,
                IbanSeparated = bankAccountNumber.IbanSeparated,
                Balance       = 0,
                DebitLimit    = 0,
                CustomerId    = (int)bankAccountCreation.CustomerId,
                CreatedById   = (int)bankAccountCreation.CustomerId
            };

            _bankAccountNumberBuilderMock.Setup(anf => anf.GenerateBankAccountNumber(null)).Returns(bankAccountNumber);

            // Act
            var createdAtRouteResult = _sut.CreateBankAccount(bankAccountCreation).Result as CreatedAtRouteResult;

            // Assert
            Assert.IsNotNull(createdAtRouteResult);
            Assert.IsInstanceOfType(createdAtRouteResult.Value, typeof(BankAccountDto));

            var bankAccountDto = createdAtRouteResult.Value as BankAccountDto;

            Assert.IsNotNull(bankAccountDto);
            Assert.AreEqual(expectedBankAccount.AccountType, bankAccountDto.AccountType);
            Assert.AreEqual(expectedBankAccount.Currency, bankAccountDto.Currency);
            Assert.AreEqual(expectedBankAccount.CountryCode, bankAccountDto.CountryCode);
            Assert.AreEqual(expectedBankAccount.CheckDigits, bankAccountDto.CheckDigits);
            Assert.AreEqual(expectedBankAccount.NationalBankCode, bankAccountDto.NationalBankCode);
            Assert.AreEqual(expectedBankAccount.BranchCode, bankAccountDto.BranchCode);
            Assert.AreEqual(expectedBankAccount.NationalCheckDigit, bankAccountDto.NationalCheckDigit);
            Assert.AreEqual(expectedBankAccount.AccountNumber, bankAccountDto.AccountNumber);
            Assert.AreEqual(expectedBankAccount.AccountNumberText, bankAccountDto.AccountNumberText);
            Assert.AreEqual(expectedBankAccount.Iban, bankAccountDto.Iban);
            Assert.AreEqual(expectedBankAccount.IbanSeparated, bankAccountDto.IbanSeparated);
            Assert.AreEqual(expectedBankAccount.Balance, bankAccountDto.Balance);
            Assert.AreEqual(expectedBankAccount.DebitLimit, bankAccountDto.DebitLimit);
            Assert.AreNotEqual(DateTime.MinValue, bankAccountDto.OpenedDate);
            Assert.AreEqual(expectedBankAccount.CustomerId, bankAccountDto.CustomerId);
            Assert.AreEqual(expectedBankAccount.CreatedById, bankAccountDto.CreatedById);

            var bankAccountFromDb = _context.BankAccounts.SingleOrDefault(ba => ba.Id == bankAccountDto.Id);

            Assert.IsNotNull(bankAccountFromDb);
            Assert.AreEqual(expectedBankAccount.AccountType, bankAccountFromDb.AccountType);
            Assert.AreEqual(expectedBankAccount.Currency, bankAccountFromDb.Currency);
            Assert.AreEqual(expectedBankAccount.CountryCode, bankAccountFromDb.CountryCode);
            Assert.AreEqual(expectedBankAccount.CheckDigits, bankAccountFromDb.CheckDigits);
            Assert.AreEqual(expectedBankAccount.NationalBankCode, bankAccountFromDb.NationalBankCode);
            Assert.AreEqual(expectedBankAccount.BranchCode, bankAccountFromDb.BranchCode);
            Assert.AreEqual(expectedBankAccount.NationalCheckDigit, bankAccountFromDb.NationalCheckDigit);
            Assert.AreEqual(expectedBankAccount.AccountNumber, bankAccountFromDb.AccountNumber);
            Assert.AreEqual(expectedBankAccount.AccountNumberText, bankAccountFromDb.AccountNumberText);
            Assert.AreEqual(expectedBankAccount.Iban, bankAccountFromDb.Iban);
            Assert.AreEqual(expectedBankAccount.IbanSeparated, bankAccountFromDb.IbanSeparated);
            Assert.AreEqual(expectedBankAccount.Balance, bankAccountFromDb.Balance);
            Assert.AreEqual(expectedBankAccount.DebitLimit, bankAccountFromDb.DebitLimit);
            Assert.AreNotEqual(DateTime.MinValue, bankAccountFromDb.OpenedDate);
            Assert.AreEqual(expectedBankAccount.CustomerId, bankAccountFromDb.CustomerId);
            Assert.AreEqual(expectedBankAccount.CreatedById, bankAccountFromDb.CreatedById);
        }