コード例 #1
0
        public void NetworkLogger_Info()
        {
            var mockAuditEntry = new Mock <IAuditEntry>();
            var logTemplate    = GlobalConstants.WarewolfLogsTemplate;

            var mockSerializer = new Mock <ISerializer>();

            mockSerializer.Setup(o => o.Serialize(It.IsAny <AuditCommand>())).Verifiable();

            var mockWebSocketPool    = new Mock <IWebSocketPool>();
            var mockWebSocketWrapper = new Mock <IWebSocketWrapper>();

            mockWebSocketWrapper.Setup(o => o.SendMessage(It.IsAny <byte[]>())).Verifiable();
            mockWebSocketPool.Setup(o => o.Acquire(Config.Auditing.Endpoint)).Returns(mockWebSocketWrapper.Object).Verifiable();
            mockWebSocketPool.Setup(o => o.Release(It.IsAny <IWebSocketWrapper>())).Verifiable();

            var networkLogger = new NetworkLogger(mockSerializer.Object, mockWebSocketPool.Object);

            networkLogger.Info(logTemplate, mockAuditEntry.Object);

            mockSerializer.Verify(o => o.Serialize(It.IsAny <AuditCommand>()), Times.Once);
            mockWebSocketWrapper.Verify(o => o.SendMessage(It.IsAny <byte[]>()), Times.Once);
            mockWebSocketWrapper.Verify(o => o.IsOpen(), Times.Once);
            mockWebSocketWrapper.Verify(o => o.Connect(), Times.Once);
            mockWebSocketPool.Verify(o => o.Acquire(Config.Auditing.Endpoint), Times.Once);
            mockWebSocketPool.Verify(o => o.Release(It.IsAny <IWebSocketWrapper>()), Times.Once);
        }