-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathLoggingContext_Tests.cs
More file actions
80 lines (65 loc) · 2.64 KB
/
LoggingContext_Tests.cs
File metadata and controls
80 lines (65 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Framework;
using Shouldly;
using Xunit;
#nullable disable
namespace Microsoft.Build.UnitTests.BackEnd
{
/// <summary>
/// Tests for logging contexts.
/// </summary>
public class LoggingContext_Tests
{
private readonly ITestOutputHelper _output;
public LoggingContext_Tests(ITestOutputHelper outputHelper)
{
_output = outputHelper;
}
/// <summary>
/// A few simple tests for NodeLoggingContexts.
/// </summary>
[Fact]
public void CreateValidNodeLoggingContexts()
{
NodeLoggingContext context = new NodeLoggingContext(new MockLoggingService(_output.WriteLine), 1, true);
context.IsInProcNode.ShouldBeTrue();
context.IsValid.ShouldBeTrue();
context.LogBuildFinished(true);
context.IsValid.ShouldBeFalse();
context.BuildEventContext.NodeId.ShouldBe(1);
NodeLoggingContext context2 = new NodeLoggingContext(new MockLoggingService(_output.WriteLine), 2, false);
context2.IsInProcNode.ShouldBeFalse();
context2.IsValid.ShouldBeTrue();
context2.LogBuildFinished(true);
context2.IsValid.ShouldBeFalse();
context2.BuildEventContext.NodeId.ShouldBe(2);
}
/// <summary>
/// Verifies that if an invalid node ID is passed to the NodeLoggingContext, it throws
/// an exception -- this is to guarantee that if we're passing around invalid node IDs,
/// we'll know about it.
/// </summary>
[Fact]
public void InvalidNodeIdOnNodeLoggingContext()
{
Assert.Throws<InternalErrorException>(() =>
{
_ = new NodeLoggingContext(new MockLoggingService(), -2, true);
});
}
[Fact]
public void HasLoggedErrors()
{
NodeLoggingContext context = new NodeLoggingContext(new MockLoggingService(_output.WriteLine), 1, true);
context.HasLoggedErrors.ShouldBeFalse();
context.LogCommentFromText(Framework.MessageImportance.High, "Test message");
context.HasLoggedErrors.ShouldBeFalse();
context.LogWarningFromText(null, null, null, null, "Test warning");
context.HasLoggedErrors.ShouldBeFalse();
context.LogErrorFromText(null, null, null, null, "Test error");
context.HasLoggedErrors.ShouldBeTrue();
}
}
}