Esempio n. 1
0
        public void IteratorWithoutDependenciesUnsubscribesFromAllSourceEventsWhenDisposed()
        {
            var sourceCollection = With.Inputs(Mike, Tom, Jack);

            var contactIterator = new SimpleIterator <Contact>(sourceCollection);

            Assert.IsFalse(Mike.HasPropertyChangedSubscribers);
            Assert.IsFalse(Tom.HasPropertyChangedSubscribers);
            Assert.IsFalse(Jack.HasPropertyChangedSubscribers);
            // TODO: Assert.IsTrue(sourceCollection.HasPropertyChangedSubscribers);
            // TODO: Assert.IsTrue(sourceCollection.HasCollectionChangedSubscribers);

            contactIterator.GetEnumerator();

            Assert.IsFalse(Mike.HasPropertyChangedSubscribers);
            Assert.IsFalse(Tom.HasPropertyChangedSubscribers);
            Assert.IsFalse(Jack.HasPropertyChangedSubscribers);
            // TODO: Assert.IsTrue(sourceCollection.HasPropertyChangedSubscribers);
            // TODO: Assert.IsTrue(sourceCollection.HasCollectionChangedSubscribers);

            contactIterator.Dispose();

            Assert.IsFalse(Mike.HasPropertyChangedSubscribers);
            Assert.IsFalse(Tom.HasPropertyChangedSubscribers);
            Assert.IsFalse(Jack.HasPropertyChangedSubscribers);
            // TODO: Assert.IsFalse(sourceCollection.HasPropertyChangedSubscribers);
            // TODO: Assert.IsFalse(sourceCollection.HasCollectionChangedSubscribers);
        }
Esempio n. 2
0
        public void UnionSpecification()
        {
            var additionalContacts = With.Inputs(John, Tom, Jarryd);

            Specification.Title("Union()")
            .TestingOver <Contact>()
            .UsingBindableLinq(inputs => inputs.AsBindable().Union(additionalContacts.AsBindable()))
            .UsingStandardLinq(inputs => inputs.Union(additionalContacts))
            .Scenario("Delayed evaluation",
                      With.Inputs(Mike, Tom, Jack),
                      step => Upon.Construction().ItWill.NotHaveEvaluated(),
                      step => Upon.Evaluate().ItWill.HaveCount(6)
                      )
            .Scenario("Adding items",
                      With.Inputs(Mike, Tom, Jack),
                      step => Upon.Add(Rick, Mick).ItWill.NotRaiseAnything(),
                      step => Upon.Evaluate().ItWill.NotRaiseAnything(),
                      step => Upon.Add(Jarryd).ItWill.Raise(Add.With(Jarryd).At(8)),
                      step => Upon.Add(Tom, Sally).ItWill.Raise(Add.With(Tom).At(9)).And.Raise(Add.With(Sally).At(10)),
                      step => Upon.Insert(2, Simon).ItWill.Raise(Add.With(Simon).At(11)),
                      step => Upon.Insert(3, Phil, Jake).ItWill.Raise(Add.With(Phil).At(12)).And.Raise(Add.With(Jake).At(13)),
                      step => Upon.Evaluate().ItWill.NotRaiseAnything()
                      )
            .Verify();
        }
        public void IndexerNaturalOrder()
        {
            var bindingList = With.Inputs(Brian, Gordon, Harry).AsBindable().ToBindingList();

            Assert.AreSame(Brian, bindingList[0]);
            Assert.AreSame(Gordon, bindingList[1]);
            Assert.AreSame(Harry, bindingList[2]);
        }
Esempio n. 4
0
 public void IteratorIListMethodsForceLoad()
 {
     ForcesLoad(With.Inputs(Tom, Sam, Sally), iterator => iterator.Contains(Tom));
     ForcesLoad(With.Inputs(Tom, Sam, Sally), iterator => iterator.GetEnumerator());
     ForcesLoad(With.Inputs(Tom, Sam, Sally), iterator => iterator.Count);
     // TODO: ForcesLoad(With.Inputs(Tom, Sam, Sally), iterator => iterator[2]);
     ForcesLoad(With.Inputs(Tom, Sam, Sally), iterator => ((IList)iterator)[2]);
     DoesNotForceLoad(With.Inputs(Tom, Sam, Sally), iterator => iterator.ToString());
 }
