Пример #1
0
        private void CheckLogMessages(ITest testDetails)
        {
            int checkedMessages = 0;

            LogMessageAttribute[] attributes = testDetails.Method.GetCustomAttributes <LogMessageAttribute>(true);
            if (attributes.Length > 0)
            {
                for (int i = 0; i < attributes.Length; i++)
                {
                    LogMessageAttribute logMessage = attributes[i];
                    int foundCount = Contains(logMessage.GetMessageTemplate());
                    if (foundCount != logMessage.Count && !logMessage.Ignore)
                    {
                        Assert.Fail("{0} Expected to find {1}, but found {2} messages with the following content: \"{3}\"",
                                    testDetails.FullName, logMessage.Count, foundCount, logMessage.GetMessageTemplate());
                    }
                    else
                    {
                        checkedMessages += foundCount;
                    }
                }
            }

            if (GetSize() > checkedMessages)
            {
                Assert.Fail("{0}: The test does not check the message logging - {1} messages",
                            testDetails.FullName,
                            GetSize() - checkedMessages);
            }
        }
Пример #2
0
        private void CheckLogMessages(ITest testDetails)
        {
            int checkedMessages = 0;

            LogMessageAttribute[] attributes = LogListenerHelper.GetTestAttributes <LogMessageAttribute>(testDetails);
            if (attributes.Length > 0)
            {
                for (int i = 0; i < attributes.Length; i++)
                {
                    LogMessageAttribute logMessage = attributes[i];
                    int foundCount = Contains(logMessage.GetMessageTemplate());
                    if (foundCount != logMessage.Count && !logMessage.Ignore)
                    {
                        LogListenerHelper.FailWrongMessageCount(logMessage.Count, foundCount, logMessage.GetMessageTemplate(), testDetails);
                    }
                    else
                    {
                        checkedMessages += foundCount;
                    }
                }
            }

            if (GetSize() > checkedMessages)
            {
                LogListenerHelper.FailWrongTotalCount(GetSize(), checkedMessages, testDetails);
            }
        }
Пример #3
0
 private void CheckLogMessages(ITest testDetails)
 {
     LogMessageAttribute[] attributes = testDetails.Method.GetCustomAttributes <LogMessageAttribute>(true);
     if (attributes.Length > 0)
     {
         for (int i = 0; i < attributes.Length; i++)
         {
             LogMessageAttribute logMessage = attributes[i];
             if (!logMessage.Ignore)
             {
                 int foundedCount = Contains(logMessage.GetMessageTemplate());
                 if (foundedCount != logMessage.Count)
                 {
                     Assert.Fail("{0} Some log messages are not found in test execution - {1} messages",
                                 testDetails.FullName,
                                 logMessage.Count - foundedCount);
                 }
             }
         }
     }
     else
     {
         if (GetSize() > 0)
         {
             Assert.Fail("{0}: The test does not check the message logging - {1} messages",
                         testDetails.FullName,
                         GetSize());
         }
     }
 }
Пример #4
0
 private void Init(ITest testDetails)
 {
     adapter.Clear();
     LogMessageAttribute[] attributes = LogListenerHelper.GetTestAttributes <LogMessageAttribute>(testDetails);
     if (attributes.Length > 0)
     {
         HashSet <String> expectedTemplates = new HashSet <string>();
         for (int i = 0; i < attributes.Length; i++)
         {
             LogMessageAttribute logMessage = attributes[i];
             expectedTemplates.Add(logMessage.GetMessageTemplate());
         }
         adapter.SetExpectedTemplates(expectedTemplates);
     }
 }
Пример #5
0
        private int Contains(LogMessageAttribute loggingStatement)
        {
            IList <CapturingLoggerEvent> eventList = adapter.LoggerEvents;
            int index = 0;

            for (int i = 0; i < eventList.Count; i++)
            {
                if (IsLevelCompatible(loggingStatement.LogLevel, eventList[i].Level) &&
                    LogListenerHelper.EqualsMessageByTemplate(eventList[i].RenderedMessage, loggingStatement.GetMessageTemplate()))
                {
                    index++;
                }
            }
            return(index);
        }