public void Remove_ItemReferenceCountIsTwo_ReturnsFalse()
 {
     Person person = new Person();
     _target.Add(person);
     _target.Add(person);
     Assert.IsFalse(_target.Remove(person));
 }
Exemplo n.º 2
0
 public static ObservableCollection<Person> CreateParents(Person person)
 {
     return new ObservableCollection<Person>()
     {
         new Person(person.Name + "Parent0", 40),
         new Person(person.Name + "Parent1", 41),
     };
 }
Exemplo n.º 3
0
        public void Where_FilterContainsTwoLevelConstantWithConstantNull_CorrectResultsReturned()
        {
            Person person = new Person("Ninja", 20);

            ReadOnlyContinuousCollection<Person> peopleMatchingAge = person.GetPeopleWithSameAgeAsBrother(_source);

            Assert.AreEqual(0, peopleMatchingAge.Count);
        }
Exemplo n.º 4
0
        public void Where_FilterContainsAConstant_CorrectlyFiltered()
        {
            Person person = new Person("Ninja", 20);

            ReadOnlyContinuousCollection<Person> peopleMatchingAge = person.GetPeopleWithSameAge(_source);

            Assert.AreEqual(1, peopleMatchingAge.Count);
        }
        public void AddItemToFirst_IsNotInSecond_WillBeAddedToOutput()
        {
            var newPerson = new Person { Name = "Frank" };
            _first.Add(newPerson);

            Assert.AreEqual(3, _target.Count);
            Assert.IsTrue(_target.Contains(newPerson));
        }
Exemplo n.º 6
0
        public void GetValue_PropertyIsReferenceType_GetsBoxedAndReturnsCorrectValue()
        {
            Person brother = new Person();
            _person.Brother = brother;

            _target = DynamicProperty.Create(typeof(Person), "Brother");
            object brotherDynamic = _target.GetValue(_person);
            Assert.AreSame(brother, brotherDynamic);
        }
        public void Equals_ClosureHavingSameTarget_True()
        {
            Person comparsionPerson = new Person();

            Expression<Func<Person, bool>> expressionZero = person => person.Name == comparsionPerson.Name;
            Expression<Func<Person, bool>> expressionOne = person => person.Name == comparsionPerson.Name;

            Assert.IsTrue(_target.Equals(expressionZero, expressionOne));
            Assert.AreEqual(_target.GetHashCode(expressionZero), _target.GetHashCode(expressionOne));
        }
        public void ChangeFirstLevelProperty_TwoLevelPropertyTreeAndPropertyInTree_AllNodesSubscribed()
        {
            int callCount = 0;
            _target.PropertyChanged += () => callCount++;

            Person brother = new Person();
            _person.Brother = brother;

            Assert.AreEqual(1, callCount);
        }
Exemplo n.º 9
0
        public void FirstOrDefault_GetFirstItemAfterMove()
        {
            Person newFirst = new Person() { Age = 40, Name = "New" };

            ContinuousValue<Person> firstPerson = _source.ContinuousFirstOrDefault();

            _source.Insert(0, newFirst);

            Assert.AreEqual(newFirst, firstPerson.CurrentValue);
        }
        public void Clear_ItemReferenceCountIsTwo_NextAddReturnsTrue()
        {
            Person person = new Person();
            _target.Add(person);
            _target.Add(person);

            _target.Clear();

            Assert.IsTrue(_target.Add(person));
        }