Esempio n. 5
0
        public void IteratorWithDepenedenciesDoesNotEnumerateSourceUntilResultIsEnumerated()
        {
            var sourceCollection = new SourceCollection(With.Inputs(Tom, Tim, Jack));

            Assert.AreEqual(0, sourceCollection.GetEnumeratorCalls);

            var contactIterator = new SimpleIterator <Contact>(sourceCollection.AsBindable());

            Assert.AreEqual(0, sourceCollection.GetEnumeratorCalls);

            contactIterator.AcceptDependency(new ItemDependencyDefinition("Name"));
            Assert.AreEqual(0, sourceCollection.GetEnumeratorCalls);

            foreach (var c in contactIterator)
            {
            }
            Assert.AreEqual(1, sourceCollection.GetEnumeratorCalls);

            contactIterator.Dispose();
            Assert.AreEqual(1, sourceCollection.GetEnumeratorCalls);
        }
Esempio n. 6
0
        public void IteratorUnsubscribesFromItemWhenRemoved()
        {
            var sourceCollection = With.Inputs(Mike, Tom, Jack);

            var contactIterator = new SimpleIterator <Contact>(sourceCollection);

            Assert.IsFalse(Mike.HasPropertyChangedSubscribers);
            Assert.IsFalse(Tom.HasPropertyChangedSubscribers);
            Assert.IsFalse(Jack.HasPropertyChangedSubscribers);
            // TODO: Assert.IsTrue(sourceCollection.HasPropertyChangedSubscribers);
            // TODO: Assert.IsTrue(sourceCollection.HasCollectionChangedSubscribers);

            contactIterator.AcceptDependency(new ItemDependencyDefinition("Name"));
            foreach (var c in contactIterator)
            {
            }

            Assert.IsTrue(Mike.HasPropertyChangedSubscribers);
            Assert.IsTrue(Tom.HasPropertyChangedSubscribers);
            Assert.IsTrue(Jack.HasPropertyChangedSubscribers);
            // TODO: Assert.IsTrue(sourceCollection.HasPropertyChangedSubscribers);
            // TODO: Assert.IsTrue(sourceCollection.HasCollectionChangedSubscribers);

            sourceCollection.Remove(Tom);

            Assert.IsTrue(Mike.HasPropertyChangedSubscribers);
            Assert.IsFalse(Tom.HasPropertyChangedSubscribers);
            Assert.IsTrue(Jack.HasPropertyChangedSubscribers);
            // TODO: Assert.IsTrue(sourceCollection.HasPropertyChangedSubscribers);
            // TODO: Assert.IsTrue(sourceCollection.HasCollectionChangedSubscribers);

            contactIterator.Dispose();

            Assert.IsFalse(Mike.HasPropertyChangedSubscribers);
            Assert.IsFalse(Tom.HasPropertyChangedSubscribers);
            Assert.IsFalse(Jack.HasPropertyChangedSubscribers);
            // TODO: Assert.IsFalse(sourceCollection.HasPropertyChangedSubscribers);
            // TODO: Assert.IsFalse(sourceCollection.HasCollectionChangedSubscribers);
        }
 private IBindingList NewTestBindingList()
 {
     return(With.Inputs(Gordon, Brian, Harry).AsBindable().OrderBy(c => c.Name).ToBindingList());
 }
