Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
    }
Exemplo n.º 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));
        }
Exemplo n.º 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>));
        }
Exemplo n.º 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));
        }
Exemplo n.º 8
0
 public Bank()
 {
     context = InMemoryBankData.Instance;
 }