/// <summary>
        /// Initializes a new instance of the AddressViewModel class.
        /// </summary>
        /// <param name="detail">The underlying Address this ViewModel is to be based on</param>
        public AddressViewModel(Address detail)
        {
            if (detail == null)
            {
                throw new ArgumentNullException("detail");
            }

            this.address = detail;
        }
Exemple #2
0
        public void AddContactDetailFromDefaultConstructor()
        {
            using (FakeEmployeeContext ctx = new FakeEmployeeContext())
            {
                UnitOfWork unit = new UnitOfWork(ctx);
                Employee emp = new Employee();
                unit.AddEmployee(emp);

                ContactDetail cd = new Address();
                unit.AddContactDetail(emp, cd);
                Assert.IsTrue(ctx.ContactDetails.Contains(cd), "ContactDetail was not added to underlying context.");
            }
        }
        public void PropertyGetAndSet()
        {
            // Test initial properties are surfaced in ViewModel
            Address add = new Address { LineOne = "LineOne", LineTwo = "LineTwo", City = "City", State = "State", ZipCode = "ZipCode", Country = "Country" };
            AddressViewModel vm = new AddressViewModel(add);
            Assert.AreEqual(add, vm.Model, "Bound object property did not return object from model.");
            Assert.AreEqual(add.ValidUsageValues, vm.ValidUsageValues, "ValidUsageValues property did not return value from model.");
            Assert.AreEqual("LineOne", vm.LineOne, "LineOne property did not return value from model.");
            Assert.AreEqual("LineTwo", vm.LineTwo, "LineTwo property did not return value from model.");
            Assert.AreEqual("City", vm.City, "City property did not return value from model.");
            Assert.AreEqual("State", vm.State, "State property did not return value from model.");
            Assert.AreEqual("ZipCode", vm.ZipCode, "ZipCode property did not return value from model.");
            Assert.AreEqual("Country", vm.Country, "Country property did not return value from model.");

            // Test changing properties updates Model and raises PropertyChanged
            string lastProperty;
            vm.PropertyChanged += (sender, e) => { lastProperty = e.PropertyName; };

            lastProperty = null;
            vm.LineOne = "LineOne_NEW";
            Assert.AreEqual("LineOne", lastProperty, "Setting LineOne property did not raise correct PropertyChanged event.");
            Assert.AreEqual("LineOne_NEW", add.LineOne, "Setting LineOne property did not update model.");

            lastProperty = null;
            vm.LineTwo = "LineTwo_NEW";
            Assert.AreEqual("LineTwo", lastProperty, "Setting LineTwo property did not raise correct PropertyChanged event.");
            Assert.AreEqual("LineTwo_NEW", add.LineTwo, "Setting LineTwo property did not update model.");

            lastProperty = null;
            vm.City = "City_NEW";
            Assert.AreEqual("City", lastProperty, "Setting City property did not raise correct PropertyChanged event.");
            Assert.AreEqual("City_NEW", add.City, "Setting City property did not update model.");

            lastProperty = null;
            vm.State = "State_NEW";
            Assert.AreEqual("State", lastProperty, "Setting State property did not raise correct PropertyChanged event.");
            Assert.AreEqual("State_NEW", add.State, "Setting State property did not update model.");

            lastProperty = null;
            vm.ZipCode = "ZipCode_NEW";
            Assert.AreEqual("ZipCode", lastProperty, "Setting ZipCode property did not raise correct PropertyChanged event.");
            Assert.AreEqual("ZipCode_NEW", add.ZipCode, "Setting ZipCode property did not update model.");

            lastProperty = null;
            vm.Country = "Country_NEW";
            Assert.AreEqual("Country", lastProperty, "Setting Country property did not raise correct PropertyChanged event.");
            Assert.AreEqual("Country_NEW", add.Country, "Setting Country property did not update model.");
        }
        public void BuildViewModel()
        {
            Phone p = new Phone();
            Email e = new Email();
            Address a = new Address();

            var pvm = ContactDetailViewModel.BuildViewModel(p);
            Assert.IsInstanceOfType(pvm, typeof(PhoneViewModel), "Factory method created wrong ViewModel type.");
            Assert.AreEqual(p, pvm.Model, "Underlying model object on ViewModel is not correct.");

            var evm = ContactDetailViewModel.BuildViewModel(e);
            Assert.IsInstanceOfType(evm, typeof(EmailViewModel), "Factory method created wrong ViewModel type.");
            Assert.AreEqual(e, evm.Model, "Underlying model object on ViewModel is not correct.");

            var avm = ContactDetailViewModel.BuildViewModel(a);
            Assert.IsInstanceOfType(avm, typeof(AddressViewModel), "Factory method created wrong ViewModel type.");
            Assert.AreEqual(a, avm.Model, "Underlying model object on ViewModel is not correct.");
        }
        public void ModelChangesFlowToProperties()
        {
            // Test ViewModel returns current value from model
            Address add = new Address { LineOne = "Address", LineTwo = "LineTwo", City = "City", State = "State", ZipCode = "ZipCode", Country = "Country" };
            AddressViewModel vm = new AddressViewModel(add);

            vm.LineOne = "LineOne_NEW";
            Assert.AreEqual("LineOne_NEW", add.LineOne, "LineOne property is not fetching the value from the model.");
            vm.LineTwo = "LineTwo_NEW";
            Assert.AreEqual("LineTwo_NEW", add.LineTwo, "LineTwo property is not fetching the value from the model.");
            vm.City = "City_NEW";
            Assert.AreEqual("City_NEW", add.City, "City property is not fetching the value from the model.");
            vm.State = "State_NEW";
            Assert.AreEqual("State_NEW", add.State, "State property is not fetching the value from the model.");
            vm.ZipCode = "ZipCode_NEW";
            Assert.AreEqual("ZipCode_NEW", add.ZipCode, "ZipCode property is not fetching the value from the model.");
            vm.Country = "Country_NEW";
            Assert.AreEqual("Country_NEW", add.Country, "Country property is not fetching the value from the model.");
        }