Exemplo n.º 11
0
        public void ChangeFirstLevelProperty_TwoLevelPropertyTreeAndPropertyNotInTree_EventNotFired()
        {
            int callCount = 0;
            _target.PropertyChanged += () => callCount++;

            Person brother = new Person();
            _person.Age = 12132231;

            Assert.AreEqual(0, callCount);
        }
        public void Equals_ClosureHavingDifferentTarget_False()
        {
            Person comparsionPersonZero = new Person();
            Expression<Func<Person, bool>> expressionZero = person => person.Name == comparsionPersonZero.Name;

            Person comparsionPersonOne = new Person();
            Expression<Func<Person, bool>> expressionOne = person => person.Name == comparsionPersonOne.Name;

            Assert.IsFalse(_target.Equals(expressionZero, expressionOne));
            Assert.AreNotEqual(_target.GetHashCode(expressionZero), _target.GetHashCode(expressionOne));
        }
        public void AddItemToSource_ItemFailsFilter_DoesNotFireCollectionChangedEvent()
        {
            Person newPerson = new Person() { Name = "NewPerson", Age = 8 };
            int callCount = 0;
            _target.CollectionChanged += (sender, args) =>
            {
                callCount++;
            };

            _source.Add(newPerson);
            Assert.AreEqual(0, callCount);
        }
        public void AddToFirst_Always_RaisesNotifyCollectionChangedWithAddActionAndCorrectValues()
        {
            var person = new Person();

            var eventArgsList = TestUtilities.GetCollectionChangedEventArgsList(_target);

            _first.Add(person);

            Assert.AreEqual(1, eventArgsList.Count);

            TestUtilities.AssertAdd(eventArgsList[0], 2, person);
        }
Exemplo n.º 15
0
        public void Where_FilterContainsAConstantWithPropertyChangingOnConstant_CorrectResultsReturned()
        {
            Person person = new Person("Ninja", 20);

            ReadOnlyContinuousCollection<Person> peopleMatchingAge = person.GetPeopleWithSameAge(_source);

            int callCount = 0;
            peopleMatchingAge.CollectionChanged += (sender, args) => callCount++;

            person.Age = 10;

            Assert.AreEqual(2, callCount); // one remove and one add
            Assert.AreEqual(1, peopleMatchingAge.Count);
        }
        public void AddItemToSource_ItemPassesFilter_FireCollectionChangedEvent()
        {
            Person newPerson = new Person() { Name = "NewPerson", Age = 100 };
            int callCount = 0;
            _target.CollectionChanged += (sender, args) =>
            {
                callCount++;
                Assert.AreEqual(NotifyCollectionChangedAction.Add, args.Action);
                Assert.AreEqual(newPerson, args.NewItems[0]);
            };

            _source.Add(newPerson);
            Assert.AreEqual(1, callCount);
        }
Exemplo n.º 17
0
        public void AddToSource_SingleItem_FiresAdd()
        {
            int callCount = 0;
            _target.Add += (sender, index, items) =>
            {
                callCount++;
                Assert.AreEqual(2, index);
                Assert.IsNotNull(items);
            };

            Person newPerson = new Person("New", 100);
            _source.Add(newPerson);
            Assert.AreEqual(1, callCount);
        }
        public void AddItemToSource_Always_FireCollectionChangedEvent()
        {
            Person newPerson = new Person() { Name = "NewPerson" };
            int callCount = 0;
            _target.CollectionChanged += (sender, args) =>
            {
                callCount++;
                Assert.AreEqual(NotifyCollectionChangedAction.Add, args.Action);
                Assert.AreEqual(2, args.NewStartingIndex);
                Assert.AreEqual("NewPerson", args.NewItems[0]);
            };

            _source.Add(newPerson);
            Assert.AreEqual(1, callCount);
        }
