예제 #1
0
        public void When_filename_is_set_then_log_output_is_written_to_the_specified_file()
        {
            var filename  = $"{Guid.NewGuid()}.log";
            var attribute = new LogToPocketLoggerAttribute(filename: filename);

            var methodInfo = GetType().GetMethod(nameof(When_filename_is_set_then_log_output_is_written_to_the_specified_file));

            attribute.Before(methodInfo);

            var file    = TestLog.Current.LogFile;
            var message = "hello from " + methodInfo.Name + $" ({Guid.NewGuid()})";

            Log.Info(message);

            attribute.After(methodInfo);

            file.Should().NotBeNull();
            file.Exists.Should().BeTrue();

            var text = File.ReadAllText(file.FullName);

            text.Should().Contain(message);

            file.Name.Should().Be(filename);
        }
예제 #2
0
        public void Start_events_are_logged_for_each_test()
        {
            var attribute = new LogToPocketLoggerAttribute();

            var methodInfo = GetType().GetMethod(nameof(Start_events_are_logged_for_each_test));

            attribute.Before(methodInfo);

            var log = TestLog.Current.Text;

            attribute.After(methodInfo);

            log.First()
            .Should()
            .Contain($"[{GetType().Name}.{nameof(Start_events_are_logged_for_each_test)}]  ▶");
        }
예제 #3
0
        public void When_writeToFile_is_set_to_false_then_no_file_is_written()
        {
            var attribute = new LogToPocketLoggerAttribute(writeToFile: false);

            var methodInfo = GetType().GetMethod(nameof(When_writeToFile_is_set_to_false_then_no_file_is_written));

            attribute.Before(methodInfo);

            Log.Info("hello from {method}", methodInfo.Name);

            var file = TestLog.Current.LogFile;

            attribute.After(methodInfo);

            file.Should().BeNull();
        }
예제 #4
0
        public void Stop_events_are_logged_for_each_test()
        {
            var attribute = new LogToPocketLoggerAttribute();

            var methodInfo = GetType().GetMethod(nameof(Stop_events_are_logged_for_each_test));

            attribute.Before(methodInfo);

            var log = TestLog.Current;

            attribute.After(methodInfo);

            log.Text
            .Last()
            .Should()
            .Match($"*[{GetType().Name}.{nameof(Stop_events_are_logged_for_each_test)}]  ⏹ (*ms)*");
        }
예제 #5
0
        public void When_writeToFile_is_set_to_true_then_a_file_is_written()
        {
            var attribute = new LogToPocketLoggerAttribute(writeToFile: true);

            var methodInfo = GetType().GetMethod(nameof(When_writeToFile_is_set_to_true_then_a_file_is_written));

            attribute.Before(methodInfo);

            var file    = TestLog.Current.LogFile;
            var message = "hello from " + methodInfo.Name + $" ({Guid.NewGuid()})";

            Log.Info(message);

            attribute.After(methodInfo);

            file.Should().NotBeNull();
            file.Exists.Should().BeTrue();

            var text = File.ReadAllText(file.FullName);

            text.Should().Contain(message);
        }