예제 #1
0
        public void Log_WhenLogFileDoesNotExists_CreatesFileAndLogsText()
        {
            // Arrange
            string path = "error.log";

            Assert.IsFalse(File.Exists(path), "Test setup failed.");

            var provider = new XmlFileLoggingProvider(LoggingEventType.Debug, path, null);

            File.Delete(path);

            Assert.IsFalse(File.Exists(path), "Test setup failed.");

            try
            {
                // Act
                provider.Log("Some message");

                // Assert
                Assert.IsTrue(File.Exists(path), "The provider did not create the file and did not log.");
            }
            finally
            {
                File.Delete(path);
            }
        }
예제 #2
0
        public void Log_UninitializedProvider_ThrowsDescriptiveException()
        {
            // Arrange
            var provider = new XmlFileLoggingProvider();

            try
            {
                // Act
                provider.Log("Some message");

                // Assert
                Assert.Fail("Exception expected.");
            }
            catch (InvalidOperationException ex)
            {
                Assert.IsTrue(ex.Message.Contains("The provider has not been initialized"),
                              "A provider that hasn't been initialized correctly, should throw a descriptive " +
                              "exception. Actual: " + ex.Message + Environment.NewLine + ex.StackTrace);

                Assert.IsTrue(ex.Message.Contains("XmlFileLoggingProvider"),
                              "The message should contain the type name of the unitialized provider. Actual: " +
                              ex.Message);
            }
        }