diff --git a/src/EPiServer.Search.Cms/Search/Internal/ContentSearchHandlerImplementation.cs b/src/EPiServer.Search.Cms/Search/Internal/ContentSearchHandlerImplementation.cs index 79be478..bf573de 100644 --- a/src/EPiServer.Search.Cms/Search/Internal/ContentSearchHandlerImplementation.cs +++ b/src/EPiServer.Search.Cms/Search/Internal/ContentSearchHandlerImplementation.cs @@ -143,11 +143,11 @@ public override void IndexPublishedContent() if (success) { - result.IndexingCount += 1; + result.IndexingCount += contentRequestToIndex.Count(); } else { - result.NumberOfContentErrors += 1; + result.NumberOfContentErrors += contentRequestToIndex.Count(); } } } diff --git a/src/EPiServer.Search.IndexingService/Controllers/IndexingController.cs b/src/EPiServer.Search.IndexingService/Controllers/IndexingController.cs index d5dc63c..e21094f 100644 --- a/src/EPiServer.Search.IndexingService/Controllers/IndexingController.cs +++ b/src/EPiServer.Search.IndexingService/Controllers/IndexingController.cs @@ -15,16 +15,19 @@ public class IndexingController : ControllerBase private readonly IIndexingServiceHandler _indexingServiceHandler; private readonly IIndexingServiceSettings _indexingServiceSettings; private readonly IResponseExceptionHelper _responseExceptionHelper; + private readonly ILogger _logger; public IndexingController(ISecurityHandler securityHandler, IIndexingServiceHandler indexingServiceHandler, IIndexingServiceSettings indexingServiceSettings, - IResponseExceptionHelper responseExceptionHelper) + IResponseExceptionHelper responseExceptionHelper, + ILogger logger) { _securityHandler = securityHandler; _indexingServiceHandler = indexingServiceHandler; _indexingServiceSettings = indexingServiceSettings; _responseExceptionHelper = responseExceptionHelper; + _logger = logger; } //POST: reset?namedIndex={namedIndex}&accessKey={accessKey} @@ -32,7 +35,7 @@ public IndexingController(ISecurityHandler securityHandler, [Route("reset")] public IActionResult ResetIndex(string namedIndex, string accessKey) { - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Reset of index: {0} requested", namedIndex)); + _logger.LogDebug(string.Format("Reset of index: {0} requested", namedIndex)); if (!_securityHandler.IsAuthenticated(accessKey, AccessLevel.Modify)) { diff --git a/src/EPiServer.Search.IndexingService/Helpers/DocumentHelper.cs b/src/EPiServer.Search.IndexingService/Helpers/DocumentHelper.cs index e6f95a9..10007f7 100644 --- a/src/EPiServer.Search.IndexingService/Helpers/DocumentHelper.cs +++ b/src/EPiServer.Search.IndexingService/Helpers/DocumentHelper.cs @@ -16,9 +16,11 @@ namespace EPiServer.Search.IndexingService.Helpers public class DocumentHelper : IDocumentHelper { private readonly IResponseExceptionHelper _responseExceptionHelper; - public DocumentHelper(IResponseExceptionHelper responseExceptionHelper) + private readonly ILogger _logger; + public DocumentHelper(IResponseExceptionHelper responseExceptionHelper, ILogger logger) { _responseExceptionHelper = responseExceptionHelper; + _logger = logger; } public Collection SingleIndexSearch(string q, NamedIndex namedIndex, int maxHits, out int totalHits) { @@ -29,7 +31,7 @@ public Collection SingleIndexSearch(string q, NamedIndex namedInd try { - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Creating Lucene QueryParser for index '{0}' with expression '{1}' with analyzer '{2}'", namedIndex.Name, q, IndexingServiceSettings.Analyzer.ToString())); + _logger.LogDebug(string.Format("Creating Lucene QueryParser for index '{0}' with expression '{1}' with analyzer '{2}'", namedIndex.Name, q, IndexingServiceSettings.Analyzer.ToString())); QueryParser parser = new PerFieldQueryParserWrapper(IndexingServiceSettings.LuceneVersion, IndexingServiceSettings.DefaultFieldName, IndexingServiceSettings.Analyzer, IndexingServiceSettings.LowercaseFields); var baseQuery = parser.Parse(q); using (IndexReader reader = DirectoryReader.Open(namedIndex.Directory)) @@ -64,7 +66,7 @@ public void OptimizeIndex(NamedIndex namedIndex) try { - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Start optimizing index")); + _logger.LogDebug(string.Format("Start optimizing index")); var iwc = new IndexWriterConfig(IndexingServiceSettings.LuceneVersion, IndexingServiceSettings.Analyzer) { @@ -75,12 +77,12 @@ public void OptimizeIndex(NamedIndex namedIndex) iWriter.ForceMerge(1); } - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("End optimizing index")); + _logger.LogDebug(string.Format("End optimizing index")); } catch (Exception e) { - IndexingServiceSettings.IndexingServiceServiceLog.LogError(string.Format("Failed to optimize index: '{0}'. Message: {1}{2}{3}", namedIndex.Name, e.Message, Environment.NewLine, e.StackTrace)); + _logger.LogError(string.Format("Failed to optimize index: '{0}'. Message: {1}{2}{3}", namedIndex.Name, e.Message, Environment.NewLine, e.StackTrace)); } finally { @@ -90,7 +92,7 @@ public void OptimizeIndex(NamedIndex namedIndex) //Fire event IndexingController.OnIndexedOptimized(this, new OptimizedEventArgs(namedIndex.Name)); - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Optimized index: '{0}'", namedIndex.Name)); + _logger.LogDebug(string.Format("Optimized index: '{0}'", namedIndex.Name)); } public Collection MultiIndexSearch(string q, Collection namedIndexes, int maxHits, out int totalHits) { @@ -109,7 +111,7 @@ public Collection MultiIndexSearch(string q, Collection _logger; public LuceneHelper(IFeedHelper feedHelper, IResponseExceptionHelper responseExceptionHelper, ICommonFunc commonFunc, - IDocumentHelper documentHelper) + IDocumentHelper documentHelper, + ILogger logger) { _feedHelper = feedHelper; _responseExceptionHelper = responseExceptionHelper; _commonFunc = commonFunc; _documentHelper = documentHelper; + _logger = logger; } public Document GetDocumentFromSyndicationItem(FeedItemModel feedItem, NamedIndex namedIndex) @@ -201,7 +203,7 @@ public bool UpdateReference(string referenceId, string itemId, NamedIndex mainNa if (mainDoc == null) { - IndexingServiceSettings.IndexingServiceServiceLog.LogError(string.Format("Could not find main document with id: '{0}' for referencing item id '{1}'. Continuing anyway, index will heal when main document is added/updated.", referenceId, itemId)); + _logger.LogError(string.Format("Could not find main document with id: '{0}' for referencing item id '{1}'. Continuing anyway, index will heal when main document is added/updated.", referenceId, itemId)); return false; } @@ -217,12 +219,12 @@ public bool UpdateReference(string referenceId, string itemId, NamedIndex mainNa public bool WriteToIndex(string itemId, Document doc, NamedIndex namedIndex) { var isOk = true; - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Start writing document with id '{0}' to index '{1}' with analyzer '{2}'", itemId, namedIndex.Name, IndexingServiceSettings.Analyzer.ToString())); + _logger.LogDebug(string.Format("Start writing document with id '{0}' to index '{1}' with analyzer '{2}'", itemId, namedIndex.Name, IndexingServiceSettings.Analyzer.ToString())); // Write to Directory if (_documentHelper.DocumentExists(itemId, namedIndex)) { - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Failed to write to index: '{0}'. Document with id: '{1}' already exists", namedIndex.Name, itemId)); + _logger.LogDebug(string.Format("Failed to write to index: '{0}'. Document with id: '{1}' already exists", namedIndex.Name, itemId)); isOk = false; } @@ -243,7 +245,7 @@ public bool WriteToIndex(string itemId, Document doc, NamedIndex namedIndex) } catch (Exception e) { - IndexingServiceSettings.IndexingServiceServiceLog.LogError(string.Format("Failed to write to index: '{0}'. Message: {1}{2}{3}", namedIndex.Name, e.Message, Environment.NewLine, e.StackTrace)); + _logger.LogError(string.Format("Failed to write to index: '{0}'. Message: {1}{2}{3}", namedIndex.Name, e.Message, Environment.NewLine, e.StackTrace)); isOk = false; } finally @@ -251,7 +253,7 @@ public bool WriteToIndex(string itemId, Document doc, NamedIndex namedIndex) rwl.ExitWriteLock(); } - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("End writing to index")); + _logger.LogDebug(string.Format("End writing to index")); return isOk; } @@ -264,7 +266,7 @@ public bool Add(FeedItemModel item, NamedIndex namedIndex) var id = item.Id; - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Start adding Lucene document with id field: '{0}' to index: '{1}'", id, namedIndex.Name)); + _logger.LogDebug(string.Format("Start adding Lucene document with id field: '{0}' to index: '{1}'", id, namedIndex.Name)); if (string.IsNullOrEmpty(id)) { @@ -275,7 +277,7 @@ public bool Add(FeedItemModel item, NamedIndex namedIndex) //Check if the document already exists. if (_documentHelper.DocumentExists(id, namedIndex)) { - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Document already exists. Skipping.")); + _logger.LogDebug(string.Format("Document already exists. Skipping.")); return false; } @@ -286,7 +288,7 @@ public bool Add(FeedItemModel item, NamedIndex namedIndex) var result = WriteToIndex(id, doc, namedIndex); - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("End adding document with id field: '{0}' to index: '{1}'", id, namedIndex.Name)); + _logger.LogDebug(string.Format("End adding document with id field: '{0}' to index: '{1}'", id, namedIndex.Name)); //Fire added event IndexingController.OnDocumentAdded(this, new AddUpdateEventArgs(doc, namedIndex.Name)); @@ -317,7 +319,7 @@ public void Remove(FeedItemModel feedItem, NamedIndex namedIndex) /// The named index from where to remove the document public void Remove(string itemId, NamedIndex namedIndex, bool removeRef) { - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Start deleting Lucene document with id field: '{0}' from index '{1}'", itemId, namedIndex.Name)); + _logger.LogDebug(string.Format("Start deleting Lucene document with id field: '{0}' from index '{1}'", itemId, namedIndex.Name)); IndexingController.OnDocumentRemoving(this, new RemoveEventArgs(itemId, namedIndex.Name)); @@ -327,7 +329,7 @@ public void Remove(string itemId, NamedIndex namedIndex, bool removeRef) { IndexingController.OnDocumentRemoved(this, new RemoveEventArgs(itemId, namedIndex.Name)); - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("End deleting document with id field: '{0}'", itemId)); + _logger.LogDebug(string.Format("End deleting document with id field: '{0}'", itemId)); } } @@ -338,7 +340,7 @@ public bool RemoveByVirtualPath(string virtualPath) return false; } - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Start removing all items under virtual path '{0}'.", virtualPath)); + _logger.LogDebug(string.Format("Start removing all items under virtual path '{0}'.", virtualPath)); //Get all documents under old virtual path for all named indexes var allNamedIndexes = new Collection(); @@ -361,7 +363,7 @@ public bool RemoveByVirtualPath(string virtualPath) Remove(id, namedIndex, true); } - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("End removing by virtual path.")); + _logger.LogDebug(string.Format("End removing by virtual path.")); return true; } @@ -407,7 +409,7 @@ public bool DeleteFromIndex(NamedIndex namedIndex, string itemId, bool deleteRef var isOk = true; Term term = null; - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Start deleting Lucene document with id field '{0}' from index '{1}'", itemId, namedIndex.Name)); + _logger.LogDebug(string.Format("Start deleting Lucene document with id field '{0}' from index '{1}'", itemId, namedIndex.Name)); var i = 0; var pendingDeletions = 0; @@ -433,7 +435,7 @@ public bool DeleteFromIndex(NamedIndex namedIndex, string itemId, bool deleteRef } catch (Exception e) { - IndexingServiceSettings.IndexingServiceServiceLog.LogError(string.Format("Failed to delete Document with id: {0}. Message: {1}{2}{3}", itemId.ToString(), e.Message, Environment.NewLine, e.StackTrace)); + _logger.LogError(string.Format("Failed to delete Document with id: {0}. Message: {1}{2}{3}", itemId.ToString(), e.Message, Environment.NewLine, e.StackTrace)); isOk = false; } finally @@ -443,7 +445,7 @@ public bool DeleteFromIndex(NamedIndex namedIndex, string itemId, bool deleteRef if (i == 0) // Document didn't exist { - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Failed to delete Document with id: {0}. Document does not exist.", itemId.ToString())); + _logger.LogDebug(string.Format("Failed to delete Document with id: {0}. Document does not exist.", itemId.ToString())); isOk = false; } else @@ -451,7 +453,7 @@ public bool DeleteFromIndex(NamedIndex namedIndex, string itemId, bool deleteRef // Delete any referencing documents if (deleteRef && namedIndex.ReferenceDirectory != null) { - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Start deleting reference documents for id '{0}'", itemId.ToString())); + _logger.LogDebug(string.Format("Start deleting reference documents for id '{0}'", itemId.ToString())); var rwlRef = IndexingServiceSettings.ReaderWriterLocks[namedIndex.ReferenceName]; rwlRef.EnterWriteLock(); @@ -470,7 +472,7 @@ public bool DeleteFromIndex(NamedIndex namedIndex, string itemId, bool deleteRef } catch (Exception e) { - IndexingServiceSettings.IndexingServiceServiceLog.LogError(string.Format("Failed to delete referencing Documents for reference id: {0}. Message: {1}{2}{3}", itemId.ToString(), e.Message, Environment.NewLine, e.StackTrace)); + _logger.LogError(string.Format("Failed to delete referencing Documents for reference id: {0}. Message: {1}{2}{3}", itemId.ToString(), e.Message, Environment.NewLine, e.StackTrace)); isOk = false; } finally @@ -478,10 +480,10 @@ public bool DeleteFromIndex(NamedIndex namedIndex, string itemId, bool deleteRef rwlRef.ExitWriteLock(); } - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("End deleting reference documents for id '{0}'", itemId.ToString())); + _logger.LogDebug(string.Format("End deleting reference documents for id '{0}'", itemId.ToString())); } - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("End deleting Lucene document with id field: '{0}'", itemId)); + _logger.LogDebug(string.Format("End deleting Lucene document with id field: '{0}'", itemId)); // Optimize index if ((namedIndex.PendingDeletesOptimizeThreshold > 0) && @@ -525,7 +527,7 @@ public bool UpdateVirtualPaths(string oldVirtualPath, string newVirtualPath) return false; } - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Start updating virtual paths from old path: '{0}' to new path '{1}'", oldVirtualPath, newVirtualPath)); + _logger.LogDebug(string.Format("Start updating virtual paths from old path: '{0}' to new path '{1}'", oldVirtualPath, newVirtualPath)); //Get all documents under old virtual path for all named indexes var allNamedIndexes = new Collection(); @@ -558,10 +560,10 @@ public bool UpdateVirtualPaths(string oldVirtualPath, string newVirtualPath) Remove(id, namedIndex, false); WriteToIndex(id, doc, namedIndex); - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Updated virtual path for document with id: '{0}'.", id)); + _logger.LogDebug(string.Format("Updated virtual path for document with id: '{0}'.", id)); } - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("End updating virtual paths")); + _logger.LogDebug(string.Format("End updating virtual paths")); return true; } @@ -596,7 +598,7 @@ public bool HandleDataUri(FeedItemModel item, NamedIndex namedIndex) // Get the uri string var uriString = _feedHelper.GetAttributeValue(item, IndexingServiceSettings.SyndicationItemAttributeNameDataUri); - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Start processing data uri callback for uri '{0}'", uriString)); + _logger.LogDebug(string.Format("Start processing data uri callback for uri '{0}'", uriString)); // Try to parse the uri @@ -625,7 +627,7 @@ public bool HandleDataUri(FeedItemModel item, NamedIndex namedIndex) if (string.IsNullOrEmpty(content)) { - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Content for uri '{0}' is empty", uri.ToString())); + _logger.LogDebug(string.Format("Content for uri '{0}' is empty", uri.ToString())); content = string.Empty; } @@ -670,10 +672,10 @@ public bool HandleDataUri(FeedItemModel item, NamedIndex namedIndex) item.Id, new NamedIndex(namedIndex.Name)); //Always main index - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Updated reference with reference id '{0}' ", referenceId)); + _logger.LogDebug(string.Format("Updated reference with reference id '{0}' ", referenceId)); } - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("End data uri callback")); + _logger.LogDebug(string.Format("End data uri callback")); return true; } } diff --git a/src/EPiServer.Search.IndexingService/Helpers/ResponseExceptionHelper.cs b/src/EPiServer.Search.IndexingService/Helpers/ResponseExceptionHelper.cs index 861fe7c..8e1eeff 100644 --- a/src/EPiServer.Search.IndexingService/Helpers/ResponseExceptionHelper.cs +++ b/src/EPiServer.Search.IndexingService/Helpers/ResponseExceptionHelper.cs @@ -1,13 +1,18 @@ -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; namespace EPiServer.Search.IndexingService.Helpers { public class ResponseExceptionHelper : IResponseExceptionHelper { + private readonly ILogger _logger; + public ResponseExceptionHelper(ILogger logger) + { + _logger = logger; + } public void HandleServiceError(string errorMessage) { //Log, fire event and respond with status code 500 - IndexingServiceSettings.IndexingServiceServiceLog.LogError(errorMessage); + _logger.LogError(errorMessage); throw new HttpResponseException() { Value = new { error = errorMessage }, @@ -18,7 +23,7 @@ public void HandleServiceError(string errorMessage) public void HandleServiceUnauthorized(string errorMessage) { //Log, fire event and respond with status code 500 - IndexingServiceSettings.IndexingServiceServiceLog.LogError(errorMessage); + _logger.LogError(errorMessage); throw new HttpResponseException() { Value = new { error = errorMessage }, diff --git a/src/EPiServer.Search.IndexingService/IndexingServiceHandler.cs b/src/EPiServer.Search.IndexingService/IndexingServiceHandler.cs index c52db44..0880738 100644 --- a/src/EPiServer.Search.IndexingService/IndexingServiceHandler.cs +++ b/src/EPiServer.Search.IndexingService/IndexingServiceHandler.cs @@ -20,6 +20,7 @@ public class IndexingServiceHandler : IIndexingServiceHandler private readonly ICommonFunc _commonFunc; private readonly IResponseExceptionHelper _responseExceptionHelper; private readonly IDocumentHelper _documentHelper; + private readonly ILogger _logger; #endregion #region Constructors @@ -27,11 +28,13 @@ public IndexingServiceHandler(IFeedHelper feedHelper, ILuceneHelper luceneHelper, ICommonFunc commonFunc, IResponseExceptionHelper responseExceptionHelper, - IDocumentHelper documentHelper) + IDocumentHelper documentHelper, + ILogger logger, ILoggerFactory loggerFactory) { if (_taskQueue == null) { - _taskQueue = new TaskQueue("indexing service data uri callback", 1000, TimeSpan.FromSeconds(0)); + var loggerTaskQueue = loggerFactory.CreateLogger(); + _taskQueue = new TaskQueue("indexing service data uri callback", 1000, TimeSpan.FromSeconds(0), loggerTaskQueue); } _feedHelper = feedHelper; @@ -39,6 +42,7 @@ public IndexingServiceHandler(IFeedHelper feedHelper, _commonFunc = commonFunc; _responseExceptionHelper = responseExceptionHelper; _documentHelper = documentHelper; + _logger = logger; } #endregion @@ -50,7 +54,7 @@ public IndexingServiceHandler(IFeedHelper feedHelper, /// The feed to process public void UpdateIndex(FeedModel feed) { - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Start processing feed '{0}'", feed.Id)); + _logger.LogDebug(string.Format("Start processing feed '{0}'", feed.Id)); foreach (var item in feed.Items) { @@ -78,7 +82,7 @@ public void UpdateIndex(FeedModel feed) } } - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Start processing feed item '{0}' for '{1}'", item.Id, indexAction)); + _logger.LogDebug(string.Format("Start processing feed item '{0}' for '{1}'", item.Id, indexAction)); // If there is a callback uri defined, we run the callback in async mode if (!string.IsNullOrEmpty(dataUri)) @@ -86,7 +90,7 @@ public void UpdateIndex(FeedModel feed) var callback = new Action(new DataUriQueueItem(item, namedIndex, _luceneHelper).Do); _taskQueue.Enqueue(callback); - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Callback for data uri '{0}' enqueued", dataUri)); + _logger.LogDebug(string.Format("Callback for data uri '{0}' enqueued", dataUri)); } else { @@ -113,15 +117,15 @@ public void UpdateIndex(FeedModel feed) item.Id, new NamedIndex(namedIndexName)); // Always main index - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Updated reference with reference id '{0}' ", referenceId)); + _logger.LogDebug(string.Format("Updated reference with reference id '{0}' ", referenceId)); } } } - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("End processing feed item '{0}'", item.Id)); + _logger.LogDebug(string.Format("End processing feed item '{0}'", item.Id)); } - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("End processing feed '{0}'", feed.Id)); + _logger.LogDebug(string.Format("End processing feed '{0}'", feed.Id)); } /// @@ -134,7 +138,7 @@ public void UpdateIndex(FeedModel feed) /// s public FeedModel GetSearchResults(string q, string[] namedIndexNames, int offset, int limit) { - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Start search with expression: '{0}'", q)); + _logger.LogDebug(string.Format("Start search with expression: '{0}'", q)); var feed = new FeedModel(); var feedItems = new Collection(); @@ -184,7 +188,7 @@ public FeedModel GetSearchResults(string q, string[] namedIndexNames, int offset version.Build.ToString(CultureInfo.InvariantCulture), version.Revision.ToString(CultureInfo.InvariantCulture)); feed.AttributeExtensions.Add(IndexingServiceSettings.SyndicationFeedAttributeNameVersion, versionString); - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("End search with expression '{0}'. Returned {1} hits of total {2} with offset {3} and limit {4}", + _logger.LogDebug(string.Format("End search with expression '{0}'. Returned {1} hits of total {2} with offset {3} and limit {4}", q, returnedHits.ToString(CultureInfo.InvariantCulture), totalHits.ToString(CultureInfo.InvariantCulture), offset.ToString(CultureInfo.InvariantCulture), limit.ToString(CultureInfo.InvariantCulture))); @@ -233,7 +237,7 @@ public void ResetNamedIndex(string namedIndexName) public FeedModel GetSearchResults(string q, string namedIndexes, int offset, int limit) { - IndexingServiceSettings.IndexingServiceServiceLog.LogDebug(string.Format("Request for search with query parser with expression: {0} in named indexes: {1}", q, namedIndexes)); + _logger.LogDebug(string.Format("Request for search with query parser with expression: {0} in named indexes: {1}", q, namedIndexes)); //Parse named indexes string from request string[] namedIndexesArr = null; diff --git a/src/EPiServer.Search.IndexingService/TaskQueue.cs b/src/EPiServer.Search.IndexingService/TaskQueue.cs index 13dcbaf..ad2dfbe 100644 --- a/src/EPiServer.Search.IndexingService/TaskQueue.cs +++ b/src/EPiServer.Search.IndexingService/TaskQueue.cs @@ -14,6 +14,7 @@ public class TaskQueue private readonly double _timerInterval; private readonly TimeSpan _minQueueItemAge; private readonly string _queueName; + private readonly ILogger _logger; /// /// Constructs a TaskQueue @@ -21,7 +22,7 @@ public class TaskQueue /// Queue identifier used for logging purposes /// Interval in milliseconds telling when the queue should be processed /// The minimum age of a queue item in order for it to be dequeued - public TaskQueue(string queueName, double timerInterval, TimeSpan minQueueItemAge) + public TaskQueue(string queueName, double timerInterval, TimeSpan minQueueItemAge, ILogger logger) { _queueName = queueName; _timerInterval = timerInterval; @@ -31,6 +32,7 @@ public TaskQueue(string queueName, double timerInterval, TimeSpan minQueueItemAg AutoReset = false }; _queueFlushTimer.Elapsed += Timer_Elapsed; + _logger = logger; } /// @@ -58,7 +60,7 @@ private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) } catch (Exception ex) { - IndexingServiceSettings.IndexingServiceServiceLog.LogError( + _logger.LogError( string.Format("An exception was thrown when task was invoked by TaskQueue: '{0}'. The message was: {1}. Stacktrace was: {2}", _queueName, ex.Message, ex.StackTrace)); } } @@ -66,7 +68,7 @@ private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) } catch (Exception ex) { - IndexingServiceSettings.IndexingServiceServiceLog.LogError( + _logger.LogError( string.Format("An exception was thrown while processing TaskQueue: '{0}'. The message was: {1}. Stacktrace was: {2}", _queueName, ex.Message, ex.StackTrace)); } finally diff --git a/test/EPiServer.Search.IndexingService.Test/Controllers/IndexingControllerTestBase.cs b/test/EPiServer.Search.IndexingService.Test/Controllers/IndexingControllerTestBase.cs index 30316f3..21e8c58 100644 --- a/test/EPiServer.Search.IndexingService.Test/Controllers/IndexingControllerTestBase.cs +++ b/test/EPiServer.Search.IndexingService.Test/Controllers/IndexingControllerTestBase.cs @@ -1,4 +1,4 @@ -using EPiServer.Search.IndexingService.Helpers; +using EPiServer.Search.IndexingService.Helpers; using EPiServer.Search.IndexingService.Security; using Microsoft.Extensions.Logging; using Moq; @@ -11,6 +11,7 @@ public class IndexingControllerTestBase protected readonly Mock _indexingServiceSettingsMock; protected readonly Mock _indexingServiceHandlerMock; protected readonly Mock _securityHandlerMock; + protected readonly Mock> _loggerMock; public IndexingControllerTestBase() { _responseExceptionHelperMock = new Mock(); @@ -18,17 +19,17 @@ public IndexingControllerTestBase() _indexingServiceHandlerMock = new Mock(); _securityHandlerMock = new Mock(); - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; + _loggerMock = new Mock>(); } - public EPiServer.Search.IndexingService.Controllers.IndexingController SetupMock() + public IndexingService.Controllers.IndexingController SetupMock() { - return new EPiServer.Search.IndexingService.Controllers.IndexingController( + return new IndexingService.Controllers.IndexingController( _securityHandlerMock.Object, _indexingServiceHandlerMock.Object, _indexingServiceSettingsMock.Object, - _responseExceptionHelperMock.Object); + _responseExceptionHelperMock.Object, + _loggerMock.Object); } } } diff --git a/test/EPiServer.Search.IndexingService.Test/Helpers/DocumentHelper/DocumentHelperTestBase.cs b/test/EPiServer.Search.IndexingService.Test/Helpers/DocumentHelper/DocumentHelperTestBase.cs index 50f518b..daeac82 100644 --- a/test/EPiServer.Search.IndexingService.Test/Helpers/DocumentHelper/DocumentHelperTestBase.cs +++ b/test/EPiServer.Search.IndexingService.Test/Helpers/DocumentHelper/DocumentHelperTestBase.cs @@ -10,21 +10,19 @@ namespace EPiServer.Search.IndexingService.Test.Helpers.DocumentHelper public class DocumentHelperTestBase { protected readonly Mock _responseExceptionHelperMock; + protected readonly Mock> _loggerMock; public DocumentHelperTestBase() { IndexingServiceSettings.ReaderWriterLocks.TryAdd("testindex1", new ReaderWriterLockSlim()); IndexingServiceSettings.ReaderWriterLocks.TryAdd("testindex2", new ReaderWriterLockSlim()); _responseExceptionHelperMock = new Mock(); - - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; - + _loggerMock = new Mock>(); } - public EPiServer.Search.IndexingService.Helpers.DocumentHelper SetupMock() + public IndexingService.Helpers.DocumentHelper SetupMock() { return new EPiServer.Search.IndexingService.Helpers.DocumentHelper( - _responseExceptionHelperMock.Object); + _responseExceptionHelperMock.Object, _loggerMock.Object); } public void AddDocumentForTest(NamedIndex namedIndex, string itemId) @@ -33,12 +31,14 @@ public void AddDocumentForTest(NamedIndex namedIndex, string itemId) var _commonFuncMock = new Mock(); var _responseExceptionHelperMock = new Mock(); var _documentHelperMock = new Mock(); + var _loggerMock1 = new Mock>(); - var _luceneHelper = new EPiServer.Search.IndexingService.Helpers.LuceneHelper( + var _luceneHelper = new IndexingService.Helpers.LuceneHelper( _feedHelperMock.Object, _responseExceptionHelperMock.Object, _commonFuncMock.Object, - _documentHelperMock.Object); + _documentHelperMock.Object, + _loggerMock1.Object); var feed = new FeedItemModel() { @@ -77,12 +77,14 @@ public void DeleteDocumentForTest(NamedIndex namedIndex, string itemId) var _commonFuncMock = new Mock(); var _responseExceptionHelperMock = new Mock(); var _documentHelperMock = new Mock(); + var _loggerMock1 = new Mock>(); - var _luceneHelper = new EPiServer.Search.IndexingService.Helpers.LuceneHelper( + var _luceneHelper = new IndexingService.Helpers.LuceneHelper( _feedHelperMock.Object, _responseExceptionHelperMock.Object, _commonFuncMock.Object, - _documentHelperMock.Object); + _documentHelperMock.Object, + _loggerMock1.Object); var result = _luceneHelper.DeleteFromIndex(namedIndex, itemId, false); } diff --git a/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/AddTest.cs b/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/AddTest.cs index 196d052..ee9da6f 100644 --- a/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/AddTest.cs +++ b/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/AddTest.cs @@ -1,12 +1,11 @@ using System; using System.Collections.ObjectModel; -using Microsoft.Extensions.Logging; using Moq; using Xunit; namespace EPiServer.Search.IndexingService.Test.Helpers.LuceneHelper { - [Trait(nameof(EPiServer.Search.IndexingService.Helpers.LuceneHelper), nameof(EPiServer.Search.IndexingService.Helpers.LuceneHelper.Add))] + [Trait(nameof(IndexingService.Helpers.LuceneHelper), nameof(IndexingService.Helpers.LuceneHelper.Add))] public class AddTest : LuceneHelperTestBase { [Fact] @@ -21,8 +20,6 @@ public void Add_WhenItemIsNull_ShouldReturnFalse() [Fact] public void Add_WhenItemIdIsEmpty_ShouldReturnFalse() { - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; var item = new FeedItemModel { Id = "" @@ -38,8 +35,6 @@ public void Add_WhenItemIdIsEmpty_ShouldReturnFalse() [Fact] public void Add_WhenDocumentExists_ShouldReturnFalse() { - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; var item = new FeedItemModel { Id = "1" @@ -56,8 +51,6 @@ public void Add_WhenDocumentExists_ShouldReturnFalse() [Fact] public void Add_WhenEverythingIsValid_ShouldReturnTrue() { - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; var feed = new FeedItemModel() { Id = Guid.NewGuid().ToString(), diff --git a/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/DeleteFromIndexTest.cs b/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/DeleteFromIndexTest.cs index 0791831..c3c71ed 100644 --- a/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/DeleteFromIndexTest.cs +++ b/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/DeleteFromIndexTest.cs @@ -1,21 +1,17 @@ using System; using Lucene.Net.Documents; using Lucene.Net.Index; -using Microsoft.Extensions.Logging; using Moq; using Xunit; namespace EPiServer.Search.IndexingService.Test.Helpers.LuceneHelper { - [Trait(nameof(EPiServer.Search.IndexingService.Helpers.LuceneHelper), nameof(EPiServer.Search.IndexingService.Helpers.LuceneHelper.DeleteFromIndex))] + [Trait(nameof(IndexingService.Helpers.LuceneHelper), nameof(IndexingService.Helpers.LuceneHelper.DeleteFromIndex))] public class DeleteFromIndexTest : LuceneHelperTestBase { [Fact] public void DeleteFromIndex_WhenHaveFileToDelete_ShouldReturnTrue() { - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; - var folderId = Guid.NewGuid().ToString(); var dir1 = Lucene.Net.Store.FSDirectory.Open(new System.IO.DirectoryInfo(string.Format(@"c:\fake\App_Data\{0}\Main", folderId))); @@ -44,9 +40,6 @@ public void DeleteFromIndex_WhenHaveFileToDelete_ShouldReturnTrue() [Fact] public void DeleteFromIndex_WhenHaveNoFile_ShouldReturnFalse() { - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; - var folderId = Guid.NewGuid().ToString(); var dir1 = Lucene.Net.Store.FSDirectory.Open(new System.IO.DirectoryInfo(string.Format(@"c:\fake\App_Data\{0}\Main", folderId))); diff --git a/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/HandleDataUriTest.cs b/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/HandleDataUriTest.cs index ffcd93e..2778456 100644 --- a/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/HandleDataUriTest.cs +++ b/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/HandleDataUriTest.cs @@ -1,21 +1,17 @@ using System; using System.Collections.ObjectModel; using System.IO; -using Microsoft.Extensions.Logging; using Moq; using Xunit; namespace EPiServer.Search.IndexingService.Test.Helpers.LuceneHelper { - [Trait(nameof(EPiServer.Search.IndexingService.Helpers.LuceneHelper), nameof(EPiServer.Search.IndexingService.Helpers.LuceneHelper.HandleDataUri))] + [Trait(nameof(IndexingService.Helpers.LuceneHelper), nameof(IndexingService.Helpers.LuceneHelper.HandleDataUri))] public class HandleDataUriTest : LuceneHelperTestBase { [Fact] public void HandleDataUri_WhenUriStringIsNotUri_ShouldReturnFalse() { - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; - var feed = new FeedItemModel(); _feedHelperMock.Setup(x => x.GetAttributeValue(It.IsAny(), It.Is(s => s == IndexingServiceSettings.SyndicationItemAttributeNameDataUri))).Returns((string)null); @@ -28,9 +24,6 @@ public void HandleDataUri_WhenUriStringIsNotUri_ShouldReturnFalse() [Fact] public void HandleDataUri_WhenFileNotExist_ShouldReturnFalse() { - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; - var feed = new FeedItemModel(); _feedHelperMock.Setup(x => x.GetAttributeValue(It.IsAny(), It.Is(s => s == IndexingServiceSettings.SyndicationItemAttributeNameDataUri))).Returns(@"c:\fake\App_Data\Index\file.txt"); @@ -45,9 +38,6 @@ public void HandleDataUri_WhenUriIsFileAndRunAdd_ShouldReturnTrue() { CreateFileForTest(); - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; - var feed = new FeedItemModel() { Id = "Id", @@ -98,9 +88,6 @@ public void HandleDataUri_WhenUriIsFileAndRunUpdate_ShouldReturnTrue() { CreateFileForTest(); - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; - var feed = new FeedItemModel() { Id = "Id", diff --git a/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/LuceneHelperTestBase.cs b/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/LuceneHelperTestBase.cs index 58b9b97..f6bd1a1 100644 --- a/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/LuceneHelperTestBase.cs +++ b/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/LuceneHelperTestBase.cs @@ -1,6 +1,7 @@ using System; using System.Threading; using EPiServer.Search.IndexingService.Helpers; +using Microsoft.Extensions.Logging; using Moq; namespace EPiServer.Search.IndexingService.Test.Helpers.LuceneHelper @@ -11,6 +12,7 @@ public class LuceneHelperTestBase protected readonly Mock _commonFuncMock; protected readonly Mock _responseExceptionHelperMock; protected readonly Mock _documentHelperMock; + protected readonly Mock> _loggerMock; public LuceneHelperTestBase() { IndexingServiceSettings.ReaderWriterLocks.TryAdd("testindex1", new ReaderWriterLockSlim()); @@ -21,6 +23,7 @@ public LuceneHelperTestBase() _commonFuncMock = new Mock(); _responseExceptionHelperMock = new Mock(); _documentHelperMock = new Mock(); + _loggerMock = new Mock>(); } public EPiServer.Search.IndexingService.Helpers.LuceneHelper SetupMock() @@ -29,7 +32,8 @@ public EPiServer.Search.IndexingService.Helpers.LuceneHelper SetupMock() _feedHelperMock.Object, _responseExceptionHelperMock.Object, _commonFuncMock.Object, - _documentHelperMock.Object); + _documentHelperMock.Object, + _loggerMock.Object); } } } diff --git a/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/RemoveByVirtualPathTest.cs b/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/RemoveByVirtualPathTest.cs index 3d2cca7..6175aa3 100644 --- a/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/RemoveByVirtualPathTest.cs +++ b/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/RemoveByVirtualPathTest.cs @@ -1,13 +1,12 @@ using System; using System.Collections.ObjectModel; using Lucene.Net.Documents; -using Microsoft.Extensions.Logging; using Moq; using Xunit; namespace EPiServer.Search.IndexingService.Test.Helpers.LuceneHelper { - [Trait(nameof(EPiServer.Search.IndexingService.Helpers.LuceneHelper), nameof(EPiServer.Search.IndexingService.Helpers.LuceneHelper.RemoveByVirtualPath))] + [Trait(nameof(IndexingService.Helpers.LuceneHelper), nameof(IndexingService.Helpers.LuceneHelper.RemoveByVirtualPath))] public class RemoveByVirtualPathTest : LuceneHelperTestBase { [Fact] @@ -22,8 +21,6 @@ public void RemoveByVirtualPath_WhenVirtualPathIsEmpty_ShouldReturnFalse() [Fact] public void RemoveByVirtualPath_WhenVirtualPathIsNotEmpty_ShouldReturnTrue() { - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; var folderId = Guid.NewGuid(); var namedIndexMock = new Mock("testindex2"); var dir1 = new System.IO.DirectoryInfo(string.Format(@"c:\fake\App_Data\{0}\Main", folderId)); diff --git a/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/RemoveTest.cs b/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/RemoveTest.cs index 20edbc7..bc6bff7 100644 --- a/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/RemoveTest.cs +++ b/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/RemoveTest.cs @@ -1,19 +1,16 @@ using System; using System.Collections.ObjectModel; -using Microsoft.Extensions.Logging; using Moq; using Xunit; namespace EPiServer.Search.IndexingService.Test.Helpers.LuceneHelper { - [Trait(nameof(EPiServer.Search.IndexingService.Helpers.LuceneHelper), nameof(EPiServer.Search.IndexingService.Helpers.LuceneHelper.Remove))] + [Trait(nameof(IndexingService.Helpers.LuceneHelper), nameof(IndexingService.Helpers.LuceneHelper.Remove))] public class RemoveTest : LuceneHelperTestBase { [Fact] public void RemoveFeedItemModelNamedIndex_WhenFeedItemIdNotEqualIgnoreItemId_ShouldRunRemove() { - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; var namedIndexMock = new Mock("testindex1"); var dir1 = Lucene.Net.Store.FSDirectory.Open(new System.IO.DirectoryInfo(string.Format(@"c:\fake\App_Data\{0}\Main", Guid.NewGuid()))); namedIndexMock.SetupGet(x => x.Directory).Returns(() => dir1); @@ -25,8 +22,6 @@ public void RemoveFeedItemModelNamedIndex_WhenFeedItemIdNotEqualIgnoreItemId_Sho [Fact] public void RemoveFeedItemModelNamedIndex_WhenFeedItemIdNotEqualIgnoreItemId_ShouldRunGetAutoUpdateVirtualPathValue() { - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; var namedIndexMock = new Mock("testindex1"); var dir1 = Lucene.Net.Store.FSDirectory.Open(new System.IO.DirectoryInfo(string.Format(@"c:\fake\App_Data\{0}\Main", Guid.NewGuid()))); namedIndexMock.SetupGet(x => x.Directory).Returns(() => dir1); @@ -43,9 +38,6 @@ public void RemoveFeedItemModelNamedIndex_WhenFeedItemIdNotEqualIgnoreItemId_Sho [Fact] public void RemoveStringNamedIndexBool_ShouldWork() { - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; - var namedIndexMock = new Mock("testindex1"); var dir1 = Lucene.Net.Store.FSDirectory.Open(new System.IO.DirectoryInfo(string.Format(@"c:\fake\App_Data\{0}\Main", Guid.NewGuid()))); namedIndexMock.SetupGet(x => x.Directory).Returns(() => dir1); diff --git a/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/UpdateReferenceTest.cs b/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/UpdateReferenceTest.cs index 944fbfd..ee7d0e5 100644 --- a/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/UpdateReferenceTest.cs +++ b/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/UpdateReferenceTest.cs @@ -1,19 +1,15 @@ using Lucene.Net.Documents; -using Microsoft.Extensions.Logging; using Moq; using Xunit; namespace EPiServer.Search.IndexingService.Test.Helpers.LuceneHelper { - [Trait(nameof(EPiServer.Search.IndexingService.Helpers.LuceneHelper), nameof(EPiServer.Search.IndexingService.Helpers.LuceneHelper.UpdateReference))] + [Trait(nameof(IndexingService.Helpers.LuceneHelper), nameof(IndexingService.Helpers.LuceneHelper.UpdateReference))] public class UpdateReferenceTest : LuceneHelperTestBase { [Fact] public void UpdateReference_WhenMainDocIsNull_ShouldReturnFalse() { - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; - _documentHelperMock.Setup(x => x.GetDocumentById(It.IsAny(), It.IsAny())).Returns((Document)null); var classInstant = SetupMock(); @@ -24,9 +20,6 @@ public void UpdateReference_WhenMainDocIsNull_ShouldReturnFalse() [Fact] public void UpdateReference_WhenMainDocIsNotNull_ShouldReturnTrue() { - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; - var doc = new Document { new TextField(IndexingServiceSettings.VirtualPathFieldName, "vp", Field.Store.YES) diff --git a/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/UpdateTest.cs b/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/UpdateTest.cs index 1bb5751..6099fbe 100644 --- a/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/UpdateTest.cs +++ b/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/UpdateTest.cs @@ -1,20 +1,17 @@ using System; using System.Collections.ObjectModel; using Lucene.Net.Documents; -using Microsoft.Extensions.Logging; using Moq; using Xunit; namespace EPiServer.Search.IndexingService.Test.Helpers.LuceneHelper { - [Trait(nameof(EPiServer.Search.IndexingService.Helpers.LuceneHelper), nameof(EPiServer.Search.IndexingService.Helpers.LuceneHelper.Update))] + [Trait(nameof(IndexingService.Helpers.LuceneHelper), nameof(IndexingService.Helpers.LuceneHelper.Update))] public class UpdateTest : LuceneHelperTestBase { [Fact] public void Update_ShouldWork() { - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; var feed = new FeedItemModel() { Id = "Id", diff --git a/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/UpdateVirtualPathsTest.cs b/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/UpdateVirtualPathsTest.cs index 8a7abb6..f2b2c4e 100644 --- a/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/UpdateVirtualPathsTest.cs +++ b/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/UpdateVirtualPathsTest.cs @@ -1,13 +1,12 @@ using System; using System.Collections.ObjectModel; using Lucene.Net.Documents; -using Microsoft.Extensions.Logging; using Moq; using Xunit; namespace EPiServer.Search.IndexingService.Test.Helpers.LuceneHelper { - [Trait(nameof(EPiServer.Search.IndexingService.Helpers.LuceneHelper), nameof(EPiServer.Search.IndexingService.Helpers.LuceneHelper.UpdateVirtualPaths))] + [Trait(nameof(IndexingService.Helpers.LuceneHelper), nameof(IndexingService.Helpers.LuceneHelper.UpdateVirtualPaths))] public class UpdateVirtualPathsTest : LuceneHelperTestBase { [Fact] @@ -29,9 +28,6 @@ public void UpdateVirtualPaths_WhenNewVirtualPathEqualToOldVirtualPath_ShouldRet [Fact] public void UpdateVirtualPaths_ShouldReturnTrue() { - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; - var folderId = Guid.NewGuid(); var namedIndexMock = new Mock("testindex1"); var dir1 = new System.IO.DirectoryInfo(string.Format(@"c:\fake\App_Data\{0}\Main", folderId)); diff --git a/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/WriteToIndexTest.cs b/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/WriteToIndexTest.cs index 7a3d991..bb9bfbc 100644 --- a/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/WriteToIndexTest.cs +++ b/test/EPiServer.Search.IndexingService.Test/Helpers/LuceneHelper/WriteToIndexTest.cs @@ -1,19 +1,16 @@ using System; using Lucene.Net.Documents; -using Microsoft.Extensions.Logging; using Moq; using Xunit; namespace EPiServer.Search.IndexingService.Test.Helpers.LuceneHelper { - [Trait(nameof(EPiServer.Search.IndexingService.Helpers.LuceneHelper), nameof(EPiServer.Search.IndexingService.Helpers.LuceneHelper.WriteToIndex))] + [Trait(nameof(IndexingService.Helpers.LuceneHelper), nameof(IndexingService.Helpers.LuceneHelper.WriteToIndex))] public class WriteToIndexTest : LuceneHelperTestBase { [Fact] public void WriteToIndexTest_WhenDocumentExists_ShouldReturnFalse() { - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; var doc = new Document(); var namedIndex = new NamedIndex("testindex1"); _documentHelperMock.Setup(x => x.DocumentExists(It.IsAny(), It.IsAny())).Returns(true); @@ -27,9 +24,6 @@ public void WriteToIndexTest_WhenDocumentExists_ShouldReturnFalse() [Fact] public void WriteToIndexTest_WhenDocumentNotExists_ShouldReturnTrue() { - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; - var doc = new Document(); var dir = Lucene.Net.Store.FSDirectory.Open(new System.IO.DirectoryInfo(string.Format(@"c:\fake\App_Data\{0}\Main", Guid.NewGuid()))); diff --git a/test/EPiServer.Search.IndexingService.Test/IndexingServiceHandler/IndexingServiceHandlerTestBase.cs b/test/EPiServer.Search.IndexingService.Test/IndexingServiceHandler/IndexingServiceHandlerTestBase.cs index 7d916be..cfced50 100644 --- a/test/EPiServer.Search.IndexingService.Test/IndexingServiceHandler/IndexingServiceHandlerTestBase.cs +++ b/test/EPiServer.Search.IndexingService.Test/IndexingServiceHandler/IndexingServiceHandlerTestBase.cs @@ -1,4 +1,4 @@ -using EPiServer.Search.IndexingService.Helpers; +using EPiServer.Search.IndexingService.Helpers; using Microsoft.Extensions.Logging; using Moq; @@ -11,6 +11,8 @@ public class IndexingServiceHandlerTestBase protected Mock _commonFuncMock; protected Mock _responseExceptionHelperMock; protected Mock _documentHelperMock; + protected readonly Mock> _loggerMock; + protected readonly Mock _loggerFactoryMock; public IndexingServiceHandlerTestBase() { @@ -19,19 +21,20 @@ public IndexingServiceHandlerTestBase() _commonFuncMock = new Mock(); _responseExceptionHelperMock = new Mock(); _documentHelperMock = new Mock(); - - var logMock = new Mock(); - IndexingServiceSettings.IndexingServiceServiceLog = logMock.Object; + _loggerMock = new Mock>(); + _loggerFactoryMock = new Mock(); } - public EPiServer.Search.IndexingService.IndexingServiceHandler SetupMock() + public IndexingService.IndexingServiceHandler SetupMock() { return new IndexingService.IndexingServiceHandler( _feedHelperMock.Object, _luceneHelperMock.Object, _commonFuncMock.Object, _responseExceptionHelperMock.Object, - _documentHelperMock.Object); + _documentHelperMock.Object, + _loggerMock.Object, + _loggerFactoryMock.Object); } } }