public ContactWindow(ObservableCollection<Contact> contacts, int index, string mode)
        {
            InitializeComponent();
            Contact context = new Contact();
            _contacts = contacts;
            _mode = mode;

            if (_mode.Equals("add"))
            {
                Title = "Add Contact";
            }
            else if (_mode.Equals("edit"))
            {
                if (index >= 0 && index < contacts.Count)
                {
                    _original = contacts[index];
                }
                else
                {
                    return;
                }
                Title = "Edit Contact";
                // copy properties of selected contact for local edits
                // global change will occur when OK is hit
                context = _original.Clone();
            }
            DataContext = context;
        }
        public void CityNotifyTest()
        {
            // based on http://www.benday.com/2010/08/24/an-easier-way-to-unit-test-inotifypropertychanged-in-silverlightwpf/
            Contact target = new Contact();
            bool changed = false;
            ((INotifyPropertyChanged)target).PropertyChanged +=
                delegate(object sender, PropertyChangedEventArgs e)
                {
                    changed = e.PropertyName == "City";
                };

            var newValue = "Albuquerque";
            target.City = newValue;
            Assert.AreEqual(newValue, target.City);
            Assert.IsTrue(changed, "City not seen in delegate.");
        }
 public void CloneTest()
 {
     string first = "Bold";
     string last = "Bigflank";
     long phone = 5558675309;
     string address = "123 Fake Street";
     string city = "Faketon";
     string state = "MO";
     int zip = 123123;
     Contact original = new Contact(first, last, phone, address, city, state, zip);
     Contact target = original.Clone();
     Assert.AreEqual(first, target.FirstName);
     Assert.AreEqual(last, target.LastName);
     Assert.AreEqual(phone, target.Phone);
     Assert.AreEqual(address, target.Address);
     Assert.AreEqual(city, target.City);
     Assert.AreEqual(state, target.State);
     Assert.AreEqual(zip, target.Zip);
 }
 public void PhoneStringTest()
 {
     Contact target = new Contact();
     target.Phone = 5558675309;
     string expected = "555-867-5309";
     string actual = target.PhoneString;
     Assert.AreEqual(expected, actual);
 }
 public void ToStringTest()
 {
     Contact target = new Contact("Punt", "Speedchunk");
     // ToString should just join the name
     string expected = "Punt Speedchunk";
     string actual;
     actual = target.ToString();
     Assert.AreEqual(expected, actual);
 }
        public void PhoneNotifyTest()
        {
            // based on http://www.benday.com/2010/08/24/an-easier-way-to-unit-test-inotifypropertychanged-in-silverlightwpf/
            Contact target = new Contact();
            bool phoneChanged = false;
            bool areaCodeChanged = false;
            bool officeChanged = false;
            bool extensionChanged = false;
            bool stringChanged = false;
            ((INotifyPropertyChanged)target).PropertyChanged +=
                delegate(object sender, PropertyChangedEventArgs e)
                {
                    phoneChanged = phoneChanged || e.PropertyName == "Phone";
                    areaCodeChanged = areaCodeChanged || e.PropertyName == "PhoneAreaCode";
                    officeChanged = officeChanged || e.PropertyName == "PhoneOffice";
                    extensionChanged = extensionChanged || e.PropertyName == "PhoneExtension";
                    stringChanged = stringChanged || e.PropertyName == "PhoneString";
                };

            var newValue = 5558675309;
            target.Phone = newValue;
            Assert.AreEqual(newValue, target.Phone);
            Assert.IsTrue(phoneChanged, "Phone not seen in delegate.");
            Assert.IsTrue(areaCodeChanged, "PhoneAreaCode not seen in delegate.");
            Assert.IsTrue(officeChanged, "PhoneOffice not seen in delegate.");
            Assert.IsTrue(extensionChanged, "PhoneExtension not seen in delegate.");
            Assert.IsTrue(stringChanged, "PhoneString not seen in delegate.");
        }
 public void PhoneOfficeTest()
 {
     Contact target = new Contact();
     target.Phone = 5558675309;
     int expected = 867;
     int actual = target.PhoneOffice;
     Assert.AreEqual(expected, actual);
 }
        public void LastNameNotifyTest()
        {
            // based on http://www.benday.com/2010/08/24/an-easier-way-to-unit-test-inotifypropertychanged-in-silverlightwpf/
            Contact target = new Contact("Blast", "Hardcheese");
            bool lastNameChanged = false;
            bool fullNameChanged = false;
            ((INotifyPropertyChanged)target).PropertyChanged +=
                delegate(object sender, PropertyChangedEventArgs e)
                {
                    lastNameChanged = lastNameChanged || e.PropertyName == "LastName";
                    fullNameChanged = fullNameChanged || e.PropertyName == "FullName";
                };

            var newValue = "Softcheese";
            target.LastName = newValue;
            Assert.AreEqual(newValue, target.LastName);
            Assert.IsTrue(lastNameChanged, "LastName not seen in delegate.");
            Assert.IsTrue(fullNameChanged, "FullName not seen in delegate.");
        }
 public void PhoneExtensionTest()
 {
     Contact target = new Contact();
     target.Phone = 5558675309;
     int expected = 5309;
     int actual = target.PhoneExtension;
     Assert.AreEqual(expected, actual);
 }
 public void FullNameTest()
 {
     Contact target = new Contact("Butch", "Deadlift");
     Assert.AreEqual("Butch Deadlift", target.FullName);
 }
 public void ContactConstructorNoArgumentsTest()
 {
     Contact target = new Contact();
     // default values
     Assert.IsNull(target.FirstName);
     Assert.IsNull(target.LastName);
     Assert.AreEqual(0, target.Phone);
     Assert.IsNull(target.Address);
     Assert.IsNull(target.City);
     Assert.IsNull(target.State);
     Assert.AreEqual(0, target.Zip);
 }
 public void ContactConstructorNameArgumentsTest()
 {
     string first = "Fridge";
     string last = "Largemeat";
     Contact target = new Contact(first, last);
     Assert.AreEqual(first, target.FirstName);
     Assert.AreEqual(last, target.LastName);
     // default values
     Assert.AreEqual(0, target.Phone);
     Assert.IsNull(target.Address);
     Assert.IsNull(target.City);
     Assert.IsNull(target.State);
     Assert.AreEqual(0, target.Zip);
 }
 public void ContactConstructorAllArgumentsTest()
 {
     string first = "Slab";
     string last = "Bulkhead";
     long phone = 5558675309;
     string address = "123 Fake Street";
     string city = "Faketon";
     string state = "MO";
     int zip = 123123;
     Contact target = new Contact(first, last, phone, address, city, state, zip);
     Assert.AreEqual(first, target.FirstName);
     Assert.AreEqual(last, target.LastName);
     Assert.AreEqual(phone, target.Phone);
     Assert.AreEqual(address, target.Address);
     Assert.AreEqual(city, target.City);
     Assert.AreEqual(state, target.State);
     Assert.AreEqual(zip, target.Zip);
 }
Esempio n. 14
0
 public void Copy(Contact other)
 {
     FirstName = other.FirstName;
     LastName = other.LastName;
     Phone = other.Phone;
     Address = other.Address;
     City = other.City;
     State = other.State;
     Zip = other.Zip;
 }