using LCU.API.Internal.DocumentLib.Containers; using Microsoft.Extensions.Logging; using OwnerNumberMigration.Logging; using OwnerNumberMigrationTest.TestDataFactories; using OwnerNumberMigrationTest.TestDoubles; namespace OwnerNumberMigrationTest.Logging; public class AttributeMigrationLoggingObserverTest { private readonly IObserver _observer; private readonly FakeLogger _logger = new(); private readonly string _attributeName = Guid.NewGuid().ToString(); public AttributeMigrationLoggingObserverTest() { _observer = new AttributeMigrationLoggingObserver(_logger, _attributeName); } [Test] public void OnCompleted_AllCases_InfoLogsCompletedAttribute() { _observer.OnCompleted(); Func logMatch = l => l.LogLevel == LogLevel.Information && l.Message.Contains("completed", StringComparison.OrdinalIgnoreCase) && l.Message.Contains(_attributeName); Assert.IsTrue(_logger.Logs.Count(logMatch) == 1); } [Test] public void OnError_AllCases_ErrorLogsExceptionAndAttribute() { var error = new Exception(Guid.NewGuid().ToString()); _observer.OnError(error); Func logMatch = l => l.LogLevel == LogLevel.Error && l.Message.Contains(error.Message) && l.Message.Contains(_attributeName); Assert.IsTrue(_logger.Logs.Count(logMatch) == 1); } [Test] public void OnNext_AllCases_InfoLogsStartingAttributeAndDocumentId() { var document = DocumentInformationFactory.CreateDocumentInformation(); _observer.OnNext(document); Func logMatch = l => l.LogLevel == LogLevel.Information && l.Message.Contains(document.DocumentId.ToString()) && l.Message.Contains(_attributeName); Assert.IsTrue(_logger.Logs.Count(logMatch) == 1); } }