public void Persister_Can_Successfully_Persist_New_Items_In_Memory() { var items = this.BuildItems(numberOfFeeds: 10, numberOfTweets: 20); var oldItem = this.BuildItem(DateTime.MinValue); var savedItems = new List<Item>(); var fakeStreamAggregator = new Mock<IItemAggregator>(); fakeStreamAggregator.Setup(a => a.GetLatest(DateTime.MinValue)).Returns(items); var fakeStreamProcessor = new Mock<IItemProcessor>(MockBehavior.Loose); var fakeStreamStorage = new Mock<IStreamStorage>(); fakeStreamStorage.Setup(s => s.Top()).Returns(oldItem); fakeStreamStorage.Setup(s => s.Save(It.IsAny<IEnumerable<Item>>())).Callback<IEnumerable<Item>>(savedItems.AddRange); var streamPersister = new StreamPersister(fakeStreamAggregator.Object, fakeStreamProcessor.Object, fakeStreamStorage.Object); streamPersister.PersistLatest(); CollectionAssert.AreEquivalent(items, savedItems); fakeStreamAggregator.Verify(a => a.GetLatest(oldItem.Published), Times.Once()); fakeStreamProcessor.Verify(p => p.Process(It.IsAny<Item>()), Times.Exactly(items.Count)); fakeStreamStorage.Verify(s => s.Top(), Times.Once()); fakeStreamStorage.Verify(s => s.Save(It.IsAny<IEnumerable<Item>>()), Times.Once()); }
public void Persister_Can_Successfully_Persist_New_Items_In_Database() { try { var streamPersister = new StreamPersister(ConnectionString, DatabaseName); streamPersister.PersistLatest(); } finally { MongoServer.Create(ConnectionString).DropDatabase(DatabaseName); } }