public void Start(IList <IWebSocketConnection> clients) { var loggerConfig = _loggerContext.LoggerConfig as ILoggerConfig; _server = _webSocketServerFactory.New(loggerConfig.ServerLoggingAddress); _server.Start(socket => { socket.OnOpen = () => { _writer.WriteLine("Logging Server OnOpen..."); clients.Add(socket); }; socket.OnClose = () => { _writer.WriteLine("Logging Server OnClose..."); clients.Remove(socket); }; socket.OnError = exception => { _writer.WriteLine($"Logging Server OnError, Error details:{exception.Message}"); }; var consumer = new SeriLogConsumer(_loggerContext); socket.StartConsuming(new AuditCommandConsumer(consumer, socket, _writer)); }); }
public void SeriLogConsumer_Consume_WarningMessage_ShouldCall_Warning() { //------------------------------Arrange----------------------------- var audit = new AuditStub(); audit.AuditType = "Warning"; var message = audit; var mockLogger = new Mock <ILogger>(); var mockLoggerPublisher = new Mock <ILoggerPublisher>(); var mockLoggerContext = new Mock <ILoggerContext>(); var mockLoggerSource = new Mock <ILoggerSource>(); var mockLoggerConnection = new Mock <ILoggerConnection>(); var mockLoggerConfig = new Mock <ILoggerConfig>(); mockLoggerPublisher.Setup(p => p.Warn(It.IsAny <string>(), It.IsAny <object[]>())).Verifiable(); mockLoggerConnection.Setup(l => l.NewPublisher()).Returns(mockLoggerPublisher.Object); mockLoggerSource.Setup(s => s.NewConnection(It.IsAny <ILoggerConfig>())).Returns(mockLoggerConnection.Object); mockLoggerContext.Setup(c => c.Source).Returns(mockLoggerSource.Object); mockLoggerContext.Setup(c => c.LoggerConfig).Returns(mockLoggerConfig.Object); var seriLogConsumer = new SeriLogConsumer(mockLoggerContext.Object); //------------------------------Act--------------------------------- var response = seriLogConsumer.Consume(message); //------------------------------Assert------------------------------ mockLoggerPublisher.Verify(p => p.Warn(It.IsAny <string>(), It.IsAny <object[]>()), Times.Once); }
public void SeriLogConsumer_Consume_Success() { //------------------------------Arrange----------------------------- var audit = new AuditStub(); audit.AuditType = "Information"; var message = audit; var mockLogger = new Mock <ILogger>(); var mockLoggerPublisher = new Mock <ILoggerPublisher>(); var mockLoggerContext = new Mock <ILoggerContext>(); var mockLoggerSource = new Mock <ILoggerSource>(); var mockLoggerConnection = new Mock <ILoggerConnection>(); var mockLoggerConfig = new Mock <ILoggerConfig>(); mockLoggerPublisher.Setup(p => p.Info(It.IsAny <string>(), It.IsAny <object[]>())).Verifiable(); mockLoggerConnection.Setup(l => l.NewPublisher()).Returns(mockLoggerPublisher.Object); mockLoggerSource.Setup(s => s.NewConnection(It.IsAny <ILoggerConfig>())).Returns(mockLoggerConnection.Object); mockLoggerContext.Setup(c => c.Source).Returns(mockLoggerSource.Object); mockLoggerContext.Setup(c => c.LoggerConfig).Returns(mockLoggerConfig.Object); var seriLogConsumer = new SeriLogConsumer(mockLoggerContext.Object); //------------------------------Act--------------------------------- var response = seriLogConsumer.Consume(message); //------------------------------Assert------------------------------ mockLoggerPublisher.Verify(p => p.Info(It.IsAny <string>(), It.IsAny <object[]>()), Times.Once); Assert.AreEqual(expected: ConsumerResult.Success, actual: response.Result); }
public void SeriLogConsumer_Consume_InfoMessage_ShouldCall_Information() { //------------------------------Arrange----------------------------- var audit = new AuditStub(); audit.LogLevel = LogLevel.Info; audit.CustomTransactionID = "testing SeriLogConsumer"; var message = audit; var mockLogger = new Mock <ILogger>(); var mockLoggerPublisher = new Mock <ILoggerPublisher>(); var mockLoggerContext = new Mock <ILoggerContext>(); var mockLoggerSource = new Mock <ILoggerSource>(); var mockLoggerConnection = new Mock <ILoggerConnection>(); var mockLoggerConfig = new Mock <ILoggerConfig>(); mockLoggerPublisher.Setup(p => p.Info(It.IsAny <string>(), It.IsAny <object[]>())).Verifiable(); mockLoggerConnection.Setup(l => l.NewPublisher()).Returns(mockLoggerPublisher.Object); mockLoggerSource.Setup(s => s.NewConnection(It.IsAny <ILoggerConfig>())).Returns(mockLoggerConnection.Object); mockLoggerContext.Setup(c => c.Source).Returns(mockLoggerSource.Object); mockLoggerContext.Setup(c => c.LoggerConfig).Returns(mockLoggerConfig.Object); var seriLogConsumer = new SeriLogConsumer(mockLoggerContext.Object); //------------------------------Act--------------------------------- var response = seriLogConsumer.Consume(message, null); //------------------------------Assert------------------------------ mockLoggerPublisher.Verify(p => p.Info(It.IsAny <string>(), It.IsAny <object[]>()), Times.Once); }
public void Start(IList <IWebSocketConnection> clients) { var loggerConfig = _loggerContext.LoggerConfig; _server = _webSocketServerFactory.New(loggerConfig.Endpoint); _server.Start(socket => { socket.OnOpen = () => { _writer.WriteLine("Logging Server OnOpen..."); clients.Add(socket); }; socket.OnClose = () => { _writer.WriteLine("Logging Server OnClose..."); clients.Remove(socket); }; socket.OnError = exception => { _writer.WriteLine($"Logging Server OnError, Error details:{exception.Message}"); }; var innerConsumer = new SeriLogConsumer(_loggerContext); var defaultConsumer = _auditCommandConsumerFactory?.New(innerConsumer, socket, _writer) ?? new AuditCommandConsumerFactory().New(innerConsumer, socket, _writer); socket.StartConsuming(new ForwardingConsumer(defaultConsumer, _loggerContext)); }); }
public IAuditCommandConsumer New(SeriLogConsumer innerConsumer, IWebSocketConnection socket, IWriter writer) { return(new AuditCommandConsumer(innerConsumer, socket, writer)); }