public async Task Test_SiteManager_CreateArticle_TestLoggingExtensionMethod() { // Arange var loggerMock = new LoggerMock <SiteManager>() .SetupLogLevel(Microsoft.Extensions.Logging.LogLevel.Information); var authorAccessMock = new AuthorAccessMock(new List <Author> { new Author { Id = 666, DisplayName = "Max", Verfied = false } }); var articleAccessMock = new ArticleAccessMock(); ISiteManager sut = new SiteManager(articleAccessMock.Object, authorAccessMock.Object, loggerMock.Object); // Act var request = new Kaylumah.AdventuresWithMock.Manager.Site.Interface.CreateArticleRequest { Title = "Pretty Title", Content = "# AdventuresWithMock ..." }; await sut.CreateArticle(request); // Assert authorAccessMock.Verify(x => x.FilterAuthors(It.IsAny <FilterAuthorCriteria>()), Times.Once); articleAccessMock.Verify(x => x.CreateArticles(It.IsAny <CreateArticlesRequest>()), Times.Never); loggerMock.VerifyLogging("Author with Id 666 is not verfied!", Microsoft.Extensions.Logging.LogLevel.Information); loggerMock.VerifyEventIdWasCalled(new Microsoft.Extensions.Logging.EventId(100, "AuthorNotVerfied")); }
public async Task Test_SiteManager_CreateArticle_TestLogging() { // Arange var loggerMock = new LoggerMock <SiteManager>(); var authorAccessMock = new AuthorAccessMock(new List <Author> { }); var articleAccessMock = new ArticleAccessMock(); ISiteManager sut = new SiteManager(articleAccessMock.Object, authorAccessMock.Object, loggerMock.Object); // Act var request = new Kaylumah.AdventuresWithMock.Manager.Site.Interface.CreateArticleRequest { Title = "Pretty Title", Content = "# AdventuresWithMock ..." }; await sut.CreateArticle(request); // Assert authorAccessMock.Verify(x => x.FilterAuthors(It.IsAny <FilterAuthorCriteria>()), Times.Once); articleAccessMock.Verify(x => x.CreateArticles(It.IsAny <CreateArticlesRequest>()), Times.Never); loggerMock.VerifyLogging("No author found for 666", Microsoft.Extensions.Logging.LogLevel.Warning); }
public async Task Test_SiteManager_CreateArticle_RepoMocksDemo1() { // Arange var loggerMock = new LoggerMock <SiteManager>(); var authorAccessMock = new AuthorAccessMock(new List <Author> { new Author { Id = 666, DisplayName = "Max", Verfied = false } }); var articleAccessMock = new ArticleAccessMock(); ISiteManager sut = new SiteManager(articleAccessMock.Object, authorAccessMock.Object, loggerMock.Object); // Act var request = new Kaylumah.AdventuresWithMock.Manager.Site.Interface.CreateArticleRequest { Title = "Pretty Title", Content = "# AdventuresWithMock ..." }; await sut.CreateArticle(request); // Assert authorAccessMock.Verify(x => x.FilterAuthors(It.IsAny <FilterAuthorCriteria>()), Times.Once); articleAccessMock.Verify(x => x.CreateArticles(It.IsAny <CreateArticlesRequest>()), Times.Never); }