Esempio n. 8
0
        /// <summary>
        /// The select specification.
        /// </summary>
        public void ExecuteSelectSpecification <TProjectionResult>(string title, Expression <Func <Contact, TProjectionResult> > selector)
        {
            var p = selector.Compile();

            Specification.Title(title)
            .TestingOver <Contact>()
            .UsingBindableLinq(inputs => inputs.AsBindable().Select(selector))
            .UsingStandardLinq(inputs => inputs.Select(p))
            .Scenario("Delayed evaluation",
                      With.Inputs(Mike, Tom, Jack),
                      step => Upon.Construction().ItWill.NotHaveEvaluated(),
                      step => Upon.Evaluate().ItWill.HaveCount(3)
                      )
            .Scenario("Adding items",
                      With.Inputs(Mike, Tom, Jack),
                      step => Upon.Add(John, Mick).ItWill.NotRaiseAnything(),
                      step => Upon.Evaluate().ItWill.NotRaiseAnything(),
                      step => Upon.Add(Jarryd).ItWill.Raise(Add.With(p(Jarryd)).At(5)),
                      step => Upon.Add(Tom, Sally).ItWill.Raise(Add.With(p(Tom)).At(6)).And.Raise(Add.With(p(Sally)).At(7)),
                      step => Upon.Insert(2, Simon).ItWill.Raise(Add.With(p(Simon)).At(2)),
                      step => Upon.Insert(3, Phil, Jake).ItWill.Raise(Add.With(p(Phil)).At(3)).And.Raise(Add.With(p(Jake)).At(4)),
                      step => Upon.Evaluate().ItWill.NotRaiseAnything()
                      )
            .Scenario("Moving items",
                      With.Inputs(Mike, Tom, Jack, John, Sally, Sam, Tim, Clancy),
                      step => Upon.Evaluate().ItWill.NotRaiseAnything(),
                      step => Upon.Move(5, Mike).ItWill.Raise(Move.With(p(Mike)).AtNew(5).AtOld(0)),
                      step => Upon.Move(6, Jack, John).ItWill.Raise(Move.With(p(Jack)).AtNew(6).AtOld(1)).And.Raise(Move.With(p(John)).AtNew(7).AtOld(1))
                      )
            .Scenario("Moving non-consecutive items",
                      With.Inputs(Mike, Tom, Jack, John, Sally, Sam, Tim, Clancy),
                      step => Upon.Evaluate().ItWill.NotRaiseAnything(),
                      step => Upon.Move(6, Mike, John).ItWill.Raise(Move.With(p(Mike)).AtNew(6).AtOld(0)).And.Raise(Move.With(p(John)).AtNew(7).AtOld(2))
                      )
            .Scenario("Removing items",
                      With.Inputs(Mike, Tom, Jack, John, Sally, Sam, Tim, Clancy),
                      step => Upon.Remove(Jack).ItWill.NotRaiseAnything(),
                      step => Upon.Evaluate().ItWill.NotRaiseAnything().And.HaveCount(7),
                      step => Upon.Remove(John).ItWill.Raise(Remove.With(p(John)).At(2)),
                      step => Upon.Remove(Sally, Sam).ItWill.Raise(Remove.With(p(Sally)).At(2)).And.Raise(Remove.With(p(Sam)).At(3)),
                      step => Upon.Remove(Mike, Clancy).ItWill.Raise(Remove.With(p(Mike)).At(0)).And.Raise(Remove.With(p(Clancy)).At(3))
                      )
            .Scenario("Replacing items",
                      With.Inputs(Mike, Tom, Jack, Clancy),
                      step => Upon.Replace(Mike).With(Sally).ItWill.NotRaiseAnything(),
                      step => Upon.Evaluate(),
                      step => Upon.Replace(Jack).With(Sam).ItWill.Raise(Replace.WithOld(p(Jack)).WithNew(p(Sam))),
                      step => Upon.Replace(Sally, Tom).With(Gordon, Sue).ItWill.Raise(Replace.WithOld(p(Sally), p(Tom)).WithNew(p(Gordon), p(Sue)))
                      )
            .Scenario("Replacing non-consecutive items",
                      With.Inputs(Mike, Tom, Jack, Clancy),
                      step => Upon.Evaluate(),
                      step => Upon.Replace(Mike, Clancy).With(Gordon, Sue).ItWill.Raise(Replace.WithOld(p(Mike)).WithNew(p(Gordon))).And.Raise(Replace.WithOld(p(Clancy)).WithNew(p(Sue)))
                      )
            .Scenario("Replacing item that isn't in source",
                      With.Inputs(Mike, Tom, Jack),
                      step => Upon.Evaluate(),
                      step => Upon.Replace(Mike, Clancy).With(Gordon, Sue).ItWill.Raise(Replace.WithOld(p(Mike)).WithNew(p(Gordon))).And.Raise(Add.With(p(Sue)))
                      )
            .Verify();
            // TODO: Add scenarios common workflows like adding and removing an item, and edge cases
        }
