示例#1
0
        public void importUpdateCustomer_Test()
        {
            // arrange
            int    id          = 1;
            string fullName    = "Full Name";
            string address     = "1 Example St";
            string phoneNumber = "1234";
            string email       = "*****@*****.**";
            string city        = "Somewhere";
            int    postcode    = 2000;

            Customer.States state       = Customer.States.NSW;
            Customer        newCustomer = new Customer(id, fullName, address, phoneNumber, email, city, state, postcode, null);
            // set up the model fake
            var  customerService            = A.Fake <Model.ServiceLayer.ICustomerOps>();
            bool updateCustomerMethodCalled = false;

            A.CallTo(() => customerService.importUpdateCustomer(newCustomer)).Invokes(() => { updateCustomerMethodCalled = true; });
            // set up the class under test
            customerController = new CustomerController(customerService);

            // act
            customerController.importUpdateCustomer(newCustomer);

            // assert
            NUnit.Framework.Assert.IsTrue(updateCustomerMethodCalled);
        }
示例#2
0
        public void addCustomer_Test()
        {
            // arrange
            // set up the data access fake
            int    id          = 1;
            string fullName    = "Full Name";
            string address     = "Address";
            string phoneNumber = "12345";
            string email       = "*****@*****.**";
            string city        = "Somewhere";

            Customer.States state    = Customer.States.NSW;
            int             postcode = 2000;

            System.Collections.Generic.List <ITransaction> transactions = null;
            Customer newCustomer             = new Customer(id, fullName, address, phoneNumber, email, city, state, postcode, transactions);
            var      customerDAO             = A.Fake <Model.DataAccessLayer.ICustomerDAO>();
            bool     addCustomerMethodCalled = false;

            A.CallTo(() => customerDAO.addCustomer(newCustomer)).Invokes(() => addCustomerMethodCalled = true);
            // set up the class under test
            this.customerService = new Model.ServiceLayer.CustomerOps(customerDAO);
            // subscribe to the event
            bool eventFired = false;

            this.customerService.GetAllCustomers += (sender, args) => { eventFired = true; };

            // act
            this.customerService.addCustomer(newCustomer);

            // assert
            NUnit.Framework.Assert.IsTrue(eventFired);
            NUnit.Framework.Assert.IsTrue(addCustomerMethodCalled);
        }
示例#3
0
        public void getCustomer_Test()
        {
            // should return either a null or a customer object

            // arrange
            // set up the data access fake
            int    id          = 1;
            string fullName    = "Full Name";
            string address     = "Address";
            string phoneNumber = "12345";
            string email       = "*****@*****.**";
            string city        = "Somewhere";

            Customer.States state    = Customer.States.NSW;
            int             postcode = 2000;

            System.Collections.Generic.List <ITransaction> transactions = null;
            var customerDAO = A.Fake <Model.DataAccessLayer.ICustomerDAO>();

            A.CallTo(() => customerDAO.getCustomer(1)).Returns(new Customer(id, fullName, address, phoneNumber, email, city, state, postcode, transactions));
            A.CallTo(() => customerDAO.getCustomer(0)).Returns(null);
            // set up the class under test
            this.customerService = new Model.ServiceLayer.CustomerOps(customerDAO);

            // act
            ICustomer customerThatExists       = this.customerService.getCustomer(1);
            ICustomer customerThatDoesNotExist = this.customerService.getCustomer(0);

            // assert
            NUnit.Framework.Assert.IsNull(customerThatDoesNotExist);
            NUnit.Framework.Assert.AreEqual(id, customerThatExists.CustomerID);
            NUnit.Framework.Assert.AreEqual(fullName, customerThatExists.FullName);
            NUnit.Framework.Assert.AreEqual(address, customerThatExists.Address);
            NUnit.Framework.Assert.AreEqual(phoneNumber, customerThatExists.PhoneNumber);
            NUnit.Framework.Assert.AreEqual(email, customerThatExists.Email);
            NUnit.Framework.Assert.AreEqual(city, customerThatExists.City);
            NUnit.Framework.Assert.AreEqual(state, customerThatExists.state);
            NUnit.Framework.Assert.AreEqual(postcode, customerThatExists.Postcode);
            NUnit.Framework.Assert.AreEqual(transactions, customerThatExists.Transactions);
        }
示例#4
0
        public void getAllCustomers_Test()
        {
            // arrange
            // set up the data access fake
            int    id          = 1;
            string fullName    = "Full Name";
            string address     = "Address";
            string phoneNumber = "12345";
            string email       = "*****@*****.**";
            string city        = "Somewhere";

            Customer.States state    = Customer.States.NSW;
            int             postcode = 2000;

            System.Collections.Generic.List <ITransaction> transactions = null;
            var customerDAO = A.Fake <Model.DataAccessLayer.ICustomerDAO>();

            A.CallTo(() => customerDAO.getAllCustomers()).Returns(new System.Collections.Generic.List <ICustomer> {
                new Customer(id, fullName, address, phoneNumber, email, city, state, postcode, transactions)
            });
            // set up the class under test
            this.customerService = new Model.ServiceLayer.CustomerOps(customerDAO);
            // subscribe to the event
            bool eventFired = false;

            this.customerService.GetAllCustomers += (sender, args) => { eventFired = true; };

            // act
            IEnumerable <ICustomer> collectionOfCustomers = this.customerService.getAllCustomers();

            // assert
            NUnit.Framework.Assert.IsTrue(eventFired);
            foreach (ICustomer customer in collectionOfCustomers)
            {
                NUnit.Framework.Assert.AreEqual(id, customer.CustomerID);
            }
        }