private void ProcessFeed(DataFeed dataFeed) { VkGroup group = this.groupRepository.GetGroupById(dataFeed.VkGroupId); IFeedProcessor processor = this.processorFactory.Create(dataFeed.Type); using (var transaction = this.transactionProvider.CreateTransaction().Begin()) { this.log.InfoFormat("Processing data feed with VkGroupId={0} ({1}) is started", dataFeed.VkGroupId, dataFeed.Type); try { processor.Process(dataFeed, group); transaction.Commit(); this.log.InfoFormat("Processing data feed with VkGroupId={0} ({1}) is finished", dataFeed.VkGroupId, dataFeed.Type); } catch (Exception exc) { transaction.Rollback(); this.log.ErrorFormat("Data feed with VkGroupId={0} ({1}) is failed to be processed. Reason: {2}", dataFeed.VkGroupId, dataFeed.Type, exc.ToString()); throw; } finally { dataFeed.MarkAsCompleted(); this.log.InfoFormat("Data feed with Id={0} ({1}) is deleted", dataFeed.VkGroupId, dataFeed.Type); } } }
public void GivenSuccessfullyProcessedFeedThenShouldPersistFeed() { // Arrange var feed = new Models.Feed(); A.CallTo(() => _feedProcessor.CanProcess(A<string>.Ignored)).Returns(true); A.CallTo(() => _feedProcessor.Process(A<string>.Ignored)).Returns(feed); // Act var actual = _subject.Ingest("SOURCE"); // Assert A.CallTo(() => _command.Execute(A<PersistFeedRequest>.That.Matches(r => r.Feed == feed))).MustHaveHappenedOnceExactly(); }