Exemplo n.º 19
0
        public static ObservableCollection<Person> CreateSixPersonSourceWithDuplicates()
        {
            Person bob = new Person("Bob", 10);
            Person jim = new Person("Jim", 20);

            ObservableCollection<Person> source = CreateSixPersonSource();
            source[0] = bob;
            source[1] = bob;
            source[2] = bob;

            source[4] = jim;
            source[5] = jim;

            return source;
        }
        public void AddItemToSource_NewPerson_FireCollectionChangedEvent()
        {
            Person person = new Person();
            int callCount = 0;
            _target.CollectionChanged += (sender, args) =>
            {
                callCount++;
                Assert.AreEqual(NotifyCollectionChangedAction.Add, args.Action);
                Assert.AreEqual(3, args.NewStartingIndex);
                Assert.AreEqual(person, args.NewItems[0]);
            };

            _source.Add(person);
            Assert.AreEqual(1, callCount);
        }
        public void GetCompiledExpressionAndExecuteBoth_ClosureInExpression_SameResult()
        {
            Person comparsonPerson = new Person("Bob", 200);

            Expression<Func<Person, bool>> expressionZero = person => person.Name == comparsonPerson.Name;
            Expression<Func<Person, bool>> expressionOne = person => person.Name == comparsonPerson.Name;

            Func<Person, bool> cachedZero = expressionZero.CachedCompile();
            Func<Person, bool> cachedOne = expressionOne.CachedCompile();

            Person personToTestAgainstZero = new Person("Bob", 123);
            Assert.IsTrue(cachedZero(personToTestAgainstZero));

            Person personToTestAgainstOne = new Person("Bob", 4564);
            Assert.IsTrue(cachedOne(personToTestAgainstOne));
        }
Exemplo n.º 22
0
        public void Setup()
        {
            _person = new Person();

            _ageAccessNode = new PropertyAccessNode(typeof(Person).GetProperty("Age"));
            _brotherAccessNode = new PropertyAccessNode(typeof(Person).GetProperty("Brother")) { Children = new List<PropertyAccessTreeNode>() { _ageAccessNode } };
            _parameterAccessNode = new ParameterNode(typeof(Person), "person") { Children = new List<PropertyAccessTreeNode>() { _brotherAccessNode } };

            _brotherNode = new SubscriptionNode() { AccessNode = _brotherAccessNode };
            _parameterNode = new SubscriptionNode() { AccessNode = _parameterAccessNode, Children = new List<SubscriptionNode>() { _brotherNode } };
            _parameterNode.Subject = _person;

            List<SubscriptionNode> nodes = new List<SubscriptionNode>() { _parameterNode };

            _target = new SubscriptionTree(_person, nodes);
        }
Exemplo n.º 23
0
        public void ChangeSecondLevelProperty_TwoLevelPropertyTreeAndPropertyInTree_AllNodesSubscribed()
        {
            Person brother = new Person();

            _person.Brother = brother;

            int parameterNodeCallCount = 0;
            _target.PropertyChanged += () => parameterNodeCallCount++;

            int brotherNodeCallCount = 0;
            _brotherNode.PropertyChanged += () => brotherNodeCallCount++;

            _person.Brother.Age = 100;

            Assert.AreEqual(0, parameterNodeCallCount);
            Assert.AreEqual(1, brotherNodeCallCount);
        }
Exemplo n.º 24
0
        public void ChangeSecondLevelProperty_TwoLevelPropertyTreeAndPropertyNotInTree_EventNotFired()
        {
            Person brother = new Person();

            _person.Brother = brother;

            int parameterNodeCallCount = 0;
            _target.PropertyChanged += () => parameterNodeCallCount++;

            int brotherNodeCallCount = 0;
            _brotherNode.PropertyChanged += () => brotherNodeCallCount++;

            _person.Brother.Name = "adfja";

            Assert.AreEqual(0, parameterNodeCallCount);
            Assert.AreEqual(0, brotherNodeCallCount);
        }
        public void CreateSubscriptionTreeChangeSecondLevelPropertyOnParameterAndThenModifyOldProperty_TwoLevelPropertyBeingMonitored_PropertyDoesNotChange()
        {
            InitializeTargetBrothersAgeAccess();

            Person brother = new Person();
            _person.Brother = brother;

            SubscriptionTree subscriptionTree = _target.CreateSubscriptionTree(_person);
            int callCount = 0;
            subscriptionTree.PropertyChanged += (sender) => callCount++;

            _person.Brother = null;

            brother.Age = 1000022;

            Assert.AreEqual(1, callCount);
        }
