public void CollectionChangedIsCombinedWhenBufferingMultipleAddsAndRemoves()
        {
            var eventBuffer = new EventBuffer();
            var sut         = CreateSut(eventBuffer);

            sut.Add(3);
            eventBuffer.StartBuffering();
            var raised = false;

            sut.CollectionChanged += (sender, args) =>
            {
                Assert.AreEqual(new[] { -1, -2 }, args.AddedItems);
                Assert.AreEqual(new[] { 3 }, args.RemovedItems);
                raised = true;
            };

            sut.Add(-1);
            sut.Add(-1);
            sut.Add(-2);
            sut.Remove(-2);
            sut.Remove(3);
            sut.Add(-2);
            sut.Add(3);
            sut.Remove(3);
            eventBuffer.Flush();

            Assert.IsTrue(raised);
        }
示例#2
0
        public void BufferDoesNotInvokeWhenBuffering()
        {
            var sut        = new EventBuffer();
            var bufferable = new Mock <IBufferableEvent <int> >();

            sut.StartBuffering();
            sut.Buffer(bufferable.Object, 1);

            bufferable.VerifyNoOtherCalls();
        }
示例#3
0
        public void FlushInvokesBufferedCall()
        {
            var sut        = new EventBuffer();
            var bufferable = CreateBufferInvokedEvent(1);

            sut.StartBuffering();

            sut.Buffer(bufferable.Object, 1);
            sut.Flush();

            bufferable.Verify();
        }
示例#4
0
        public void BufferInvokesWhenBufferingStopped()
        {
            var sut        = new EventBuffer();
            var bufferable = CreateImmediatelyInvokedEvent(1);

            sut.StartBuffering();

            sut.StopBuffering();
            sut.Buffer(bufferable.Object, 1);

            bufferable.Verify();
        }
示例#5
0
        public void FlushMergesCallsWithSameSender()
        {
            var sut        = new EventBuffer();
            var bufferable = CreateBufferInvokedEvent(1, 2);

            sut.StartBuffering();

            sut.Buffer(bufferable.Object, 1);
            sut.Buffer(bufferable.Object, 2);
            sut.Flush();

            bufferable.Verify();
        }
示例#6
0
        public void FlushClearsBuffer()
        {
            var sut        = new EventBuffer();
            var bufferable = new Mock <IBufferableEvent <int> >();

            sut.StartBuffering();
            sut.Buffer(bufferable.Object, 1);
            sut.Flush();
            bufferable.Reset();

            sut.Flush();

            bufferable.VerifyNoOtherCalls();
        }
示例#7
0
 public void Update(CalculatorUpdate update)
 {
     _eventBuffer.StartBuffering();
     foreach (var modifier in update.RemovedModifiers)
     {
         _modifierCollection.RemoveModifier(modifier);
     }
     foreach (var modifier in update.AddedModifiers)
     {
         _modifierCollection.AddModifier(modifier);
     }
     _graphPruner.RemoveUnusedNodes();
     _eventBuffer.Flush();
     _eventBuffer.StopBuffering();
 }
示例#8
0
        public void FlushKeepsCallsWithDifferentSender()
        {
            var sut         = new EventBuffer();
            var bufferable1 = CreateBufferInvokedEvent(1);
            var bufferable2 = CreateBufferInvokedEvent(2);

            sut.StartBuffering();

            sut.Buffer(bufferable1.Object, 1);
            sut.Buffer(bufferable2.Object, 2);
            sut.Flush();

            bufferable1.Verify();
            bufferable2.Verify();
        }
示例#9
0
        public void FlushLoopsOverBuffers()
        {
            var sut         = new EventBuffer();
            var bufferable1 = CreateBufferInvokedEvent(1);
            var bufferable2 = CreateBufferInvokedEvent(2);

            bufferable1.Setup(b => b.Invoke(It.IsAny <List <int> >()))
            .Callback(() => sut.Buffer(bufferable2.Object, 2));
            sut.StartBuffering();

            sut.Buffer(bufferable1.Object, 1);
            sut.Flush();

            bufferable1.Verify();
            bufferable2.Verify();
        }
示例#10
0
        public void InvokesAddAndRemoveOnAddAndRemove()
        {
            var stats          = new[] { new Stat("a"), new Stat("b"), new Stat("c"), };
            var actualAdded    = new List <IStat>();
            var actualRemoved  = new List <IStat>();
            var eventBuffer    = new EventBuffer();
            var nodeCollection = CreateNodeCollection(eventBuffer);

            SetupSut(nodeCollection, actualAdded, actualRemoved);
            nodeCollection.Add(null, stats[0]);
            nodeCollection.Add(null, stats[1]);
            actualAdded.Clear();

            eventBuffer.StartBuffering();
            nodeCollection.Add(null, stats[2]);
            nodeCollection.Remove(null, stats[0]);
            eventBuffer.Flush();

            Assert.AreEqual(stats.Skip(2), actualAdded);
            Assert.AreEqual(stats.Take(1), actualRemoved);
        }