Example #1
0
        public void GetLayout_WithExceptionLayoutAttribute_ShouldReturnLayout2RawLayout()
        {
            // Arrange
            var sut       = new LayoutAdapterProvider();
            var attribute = new ExceptionLayoutAttribute();

            // Act
            var result = sut.GetLayout(attribute);

            // Assert
            Assert.IsInstanceOfType(result, typeof(Layout2RawLayoutAdapter));
        }
        public void CanAdapt_WithInvalidType_ShouldReturnFalse()
        {
            // Arrange
            var sut       = new RawPropertyLayoutAdapter();
            var attribute = new ExceptionLayoutAttribute();

            // Act
            var result = sut.CanAdapt(attribute);

            // Assert
            Assert.IsFalse(result);
        }
        public void AdaptLayoutShouldCorrectlyFormatEvent()
        {
            // Arrange
            var attribute  = new ExceptionLayoutAttribute();
            var repository = LogManager.CreateRepository(Guid.NewGuid().ToString());
            var exception  = new Exception("An error occurred");

            // Act
            var layout = sut.Adapt(attribute);

            var result = layout.Format(new LoggingEvent(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, repository, "TestLogger", Level.Error, "Error occurred", exception));

            // Assert
            var expected = $"{exception.GetType().FullName}: {exception.Message}";

            Assert.AreEqual(expected, result);
        }