Exemplo n.º 26
0
        public void RemoveFromSource_LastItemInCollection_CountIsZeroAndNoExceptionThrown()
        {
            var sourceWithTwoItems = new ObservableCollection<Person>();
            var personOne = new Person("Bob", 10);
            var personTwo = new Person("Jim", 20);

            ReadOnlyContinuousCollection<string> output =
                from person in sourceWithTwoItems
                where person.Age <= 20
                orderby person.Name
                select person.Name;

            sourceWithTwoItems.Add(personOne);
            sourceWithTwoItems.Add(personTwo);
            sourceWithTwoItems.Remove(personOne);

            //Assert.AreEqual(_source.Count, output.Count);
        }
Exemplo n.º 27
0
        public void AddNewSublistToSource_SublistIsNull_DoesNotFireCollectionChangedEvent()
        {
            Person newPerson = new Person("Ninja", 23);

            int callCount = 0;

            _target.CollectionChanged += (sender, args) =>
            {
                callCount++;
            };

            _source.Insert(0, newPerson);
            Assert.AreEqual(0, callCount);

            Assert.AreEqual(4, _target.Count);
            Assert.AreEqual("BobParent0", _target[0].Name);
            Assert.AreEqual("BobParent1", _target[1].Name);
            Assert.AreEqual("JimParent0", _target[2].Name);
            Assert.AreEqual("JimParent1", _target[3].Name);
        }
Exemplo n.º 28
0
        public void AddItemToSource_SecondSublist_FireCollectionChangedEvent()
        {
            Person newPerson = new Person() { Name = "NewPerson", Age = 5 };
            int callCount = 0;

            _target.CollectionChanged += (sender, args) =>
            {
                callCount++;
                Assert.AreEqual(NotifyCollectionChangedAction.Add, args.Action);
                Assert.AreEqual(4, args.NewStartingIndex);
                Assert.AreEqual(newPerson, args.NewItems[0]);
            };

            _parents[1].Add(newPerson);
            Assert.AreEqual(1, callCount);

            Assert.AreEqual(5, _target.Count);
            Assert.AreEqual("BobParent0", _target[0].Name);
            Assert.AreEqual("BobParent1", _target[1].Name);
            Assert.AreEqual("JimParent0", _target[2].Name);
            Assert.AreEqual("JimParent1", _target[3].Name);
            Assert.AreEqual("NewPerson", _target[4].Name);
        }
        public void Analyze_ExpressionIncludesConstantImplementingINotifyPropertyChanged_TreeContainsTwoBranches()
        {
            Person localPersonAppearingAsConstantInExpression = new Person();
            Expression<Func<Person, int>> expression = p => p.Age + localPersonAppearingAsConstantInExpression.Age;

            PropertyAccessTree tree = ExpressionPropertyAnalyzer.Analyze(expression);

            Assert.AreEqual(2, tree.Children.Count);
            PropertyAccessTreeNode parameterNode = tree.Children[0];
            Assert.IsInstanceOfType(typeof(ParameterNode), parameterNode);
            Assert.AreEqual(1, parameterNode.Children.Count);

            PropertyAccessNode parameterAgeNode = (PropertyAccessNode)parameterNode.Children[0];
            Assert.AreEqual(_ageProperty, parameterAgeNode.Property);
            Assert.AreEqual(0, parameterAgeNode.Children.Count);

            PropertyAccessTreeNode constantNode = tree.Children[1];
            Assert.IsInstanceOfType(typeof(ConstantNode), constantNode);
            Assert.AreEqual(localPersonAppearingAsConstantInExpression, ((ConstantNode)constantNode).Value);
            Assert.AreEqual(1, constantNode.Children.Count);

            PropertyAccessNode constantAgeNode = (PropertyAccessNode)constantNode.Children[0];
            Assert.AreEqual(_ageProperty, constantAgeNode.Property);
            Assert.AreEqual(0, constantAgeNode.Children.Count);
        }
Exemplo n.º 30
0
 public void Setup()
 {
     _source = ClinqTestFactory.CreateSixPersonSourceWithDuplicates();
     _first = _source[0];
     _second = _source[3];
     _third = _source[4];
     _target = new ListIndexer<Person>(_source);
 }