public void PassesThroughFatal() { string message = "a message"; MockLog log = new MockLog(); ProxyLog tested = new ProxyLog(log); tested.Fatal(message); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Fatal && x.Message == message)); }
public void Initialize() { _mockLog = new MockLog(); _innerException = new InvalidOperationException(_innerExceptionMessage); _exception = new SystemException(_exceptionMessage, _innerException); _level = LogLevel.Warn; }
public void ShouldLogAsDebugWhenPluginSourceIsAdded() { PluginRepository tested = new PluginRepository(); MockLog log = new MockLog(tested); var pluginSource = new Mock <IPluginSource>().Object; tested.AddPluginSource(pluginSource); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Debug && x.Message.Contains("added") && x.Message.Contains(pluginSource.GetType().FullName))); }
public void ShouldLogToDebugOnPluginQuery() { PluginRepository tested = new PluginRepository(); MockLog log = new MockLog(tested); PluginFilter filter = PluginFilter.Create.IsNamed("plugin name").Implements(typeof(IMockPluginInterface1)); tested.Plugins(filter); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Debug && x.Message.Contains("Returning plugins for") && x.Message.Contains(filter.ToString()))); }
public void ShouldLogRenamedEventToDebug() { System.IO.FileInfo fileInfo = new System.IO.FileInfo(GetType().Assembly.Location); FileSystemWatcher tested = new FileSystemWatcher(); MockLog log = new MockLog(tested); tested.OnRenamed(tested, new System.IO.RenamedEventArgs(System.IO.WatcherChangeTypes.Created, fileInfo.Directory.FullName, "newname.dll", fileInfo.Name)); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Debug && x.Message.Contains(fileInfo.FullName))); }
public void ShouldLogToWarnWhenTryingToFetchUnknownAssembly() { var assemblyname = GetType().Assembly.FullName; var pattern = new Regex(@"^Unable to fetch .+, assembly not known.$"); AssemblyContainer tested = new AssemblyContainer(); MockLog log = new MockLog(tested); tested.Fetch(GetType().Assembly.FullName); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Warn && pattern.IsMatch(x.Message) && x.Message.Contains(assemblyname))); }
public void PassesThroughFormattedDebug() { string format = "message {0}"; string arg = "arg"; var formatProvider = CultureInfo.InvariantCulture; MockLog log = new MockLog(); ProxyLog tested = new ProxyLog(log); tested.Debug(formatProvider, format, arg); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Debug && x.Message == string.Format(formatProvider, format, arg))); }
public void CreateShouldLogCatchedPluginExceptionAsError() { MockAssemblyRepository repository = new MockAssemblyRepository(); IPluginCreator tested = PluginCreator.GetCreator(); MockLog mocklog = new MockLog((ILogWriter)tested); PluginDescriptor descriptor = MockPluginDescriptor.For <MockPlugin2>(); Exception ex = DoAssert.Throws <PluginSettingException>(() => tested.Create(descriptor, repository, null)); Assert.IsTrue(mocklog.Any(x => x.Level == MockLog.Level.Error && x.Message.Contains(ex.Message))); }
public void ShouldLogToDebugWhenRaisingFileLost() { string expected = "SomePath"; MockFileSystemWatcher mockWatcher = new MockFileSystemWatcher(); PluginDirectory tested = new PluginDirectory(mockWatcher); MockLog mockLog = new MockLog(tested); mockWatcher.RaiseDeleted(expected); Assert.IsTrue(mockLog.Any(x => x.Level == MockLog.Level.Debug && x.Message.Contains(expected))); }
public void ShouldLogToInfoWhenAddingAssembly() { var path = GetType().Assembly.Location; AssemblyContainer tested = new AssemblyContainer(); MockLog log = new MockLog(tested); tested.Add(path); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Info && x.Message.Contains("Assembly added ") && x.Message.Contains(path))); }
public void ShouldLogInfoMessageWhenPluginIsCreated() { using (MockDomain domain = new MockDomain()) { MockAssemblyRepository repository = new MockAssemblyRepository(); var creator = PluginCreator.GetCreator(domain); MockLog mocklog = new MockLog(creator as ILogWriter); var descriptor = MockPluginDescriptor.For <MockPlugin1>(); creator.Create(descriptor, repository, null); Assert.IsTrue(mocklog.Any(x => x.Level == MockLog.Level.Info && x.Message.Contains(typeof(MockPlugin1).FullName))); } }
public void ShouldLogToDebugWhenAssemblyIsFetched() { var assemblyname = GetType().Assembly.FullName; var path = GetType().Assembly.Location; var pattern = new Regex(@"^Assembly fetched .+ \(\d+ bytes read from .*\)$"); AssemblyContainer tested = new AssemblyContainer(); MockLog log = new MockLog(tested); tested.Add(path); tested.Fetch(assemblyname); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Debug && pattern.IsMatch(x.Message) && x.Message.Contains(path) && x.Message.Contains(assemblyname))); }
public void ShouldLogInfoEventWithDomainNameOnNewPluginCreator() { using (MockDomain domain = new MockDomain()) { MockAssemblyRepository repository = new MockAssemblyRepository(); MockLog mocklog = new MockLog(typeof(PluginCreator)); var mockLogFactory = new Mock <ILoggerFactory>(); mockLogFactory.Setup(x => x.GetLog(typeof(PluginCreator).FullName)).Returns(mocklog); PluginCreator.GetCreator(domain, mockLogFactory.Object); Assert.IsTrue(mocklog.Any(x => x.Level == MockLog.Level.Info && x.Message.Contains(domain.Domain.FriendlyName))); } }
public void ShouldLogToInfoWhenAddingDirectory() { var path = "mockDir"; var mockPluginDir = new Mock <IPluginDirectory>(); mockPluginDir.Setup(x => x.Path).Returns(path); AssemblyContainer tested = new AssemblyContainer(); MockLog log = new MockLog(tested); tested.AddDir(mockPluginDir.Object); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Info && x.Message.Contains("Added plugin directory ") && x.Message.Contains(path))); }
public void ShouldLogAsInfoOnPluginRemoved() { var mockPluginSource = new Mock <IPluginSource>(); PluginRepository tested = new PluginRepository(); tested.AddPluginSource(mockPluginSource.Object); MockLog log = new MockLog(tested); mockPluginSource.Raise(x => x.PluginRemoved += null, new PluginEventArgs(MockPluginDescriptor.For <MockPlugin1>())); Assert.IsTrue( log.Any( x => x.Level == MockLog.Level.Info && x.Message.Contains("Removed") && x.Message.Contains(typeof(MockPlugin1).FullName))); }
public void ShouldLogToInfoNumberOfAddedPluginsForAssembly() { var path = GetType().Assembly.Location; var pattern = new Regex(@"^Found \d+ plugins in .+$"); var mockAssemblySource = new Mock <IAssemblySource>(); PluginExtractor tested = new PluginExtractor(mockAssemblySource.Object); MockLog log = new MockLog(tested); using (AssemblyReflectionManager manager = new AssemblyReflectionManager()) { manager.LoadAssembly(path); mockAssemblySource.Raise(x => x.AssemblyAdded += null, new AssemblyAddedEventArgs(path, manager)); } Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Info && pattern.IsMatch(x.Message) && x.Message.Contains(path))); }
public void CreateShouldLogCatchedExceptionAsError() { using (MockDomain domain = new MockDomain()) { MockAssemblyRepository repository = new MockAssemblyRepository(); QualifiedName fakeName = new QualifiedName( typeof(string).FullName.Replace("mscorlib", "NonExistingAssemblyName"), typeof(string).Assembly.FullName.Replace("mscorlib", "NonExistingAssemblyName")); IPluginCreator tested = PluginCreator.GetCreator(domain); MockLog mocklog = new MockLog((ILogWriter)tested); PluginDescriptor descriptor = MockPluginDescriptor.For(fakeName); Exception ex = DoAssert.Throws<PluginException>(() => tested.Create(descriptor, repository, null)); Assert.IsTrue(mocklog.Any(x => x.Level == MockLog.Level.Error && x.Message.Contains(ex.Message))); } }
public void CreateShouldLogCatchedExceptionAsError() { using (MockDomain domain = new MockDomain()) { MockAssemblyRepository repository = new MockAssemblyRepository(); QualifiedName fakeName = new QualifiedName( typeof(string).FullName.Replace("mscorlib", "NonExistingAssemblyName"), typeof(string).Assembly.FullName.Replace("mscorlib", "NonExistingAssemblyName")); IPluginCreator tested = PluginCreator.GetCreator(domain); MockLog mocklog = new MockLog((ILogWriter)tested); PluginDescriptor descriptor = MockPluginDescriptor.For(fakeName); Exception ex = DoAssert.Throws <PluginException>(() => tested.Create(descriptor, repository, null)); Assert.IsTrue(mocklog.Any(x => x.Level == MockLog.Level.Error && x.Message.Contains(ex.Message))); } }
public void ShouldLogToDebugIfProcessingIsDelayedBecauseOfMissingDeletedEvent() { var dir = new System.IO.FileInfo(GetType().Assembly.Location).Directory.FullName; var fileName = Guid.NewGuid().ToString(); MockLog log; using (SafeEventFileSystemWatcher tested = new SafeEventFileSystemWatcher(new Mock <IFileSystemWatcher>().Object)) { log = new MockLog(tested); tested.QueueEvent(this, new FileSystemEventArgs(WatcherChangeTypes.Created, dir, fileName)); Thread.Sleep(250); } Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Debug && x.Message.Contains("does not exists, awaiting Deleted event") && x.Message.Contains(dir) && x.Message.Contains(fileName))); }
public void ShouldLogQueuedEventsToDebug() { var dir = "somedir"; var file = "somefile"; MockLog log; using (SafeEventFileSystemWatcher tested = new SafeEventFileSystemWatcher(new Mock <IFileSystemWatcher>().Object)) { log = new MockLog(tested); tested.QueueEvent(tested, new FileSystemEventArgs(WatcherChangeTypes.Created, dir, file)); } Assert.IsTrue( log.Any(x => x.Level == MockLog.Level.Debug && x.Message.Contains(dir) && x.Message.Contains(file) && x.Message.Contains(WatcherChangeTypes.Created.ToString()))); }
public void TestTheWholeThingBecauseWeCan() { // This noise will be in every one of my tests. // I can tuck it somewhere common, but we can also get rid of it entirely. var log = new MockLog(); // or new Mock<ILog>().Error((r) => true)... sucks either way. var db = new MockDb(); // there's undoubtedly more dependencies to be created here. var smtp = new MockSmtp(); var myClass = new MyClass(log, db, smtp); // All of that setup, just to get to here var request = new Request(1, "Yossarian", "*****@*****.**"); var actual = myClass.MyMethod(request); // MyMethod is the only testable unit here. // All of this setup is required for every test. // I can't test the validation logic independently. Assert.AreEqual("Ok", actual); }
public void ShouldLogToDebugIfCompactingAwayAllEventsForFile() { var dir = "somedir"; var file = "somefile"; MockLog log; using (SafeEventFileSystemWatcher tested = new SafeEventFileSystemWatcher(new Mock <IFileSystemWatcher>().Object)) { log = new MockLog(tested); List <FileSystemEventArgs> events = new List <FileSystemEventArgs>(); events.Add(new FileSystemEventArgs(WatcherChangeTypes.Created, dir, file)); events.Add(new FileSystemEventArgs(WatcherChangeTypes.Deleted, dir, file)); tested.Compact(events); } Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Debug && x.Message.Contains(dir) && x.Message.Contains(file))); }
public void TestTheWholeThingBecauseWeCan() { // Still noisy var log = new MockLog(); var db = new MockDb(); var smtp = new MockSmtp(); var myClass = new MyClass(log, db, smtp); var request = new Request(1, "Yossarian", "*****@*****.**"); // I made my UpdateDatabase call internal so I could test it. // I don't want production callers to do this, because it's not what my class is for. // class changes made for testing is an unacceptable compromise! // I also still had to string up ALL of the class dependencies just to test this. // This function doesn't even use a logger. // Passing a null logger into the constructor might work today, but possibly not tomorrow (brittle tests). // But still... I don't give a damn about that smtp thing. But i have to make one every time. // Dependency management digression here ---> ... var actual = myClass.UpdateDatabase(request); Assert.AreEqual("Ok", actual); }
public void ShouldLogToErrorWhenAllKnownPathsToAssemblyDoesNotExist() { var assemblyname = GetType().Assembly.FullName; var path = Guid.NewGuid().ToString() + ".dll"; var pattern = new Regex(@"^Unable to fetch .+, file not found in these locations:$"); try { File.Copy(GetType().Assembly.Location, path); AssemblyContainer tested = new AssemblyContainer(); MockLog log = new MockLog(tested); tested.Add(path); File.Delete(path); tested.Fetch(assemblyname); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Error && pattern.IsMatch(x.Message) && x.Message.Contains(assemblyname))); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Error && x.Message.StartsWith(" --> ") && x.Message.EndsWith(path))); } finally { File.Delete(path); } }
public void FetchShouldLogExceptionsAsErrors() { var assemblyname = GetType().Assembly.FullName; var path = Guid.NewGuid().ToString() + ".dll"; var pattern = new Regex(@"^Exception while fetching .+ (.+) .*$"); try { File.Copy(GetType().Assembly.Location, path); AssemblyContainer tested = new AssemblyContainer(); MockLog log = new MockLog(tested); tested.Add(path); using (var file = File.Open(path, FileMode.Open, FileAccess.Write, FileShare.None)) { tested.Fetch(assemblyname); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Error && pattern.IsMatch(x.Message) && x.Message.Contains(assemblyname) && x.Message.Contains(path))); } } finally { File.Delete(path); } }
public void CreateShouldLogCatchedPluginExceptionAsError() { MockAssemblyRepository repository = new MockAssemblyRepository(); IPluginCreator tested = PluginCreator.GetCreator(); MockLog mocklog = new MockLog((ILogWriter)tested); PluginDescriptor descriptor = MockPluginDescriptor.For<MockPlugin2>(); Exception ex = DoAssert.Throws<PluginSettingException>(() => tested.Create(descriptor, repository, null)); Assert.IsTrue(mocklog.Any(x => x.Level == MockLog.Level.Error && x.Message.Contains(ex.Message))); }
public void ShouldLogToDebugIfProcessingIsDelayedBecauseOfMissingDeletedEvent() { var dir = new System.IO.FileInfo(GetType().Assembly.Location).Directory.FullName; var fileName = Guid.NewGuid().ToString(); MockLog log; using (SafeEventFileSystemWatcher tested = new SafeEventFileSystemWatcher(new Mock<IFileSystemWatcher>().Object)) { log = new MockLog(tested); tested.QueueEvent(this, new FileSystemEventArgs(WatcherChangeTypes.Created, dir, fileName)); Thread.Sleep(250); } Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Debug && x.Message.Contains("does not exists, awaiting Deleted event") && x.Message.Contains(dir) && x.Message.Contains(fileName))); }
public void ShouldLogToInfoWhenRemovingAssembly() { var path = GetType().Assembly.Location; AssemblyContainer tested = new AssemblyContainer(); MockLog log = new MockLog(tested); tested.Add(path); tested.Remove(path); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Info && x.Message.Contains("Assembly removed ") && x.Message.Contains(path))); }
public void SetUp() { _mockLog = new MockLog(); _mockStore = new Mock<ILicenseStore>(); _mockVerifier = new Mock<ISignatureVerifier>(); }
public void ShouldLogRaisedEventsToDebug() { var dir = "somedir"; var file = "somefile"; MockLog log; using (SafeEventFileSystemWatcher tested = new SafeEventFileSystemWatcher(new Mock<IFileSystemWatcher>().Object)) { log = new MockLog(tested); var evt = new FileSystemEventArgs(WatcherChangeTypes.Created, dir, file); tested.RaiseEvent(evt); } Assert.IsTrue( log.Any(x => x.Level == MockLog.Level.Debug && x.Message.Contains(dir) && x.Message.Contains(file) && x.Message.Contains(WatcherChangeTypes.Created.ToString()))); }
public void ShouldLogToInfoNumberOfLostPluginsForAssembly() { var path = GetType().Assembly.Location; var pattern = new Regex(@"^Lost \d+ plugins when .+ was removed$"); var mockAssemblySource = new Mock<IAssemblySource>(); PluginExtractor tested = new PluginExtractor(mockAssemblySource.Object); MockLog log = new MockLog(tested); using (AssemblyReflectionManager manager = new AssemblyReflectionManager()) { manager.LoadAssembly(path); mockAssemblySource.Raise(x => x.AssemblyAdded += null, new AssemblyAddedEventArgs(path, manager)); mockAssemblySource.Raise(x => x.AssemblyRemoved += null, new AssemblyRemovedEventArgs(path)); } Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Info && pattern.IsMatch(x.Message) && x.Message.Contains(path))); }
public virtual void SetUp() { _test.PerformDbOperation(DbOperationFlag.CleanInsertIdentity); _mockLog = new MockLog(); _mockobjectContextFactory = new Mock<IMultitenantObjectContextFactory>(); _mockobjectContextFactory.Setup(m => m.CreateObjectContext(It.IsAny<String>())).Returns(new AuditingObjectContextFactory(ConnectionStrings.TestDatabase).CreateObjectContext()); }
public void ShouldLogAsInfoOnPluginRemoved() { var mockPluginSource = new Mock<IPluginSource>(); PluginRepository tested = new PluginRepository(); tested.AddPluginSource(mockPluginSource.Object); MockLog log = new MockLog(tested); mockPluginSource.Raise(x => x.PluginRemoved += null, new PluginEventArgs(MockPluginDescriptor.For<MockPlugin1>())); Assert.IsTrue( log.Any( x => x.Level == MockLog.Level.Info && x.Message.Contains("Removed") && x.Message.Contains(typeof(MockPlugin1).FullName))); }
public void ShouldLogToInfoWhenRemovingDirectory() { var path = "mockDir"; var mockPluginDir = new Mock<IPluginDirectory>(); mockPluginDir.Setup(x => x.Path).Returns(path); AssemblyContainer tested = new AssemblyContainer(); MockLog log = new MockLog(tested); tested.AddDir(mockPluginDir.Object); tested.RemoveDir(mockPluginDir.Object); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Info && x.Message.Contains("Removed plugin directory ") && x.Message.Contains(path))); }
public void ShouldLogToDebugIfCompactingAwayAllEventsForFile() { var dir = "somedir"; var file = "somefile"; MockLog log; using (SafeEventFileSystemWatcher tested = new SafeEventFileSystemWatcher(new Mock<IFileSystemWatcher>().Object)) { log = new MockLog(tested); List<FileSystemEventArgs> events = new List<FileSystemEventArgs>(); events.Add(new FileSystemEventArgs(WatcherChangeTypes.Created, dir, file)); events.Add(new FileSystemEventArgs(WatcherChangeTypes.Deleted, dir, file)); tested.Compact(events); } Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Debug && x.Message.Contains(dir) && x.Message.Contains(file))); }
public void ShouldLogInfoMessageWhenPluginIsCreated() { using (MockDomain domain = new MockDomain()) { MockAssemblyRepository repository = new MockAssemblyRepository(); var creator = PluginCreator.GetCreator(domain); MockLog mocklog = new MockLog(creator as ILogWriter); var descriptor = MockPluginDescriptor.For<MockPlugin1>(); creator.Create(descriptor, repository, null); Assert.IsTrue(mocklog.Any(x => x.Level == MockLog.Level.Info && x.Message.Contains(typeof(MockPlugin1).FullName))); } }
public void ShouldLogAsDebugWhenPluginSourceIsRemoved() { PluginRepository tested = new PluginRepository(); MockLog log = new MockLog(tested); var pluginSource = new Mock<IPluginSource>().Object; tested.AddPluginSource(pluginSource); tested.RemovePluginSource(pluginSource); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Debug && x.Message.Contains("removed") && x.Message.Contains(pluginSource.GetType().FullName))); }
public void ShouldLogInfoEventWithDomainNameOnNewPluginCreator() { using (MockDomain domain = new MockDomain()) { MockAssemblyRepository repository = new MockAssemblyRepository(); MockLog mocklog = new MockLog(typeof(PluginCreator)); var mockLogFactory = new Mock<ILoggerFactory>(); mockLogFactory.Setup(x => x.GetLog(typeof(PluginCreator).FullName)).Returns(mocklog); PluginCreator.GetCreator(domain, mockLogFactory.Object); Assert.IsTrue(mocklog.Any(x => x.Level == MockLog.Level.Info && x.Message.Contains(domain.Domain.FriendlyName))); } }