Esempio n. 9
0
 public void WhereSpecification()
 {
     Specification.Title("Where() specification")
     .TestingOver <Contact>()
     .UsingBindableLinq(inputs => inputs.AsBindable().Where(p => p.Name.Length >= 4))
     .UsingStandardLinq(inputs => inputs.Where(p => p.Name.Length >= 4))
     .Scenario("Delayed evaluation",
               With.Inputs(Mike, Tom, Jack),
               step => Upon.Construction().ItWill.NotHaveEvaluated(),
               step => Upon.Evaluate().ItWill.HaveCount(2)
               )
     .Scenario("Adding items",
               With.Inputs(Mike, Tom, Jack),
               step => Upon.Add(John, Mick).ItWill.NotRaiseAnything(),
               step => Upon.Evaluate().ItWill.NotRaiseAnything(),
               step => Upon.Add(Jarryd).ItWill.Raise(Add.With(Jarryd).At(4)),
               step => Upon.Add(Tim).ItWill.NotRaiseAnything(),
               step => Upon.Add(Tom, Sally).ItWill.Raise(Add.With(Sally).At(5)),
               step => Upon.Insert(2, Simon).ItWill.Raise(Add.With(Simon).At(2)),
               //step => Upon.Insert(3, Phil, Jake).ItWill.Raise(Add.With(Phil, Jake).At(3)),
               //step => Upon.Insert(3, Rick, Ryan, Tim).ItWill.Raise(Add.With(Rick, Ryan).At(3)),
               step => Upon.Evaluate().ItWill.NotRaiseAnything()
               )
     //.Scenario("Moving items",
     //    With.Inputs(Mike, Tom, Jack, John, Sally, Sam, Tim, Clancy),
     //    step => Upon.Evaluate().ItWill.NotRaiseAnything().And.HaveCount(5),
     //    step => Upon.Move(3, Mike).ItWill.Raise(Move.With(Mike).AtNew(3).AtOld(0)),
     //    step => Upon.Move(3, Tom).ItWill.NotRaiseAnything(),
     //    step => Upon.Move(4, Jack, John).ItWill.Raise(Move.With(Jack).AtNew(4).AtOld(0)).And.Raise(Move.With(John).AtNew(4).AtOld(0))
     //    )
     //.Scenario("Moving non-consecutive items",
     //    With.Inputs(Mike, Tom, Jack, John, Sally, Sam, Tim, Clancy),
     //    step => Upon.Evaluate().ItWill.NotRaiseAnything(),
     //    step => Upon.Move(6, Mike, John).ItWill.Raise(Move.With(projected(Mike)).AtNew(6).AtOld(0)).And.Raise(Move.With(projected(John)).AtNew(7).AtOld(2))
     //    )
     //.Scenario("Removing items",
     //    With.Inputs(Mike, Tom, Jack, John, Sally, Sam, Tim, Clancy),
     //    step => Upon.Remove(Jack).ItWill.NotRaiseAnything(),
     //    step => Upon.Evaluate().ItWill.NotRaiseAnything().And.HaveCount(7),
     //    step => Upon.Remove(John).ItWill.Raise(Remove.With(projected(John)).At(2)),
     //    step => Upon.Remove(Sally, Sam).ItWill.Raise(Remove.With(projected(Sally), projected(Sam)).At(2)),
     //    step => Upon.Remove(Mike, Clancy).ItWill.Raise(Remove.With(projected(Mike)).At(0)).And.Raise(Remove.With(projected(Clancy)).At(3))
     //    )
     //.Scenario("Replacing items",
     //    With.Inputs(Mike, Tom, Jack, Clancy),
     //    step => Upon.Replace(Mike).With(Sally).ItWill.NotRaiseAnything(),
     //    step => Upon.Evaluate(),
     //    step => Upon.Replace(Jack).With(Sam).ItWill.Raise(Replace.WithOld(projected(Jack)).WithNew(projected(Sam))),
     //    step => Upon.Replace(Sally, Tom).With(Gordon, Sue).ItWill.Raise(Replace.WithOld(projected(Sally), projected(Tom)).WithNew(projected(Gordon), projected(Sue)))
     //    )
     //.Scenario("Replacing non-consecutive items",
     //    With.Inputs(Mike, Tom, Jack, Clancy),
     //    step => Upon.Evaluate(),
     //    step => Upon.Replace(Mike, Clancy).With(Gordon, Sue).ItWill.Raise(Replace.WithOld(projected(Mike)).WithNew(projected(Gordon))).And.Raise(Replace.WithOld(projected(Clancy)).WithNew(projected(Sue)))
     //    )
     //.Scenario("Replacing item that isn't in source",
     //    With.Inputs(Mike, Tom, Jack),
     //    step => Upon.Evaluate(),
     //    step => Upon.Replace(Mike, Clancy).With(Gordon, Sue).ItWill.Raise(Replace.WithOld(projected(Mike)).WithNew(projected(Gordon))).And.Raise(Add.With(projected(Sue)))
     //    )
     .Verify();
 }