示例#1
0
        public void Entity_RaiseDataMemberChanged()
        {
            MockEntity_RaisePropertyChangedEvents entity = new MockEntity_RaisePropertyChangedEvents();

            entity.StartTracking();

            ConfigurableEntityContainer container = new ConfigurableEntityContainer();

            container.CreateSet <MockEntity_RaisePropertyChangedEvents>(EntitySetOperations.All);
            container.GetEntitySet <MockEntity_RaisePropertyChangedEvents>().Add(entity);

            List <string> propertyChanges = new List <string>();

            entity.PropertyChanged += (s, a) => propertyChanges.Add(a.PropertyName);

            // Real property, should have no errors
            entity.Mock_RaiseDataMemberChanging("Property1");
            entity.Mock_RaiseDataMemberChanged("Property1");
            entity.Mock_RaiseDataMemberChanged("Property1"); // Called twice to ensure we go through the Entity::PropertyHasChanged code path

            Assert.AreEqual(2, propertyChanges.Count(p => p == "Property1"));
        }
示例#2
0
        public void Entity_RaiseDataMemberChanged_NonChangeTrackedProperty()
        {
            MockEntity_RaisePropertyChangedEvents entity = new MockEntity_RaisePropertyChangedEvents();

            entity.StartTracking();

            ConfigurableEntityContainer container = new ConfigurableEntityContainer();

            container.CreateSet <MockEntity_RaisePropertyChangedEvents>(EntitySetOperations.All);
            container.GetEntitySet <MockEntity_RaisePropertyChangedEvents>().Add(entity);

            List <string> propertyChanges = new List <string>();

            entity.PropertyChanged += (s, a) => propertyChanges.Add(a.PropertyName);

            // Non-existent property - we don't do any validation internally
            // for this. The methods are protected, so we don't attempt to protect
            // the user from lying to themselves.
            entity.Mock_RaiseDataMemberChanging("CalculatedProperty1");
            entity.Mock_RaiseDataMemberChanged("CalculatedProperty1");
            entity.Mock_RaiseDataMemberChanged("CalculatedProperty1");

            Assert.AreEqual(2, propertyChanges.Count(p => p == "CalculatedProperty1"));
        }