public async Task PostReturnsLogMessageForValidMessages()
        {
            //Arrange
            var fakeMessages = new LogMessageModel()
            {
                Messages = new List <Message>()
                {
                    new Message
                    {
                        Title = "Test message summary",
                        Text  = "Exceptiion occured at ..."
                    }
                }.ToArray()
            };

            var fakeLogMessageResponse = new LogMessageResponse
            {
                Records = new List <RecordResponse>()
                {
                    new RecordResponse
                    {
                        Id    = Guid.NewGuid().ToString(),
                        Field = new Field()
                        {
                            Id         = "recTPWgTQaKlETabD",
                            Message    = "Test message summary",
                            Summary    = "Exceptiion occured at ...",
                            ReceivedAt = DateTime.UtcNow
                        },

                        CreatedTime = DateTime.UtcNow
                    }
                }.ToArray()
            };

            var mockLogMessageManager = new Mock <ILogMessageManager>();

            mockLogMessageManager.Setup(x => x.SendLogMessageAsync(It.IsAny <Message[]>())).Returns(Task.FromResult(fakeLogMessageResponse));

            var mockLogger = new Mock <ILogger <MessageController> >();
            var controller = new MessageController(mockLogMessageManager.Object, mockLogger.Object);

            //Act
            var result = await controller.Post(fakeMessages);

            var okResult = result as OkObjectResult;

            //Assert
            Assert.IsInstanceOf(typeof(LogMessageResponse), okResult.Value);
            Assert.IsNotNull(okResult.Value);
            var response = okResult.Value as LogMessageResponse;

            Assert.AreEqual(fakeLogMessageResponse.Records.Length, response.Records.Length);
            Assert.AreEqual(200, okResult.StatusCode);
        }
Beispiel #2
0
        public LogMessageResponse LogMessage(LogMessageRequest request)
        {
            var response = new LogMessageResponse
            {
                Request = request
            };

            GetLogMessageLookupValues(request.LogMessage);

            _logRepository.LogMessage(request.LogMessage);

            return(response);
        }
        public async Task GetLogMessagesAsync_ReturnsResponseMessages()
        {
            //Arrange
            var fakeLogMessageResponse = new LogMessageResponse
            {
                Records = new List <RecordResponse>()
                {
                    new RecordResponse
                    {
                        Id    = Guid.NewGuid().ToString(),
                        Field = new Field()
                        {
                            Id         = "recTPWgTQaKlETabD",
                            Message    = "Test message summary",
                            Summary    = "Exceptiion occured at ...",
                            ReceivedAt = DateTime.UtcNow
                        },

                        CreatedTime = DateTime.UtcNow
                    },
                    new RecordResponse
                    {
                        Id    = Guid.NewGuid().ToString(),
                        Field = new Field()
                        {
                            Id         = "rectH58h4TrecAdJG",
                            Message    = "Test message summary",
                            Summary    = "Exceptiion occured at ...",
                            ReceivedAt = DateTime.UtcNow
                        },

                        CreatedTime = DateTime.UtcNow
                    }
                }.ToArray()
            };

            var json = JsonConvert.SerializeObject(fakeLogMessageResponse);
            var mockLogMessageManager = new Mock <ILogMessageService>();

            mockLogMessageManager.Setup(x => x.GetLogsAsync(It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(json));
            var manager = new LogMessageManager(mockLogMessageManager.Object);
            //Act
            var response = await manager.GetLogMessagesAsync("2", "Grid+view");

            //Assert
            Assert.IsNotNull(response);
            Assert.AreEqual(fakeLogMessageResponse.Records.Length, response.Records.Length);
            mockLogMessageManager.Verify(s => s.GetLogsAsync(It.IsAny <string>(), It.IsAny <string>()), Times.Once);
        }
        public async Task SendLogMessageAsync_ReturnsResponse_ForValidMessages()
        {
            //Arrange
            var fakeMessages = new List <Message>()
            {
                new Message
                {
                    Title = "Test message summary",
                    Text  = "Exceptiion occured at ..."
                }
            }.ToArray();

            var fakeLogMessageResponse = new LogMessageResponse
            {
                Records = new List <RecordResponse>()
                {
                    new RecordResponse
                    {
                        Id    = Guid.NewGuid().ToString(),
                        Field = new Field()
                        {
                            Id         = "recTPWgTQaKlETabD",
                            Message    = "Test message summary",
                            Summary    = "Exceptiion occured at ...",
                            ReceivedAt = DateTime.UtcNow
                        },

                        CreatedTime = DateTime.UtcNow
                    }
                }.ToArray()
            };

            var json = JsonConvert.SerializeObject(fakeLogMessageResponse);
            var mockLogMessageManager = new Mock <ILogMessageService>();

            mockLogMessageManager.Setup(x => x.SendLogsAsync(It.IsAny <LogMessageRequest>())).Returns(Task.FromResult(json));
            var manager = new LogMessageManager(mockLogMessageManager.Object);
            //Act
            var response = await manager.SendLogMessageAsync(fakeMessages);

            //Assert
            Assert.IsNotNull(response);
            mockLogMessageManager.Verify(s => s.SendLogsAsync(It.IsAny <LogMessageRequest>()), Times.Once);
        }