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(); }
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); }
public void FlushInvokesBufferedCall() { var sut = new EventBuffer(); var bufferable = CreateBufferInvokedEvent(1); sut.StartBuffering(); sut.Buffer(bufferable.Object, 1); sut.Flush(); bufferable.Verify(); }
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(); }
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(); }
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(); }
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(); }
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); }