Beispiel #1
0
        public void GetCustomerByNonExistingIdReturnsNull()
        {
            List <Customer> cData = new List <Customer>()
            {
                new Customer()
                {
                    Id = 900, Name = "First M.I. Customer"
                },
                new Customer()
                {
                    Id = 2, Name = "Second Client"
                }
            };

            Customer expectedResult = null;

            IBankData fakeDb = Mock.Create <IBankData>();

            Mock.Arrange(() => fakeDb.GetAllCustomers()).Returns(cData).MustBeCalled();
            Bank bank = new Bank(fakeDb);
            //Act
            Customer actualresult = bank.GetCustomerById(501);

            //Assert
            Assert.AreEqual(expectedResult, actualresult);
        }
Beispiel #2
0
        public void GetAccountByNonExistingNumberGivesNull()
        {
            //Arrange
            Account expectedResult            = null;
            ICollection <Account> allAccounts = new List <Account>()
            {
                new Account()
                {
                    AccountNumber = 1
                },
                new Account()
                {
                    AccountNumber = 1
                },
                new Account()
                {
                    AccountNumber = 2
                },
                new Account()
                {
                    AccountNumber = 7
                }
            };
            IBankData fakeDb = Mock.Create <IBankData>();

            Mock.Arrange(() => fakeDb.GetAllAccounts()).Returns(allAccounts);
            Bank bank = new Bank(fakeDb);
            //Act
            Account actualResult = bank.GetAccountByNumber(100);

            //Assert

            Assert.AreEqual(expectedResult, actualResult);
        }
Beispiel #3
0
 public Bank(IBankData context)
 {
     if (context == null)
     {
         throw new ArgumentNullException("Context may not be null when constructing a bank");
     }
     this.context = context;
 }
    public static string SaveBank(IBankData bankData)
    {
        string jsonText = JsonConvert.SerializeObject(bankData, Formatting.Indented, new BankJsonConverter());

        // this example just returns the JSON text
        //  but you would implement your save logic as needed
        return(jsonText);
    }
Beispiel #5
0
        public void ConstructorGivenIBankDataGivesBank()
        {
            //Arrange
            IBankData fakeDb       = Mock.Create <IBankData>();
            Bank      actualResult = new Bank(fakeDb);

            //Act
            actualResult.GetAllAccounts(); // Gives exception if context == null
            //Assert
            Assert.IsNotNull(actualResult);
            Assert.IsInstanceOfType(actualResult, typeof(Bank));
        }
Beispiel #6
0
        public void GetAllAccountsGivesListOfAccounts()
        {
            //Arrange
            ICollection <Account> expectedResult = new List <Account>()
            {
                new Account(),
                new Account()
            };
            IBankData fakeDb = Mock.Create <IBankData>();

            Mock.Arrange(() => fakeDb.GetAllAccounts()).Returns(expectedResult).MustBeCalled();
            Bank bank = new Bank(fakeDb);
            //Act
            IEnumerable <Account> actualResult = bank.GetAllAccounts();

            //Assert
            Assert.IsNotNull(actualResult);
            Assert.IsInstanceOfType(actualResult, typeof(IEnumerable <Account>));
        }
Beispiel #7
0
        public void GetAllCustomersGiven2CutomersReturns2Customers()
        {
            List <Customer> cData = new List <Customer>()
            {
                new Customer()
                {
                    Id = 1, Name = "First M.I. Customer"
                },
                new Customer()
                {
                    Id = 2, Name = "Second Client"
                }
            };

            IBankData fakeDb = Mock.Create <IBankData>();

            Mock.Arrange(() => fakeDb.GetAllCustomers()).Returns(cData).MustBeCalled();
            Bank bank = new Bank(fakeDb);
            //Act
            IEnumerable <Customer> actualresult = bank.GetAllCustomers();

            //Assert
            Assert.IsTrue((cData).SequenceEqual(actualresult));
        }
Beispiel #8
0
 public Bank()
 {
     context = InMemoryBankData.Instance;
 }