/// <summary> /// Autofac will call this each time a class depends on ComicConfigRegistry /// </summary> /// <param name="componentRegistry"></param> /// <returns></returns> public static ComicConfigRegistry RegisterComics(IComponentContext componentRegistry) { var registry = new ComicConfigRegistry(); registry.Add( new ComicConfig(ComicType.Dilbert, componentRegistry.Resolve<DilbertDownloader>())); registry.Add( new ComicConfig(ComicType.Explosm, componentRegistry.Resolve<ExplosmDownloader>())); registry.Add( new ComicConfig(ComicType.Pearls, componentRegistry.Resolve<PearlsDownloader>())); return registry; }
public void UsesRegistryToGetNewComics() { var mocker = new AutoMoqer(); var lastExplosmComic = new Comic(); var newExplosmComic1 = new Comic(); var newExplosmComic2 = new Comic(); var explosm = new Mock<IComicDownloader>(); explosm.Setup(m => m.GetNewComicsSince(lastExplosmComic)) .Returns(new[] { newExplosmComic1, newExplosmComic2 }); mocker.GetMock<IComicsRepository>() .Setup(m => m.GetLastImportedComic(ComicType.Explosm)) .Returns(lastExplosmComic) .Verifiable(); var registry = new ComicConfigRegistry(); registry.Add(new ComicConfig(ComicType.Explosm, explosm.Object)); // ReSharper disable once RedundantTypeArgumentsOfMethod mocker.SetInstance<ComicConfigRegistry>(registry); mocker.Create<ImportProcess>() .Run(); mocker.GetMock<IComicsRepository>().VerifyAll(); mocker.GetMock<IComicsRepository>() .Verify(m => m.InsertComic(newExplosmComic1), Times.Once); mocker.GetMock<IComicsRepository>() .Verify(m => m.InsertComic(newExplosmComic2), Times.Once); }
public void ReportsComicsImported() { var mocker = new AutoMoqer(); var lastExplosmComic = new Comic(); var newExplosmComic1 = new Comic(); var newExplosmComic2 = new Comic(); var explosm = new Mock<IComicDownloader>(); explosm.Setup(m => m.GetNewComicsSince(lastExplosmComic)) .Returns(new[] { newExplosmComic1, newExplosmComic2 }); mocker.GetMock<IComicsRepository>() .Setup(m => m.GetLastImportedComic(ComicType.Explosm)) .Returns(lastExplosmComic) .Verifiable(); var registry = new ComicConfigRegistry(); registry.Add(new ComicConfig(ComicType.Explosm, explosm.Object)); // ReSharper disable once RedundantTypeArgumentsOfMethod mocker.SetInstance<ComicConfigRegistry>(registry); var process = mocker.Create<ImportProcess>(); process.Run(); Check.That(process.ImportedComics.Count).IsEqualTo(2); }