public void TestTotalSelectedSales()
        {
            var repos = new CustomerRepository(new FakeCustomerModule());
            var target = new AllCustomersViewModel(repos);

            int notifications = 0;
            target.PropertyChanged += (sender, e) =>
                                          {
                                              if (e.PropertyName == "TotalSelectedSales")
                                                  ++notifications;
                                          };

            Assert.AreEqual(0.0, target.TotalSelectedSales, "Should be zero when no customers are selected");

            CustomerViewModel firstCust = target.AllCustomers[0];

            firstCust.IsSelected = true;
            Assert.AreEqual(1, notifications, "TotalSelectedSales change notification was not raised");
            Assert.AreEqual(firstCust.TotalSales, target.TotalSelectedSales);

            CustomerViewModel secondCust = target.AllCustomers[1];
            secondCust.IsSelected = true;
            Assert.AreEqual(2, notifications, "TotalSelectedSales change notification was not raised again");
            Assert.AreEqual(firstCust.TotalSales + secondCust.TotalSales, target.TotalSelectedSales);
        }
        public void TestNewCustomerIsAdded()
        {
            var repos = new CustomerRepository(new FakeCustomerModule());
            var target = new AllCustomersViewModel(repos);

            Assert.AreEqual(3, target.AllCustomers.Count, "Test data includes three customers");

            repos.AddCustomer(Customer.CreateCustomer(123.45, "new", "customer", false, "*****@*****.**"));

            Assert.AreEqual(4, target.AllCustomers.Count, "Adding a customer to the repository increase the Count");
        }
        public void TestNewCustomerIsAdded()
        {
            CustomerRepository repos = new CustomerRepository(Constants.CUSTOMER_DATA_FILE);
            AllCustomersViewModel target = new AllCustomersViewModel(repos);

            Assert.AreEqual(3, target.AllCustomers.Count, "Test data includes three customers");

            repos.AddCustomer(Customer.CreateCustomer(123.45, "new", "customer", false, "*****@*****.**"));

            Assert.AreEqual(4, target.AllCustomers.Count, "Adding a customer to the repository increase the Count");
        }
        public CustomerViewModel(Customer customer, CustomerRepository customerRepository)
        {
            if (customer == null)
                throw new ArgumentNullException("customer");

            if (customerRepository == null)
                throw new ArgumentNullException("customerRepository");

            _customer = customer;
            _customerRepository = customerRepository;
            _customerType = Strings.CustomerViewModel_CustomerTypeOption_NotSpecified;
        }
        public void TestNewCustomerIsAddedProperly()
        {
            CustomerRepository target = new CustomerRepository(Constants.CUSTOMER_DATA_FILE);
            Customer cust = Customer.CreateNewCustomer();

            bool eventArgIsValid = false;
            target.CustomerAdded += (sender, e) => eventArgIsValid = (e.NewCustomer == cust);
            target.AddCustomer(cust);

            Assert.IsTrue(eventArgIsValid, "Invalid NewCustomer property");
            Assert.IsTrue(target.ContainsCustomer(cust), "New customer was not added");
        }
        public void TestNewCustomerIsAddedProperly()
        {
            var target = new CustomerRepository(new FakeCustomerModule());
            Customer cust = Customer.CreateNewCustomer();

            bool eventArgIsValid = false;
            target.CustomerAdded += (sender, e) => eventArgIsValid = (e.NewItem == cust);
            target.AddCustomer(cust);

            Assert.IsTrue(eventArgIsValid, "Invalid NewCustomer property");
            Assert.IsTrue(target.ContainsCustomer(cust), "New customer was not added");
        }
        public AllCustomersViewModel(CustomerRepository customerRepository)
        {
            if (customerRepository == null)
                throw new ArgumentNullException("customerRepository");

            base.DisplayName = Strings.AllCustomersViewModel_DisplayName;            

            _customerRepository = customerRepository;

            // Subscribe for notifications of when a new customer is saved.
            _customerRepository.CustomerAdded += this.OnCustomerAddedToRepository;

            // Populate the AllCustomers collection with CustomerViewModels.
            this.CreateAllCustomers();              
        }
        public void TestCustomerType()
        {
            Customer cust = Customer.CreateNewCustomer();
            CustomerRepository repos = new CustomerRepository(Constants.CUSTOMER_DATA_FILE);
            CustomerViewModel target = new CustomerViewModel(cust, repos);

            target.CustomerType = Strings.CustomerViewModel_CustomerTypeOption_Company;
            Assert.IsTrue(cust.IsCompany, "Should be a company");

            target.CustomerType = Strings.CustomerViewModel_CustomerTypeOption_Person;
            Assert.IsFalse(cust.IsCompany, "Should be a person");

            target.CustomerType = Strings.CustomerViewModel_CustomerTypeOption_NotSpecified;
            string error = (target as IDataErrorInfo)["CustomerType"];
            Assert.IsFalse(String.IsNullOrEmpty(error), "Error message should be returned");
        }
示例#9
0
		public CustomerViewModel( Customer customer, CustomerRepository customerRepository )
		{
			if ( customer == null )
				throw new ArgumentNullException( "customer" );

			if ( customerRepository == null )
				throw new ArgumentNullException( "customerRepository" );

			_customer = customer;
			_customerRepository = customerRepository;
			_customerType = Strings.CustomerViewModel_CustomerTypeOption_NotSpecified;

			if ( !IsNewCustomer )
			{
				if ( customer.IsCompany )
					CustomerType = Strings.CustomerViewModel_CustomerTypeOption_Company;
				else
					CustomerType = Strings.CustomerViewModel_CustomerTypeOption_Person;
			}
		}
        public MainWindowViewModel(string customerDataFile)
        {
            base.DisplayName = Strings.MainWindowViewModel_DisplayName;

            _customerRepository = new CustomerRepository(customerDataFile);
        }
        private MainWindowViewModel GetTarget()
        {
            var commands = new CommandController();
            //todo: fake this with rhino mocks...
            var repo = new CustomerRepository(new CustomerModule
                                                  {
                                                      CustomerDataFile =
                                                          Constants.CUSTOMER_DATA_FILE
                                                  });

            new CustomerController(_workspaces, commands, repo).Run();

            return new MainWindowViewModel(_workspaces, commands);
        }
 public void TestAllCustomersAreLoaded()
 {
     CustomerRepository target = new CustomerRepository(Constants.CUSTOMER_DATA_FILE);
     Assert.AreEqual(3, target.GetCustomers().Count, "Invalid number of customers in repository.");
 }
 public void TestAllCustomersAreLoaded()
 {
     var target = new CustomerRepository(new FakeCustomerModule());
     Assert.AreEqual(3, target.GetCustomers().Count, "Invalid number of customers in repository.");
 }