-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathLoggingService_Tests.cs
More file actions
1645 lines (1436 loc) · 74.6 KB
/
LoggingService_Tests.cs
File metadata and controls
1645 lines (1436 loc) · 74.6 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading;
using Microsoft.Build.BackEnd;
using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Evaluation;
using Microsoft.Build.Exceptions;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using Microsoft.Build.Logging;
using Microsoft.Build.UnitTests.BackEnd;
using Shouldly;
using Xunit;
#nullable disable
namespace Microsoft.Build.UnitTests.Logging
{
/// <summary>
/// Test the logging service component
/// </summary>
public class LoggingService_Tests
{
#region Data
/// <summary>
/// An already instantiated and initialized service.
/// This is used so the host object does not need to be
/// used in every test method.
/// </summary>
private LoggingService _initializedService;
#endregion
#region Setup
/// <summary>
/// This method is run before each test case is run.
/// We instantiate and initialize a new logging service each time
/// </summary>
public LoggingService_Tests()
{
InitializeLoggingService();
}
#endregion
#region Test BuildComponent Methods
/// <summary>
/// Verify the CreateLogger method create a LoggingService in both Synchronous mode
/// and Asynchronous mode.
/// </summary>
[Fact]
public void CreateLogger()
{
// Generic host which has some default properties set inside of it
IBuildComponent logServiceComponent = (IBuildComponent)LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1);
// Create a synchronous logging service and do some quick checks
Assert.NotNull(logServiceComponent);
LoggingService logService = (LoggingService)logServiceComponent;
Assert.Equal(LoggerMode.Synchronous, logService.LoggingMode);
Assert.Equal(LoggingServiceState.Instantiated, logService.ServiceState);
// Create an asynchronous logging service
logServiceComponent = (IBuildComponent)LoggingService.CreateLoggingService(LoggerMode.Asynchronous, 1);
Assert.NotNull(logServiceComponent);
logService = (LoggingService)logServiceComponent;
Assert.Equal(LoggerMode.Asynchronous, logService.LoggingMode);
Assert.Equal(LoggingServiceState.Instantiated, logService.ServiceState);
// Shutdown logging thread
logServiceComponent.InitializeComponent(new MockHost());
logServiceComponent.ShutdownComponent();
Assert.Equal(LoggingServiceState.Shutdown, logService.ServiceState);
}
/// <summary>
/// Test the IBuildComponent method InitializeComponent, make sure the component gets the parameters it expects
/// </summary>
[Fact]
public void InitializeComponent()
{
IBuildComponent logServiceComponent = (IBuildComponent)LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1);
BuildParameters parameters = new BuildParameters();
parameters.MaxNodeCount = 4;
parameters.OnlyLogCriticalEvents = true;
IBuildComponentHost loggingHost = new MockHost(parameters);
// Make sure we are in the Instantiated state before initializing
Assert.Equal(LoggingServiceState.Instantiated, ((LoggingService)logServiceComponent).ServiceState);
logServiceComponent.InitializeComponent(loggingHost);
// Make sure that the parameters in the host are set in the logging service
LoggingService service = (LoggingService)logServiceComponent;
Assert.Equal(LoggingServiceState.Initialized, service.ServiceState);
Assert.Equal(4, service.MaxCPUCount);
Assert.True(service.OnlyLogCriticalEvents);
}
/// <summary>
/// Verify the correct exception is thrown when a null Component host is passed in
/// </summary>
[Fact]
public void InitializeComponentNullHost()
{
Assert.Throws<InternalErrorException>(() =>
{
IBuildComponent logServiceComponent = (IBuildComponent)LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1);
logServiceComponent.InitializeComponent(null);
});
}
/// <summary>
/// Verify an exception is thrown if in initialized is called after the service has been shutdown
/// </summary>
[Fact]
public void InitializeComponentAfterShutdown()
{
Assert.Throws<InternalErrorException>(() =>
{
_initializedService.ShutdownComponent();
_initializedService.InitializeComponent(new MockHost());
});
}
/// <summary>
/// Verify the correct exceptions are thrown if the loggers crash
/// when they are shutdown
/// </summary>
[Fact]
public void ShutDownComponentExceptionsInForwardingLogger()
{
// Cause a logger exception in the shutdown of the logger
string className = "Microsoft.Build.UnitTests.Logging.LoggingService_Tests+ShutdownLoggerExceptionFL";
Type exceptionType = typeof(LoggerException);
VerifyShutdownExceptions(null, className, exceptionType);
Assert.Equal(LoggingServiceState.Shutdown, _initializedService.ServiceState);
// Cause a general exception which should result in an InternalLoggerException
className = "Microsoft.Build.UnitTests.Logging.LoggingService_Tests+ShutdownGeneralExceptionFL";
exceptionType = typeof(InternalLoggerException);
VerifyShutdownExceptions(null, className, exceptionType);
Assert.Equal(LoggingServiceState.Shutdown, _initializedService.ServiceState);
// Cause a StackOverflow exception in the shutdown of the logger
// this kind of exception should not be caught
className = "Microsoft.Build.UnitTests.Logging.LoggingService_Tests+ShutdownStackoverflowExceptionFL";
exceptionType = typeof(StackOverflowException);
VerifyShutdownExceptions(null, className, exceptionType);
Assert.Equal(LoggingServiceState.Shutdown, _initializedService.ServiceState);
}
/// <summary>
/// Verify the correct exceptions are thrown when ILoggers
/// throw exceptions during shutdown
/// </summary>
[Fact]
public void ShutDownComponentExceptionsInLogger()
{
LoggerThrowException logger = new LoggerThrowException(true, false, new LoggerException("Hello"));
VerifyShutdownExceptions(logger, null, typeof(LoggerException));
logger = new LoggerThrowException(true, false, new Exception("boo"));
VerifyShutdownExceptions(logger, null, typeof(InternalLoggerException));
logger = new LoggerThrowException(true, false, new StackOverflowException());
VerifyShutdownExceptions(logger, null, typeof(StackOverflowException));
Assert.Equal(LoggingServiceState.Shutdown, _initializedService.ServiceState);
}
/// <summary>
/// Make sure an exception is thrown if shutdown is called
/// more than once
/// </summary>
[Fact]
public void DoubleShutdown()
{
Assert.Throws<InternalErrorException>(() =>
{
_initializedService.ShutdownComponent();
_initializedService.ShutdownComponent();
});
}
#endregion
#region RegisterLogger
/// <summary>
/// Verify we get an exception when a null logger is passed in
/// </summary>
[Fact]
public void NullLogger()
{
Assert.Throws<InternalErrorException>(() =>
{
_initializedService.RegisterLogger(null);
});
}
/// <summary>
/// Verify we get an exception when we try and register a logger
/// and the system has already shutdown
/// </summary>
[Fact]
public void RegisterLoggerServiceShutdown()
{
Assert.Throws<InternalErrorException>(() =>
{
_initializedService.ShutdownComponent();
RegularILogger regularILogger = new RegularILogger();
_initializedService.RegisterLogger(regularILogger);
});
}
/// <summary>
/// Verify a logger exception when initializing a logger is rethrown
/// as a logger exception
/// </summary>
[Fact]
public void LoggerExceptionInInitialize()
{
Assert.Throws<LoggerException>(() =>
{
LoggerThrowException exceptionLogger = new LoggerThrowException(false, true, new LoggerException());
_initializedService.RegisterLogger(exceptionLogger);
});
}
/// <summary>
/// Verify a general exception when initializing a logger is wrapped
/// as a InternalLogger exception
/// </summary>
[Fact]
public void GeneralExceptionInInitialize()
{
Assert.Throws<InternalLoggerException>(() =>
{
LoggerThrowException exceptionLogger = new LoggerThrowException(false, true, new Exception());
_initializedService.RegisterLogger(exceptionLogger);
});
}
/// <summary>
/// Verify a critical exception is not wrapped
/// </summary>
[Fact]
public void ILoggerExceptionInInitialize()
{
Assert.Throws<StackOverflowException>(() =>
{
LoggerThrowException exceptionLogger = new LoggerThrowException(false, true, new StackOverflowException());
_initializedService.RegisterLogger(exceptionLogger);
});
}
/// <summary>
/// Register an good Logger and verify it was registered.
/// </summary>
[Fact]
public void RegisterILoggerAndINodeLoggerGood()
{
ConsoleLogger consoleLogger = new ConsoleLogger();
RegularILogger regularILogger = new RegularILogger();
Assert.True(_initializedService.RegisterLogger(consoleLogger));
Assert.True(_initializedService.RegisterLogger(regularILogger));
Assert.NotNull(_initializedService.RegisteredLoggerTypeNames);
// Should have 2 central loggers and 1 forwarding logger
Assert.Equal(3, _initializedService.RegisteredLoggerTypeNames.Count);
Assert.Contains("Microsoft.Build.BackEnd.Logging.CentralForwardingLogger", _initializedService.RegisteredLoggerTypeNames);
Assert.Contains("Microsoft.Build.UnitTests.Logging.LoggingService_Tests+RegularILogger", _initializedService.RegisteredLoggerTypeNames);
Assert.Contains("Microsoft.Build.Logging.ConsoleLogger", _initializedService.RegisteredLoggerTypeNames);
// Should have 1 event sink
Assert.NotNull(_initializedService.RegisteredSinkNames);
Assert.Single(_initializedService.RegisteredSinkNames);
}
/// <summary>
/// Try and register the same logger multiple times
/// </summary>
[Fact]
public void RegisterDuplicateLogger()
{
ConsoleLogger consoleLogger = new ConsoleLogger();
RegularILogger regularILogger = new RegularILogger();
Assert.True(_initializedService.RegisterLogger(consoleLogger));
Assert.False(_initializedService.RegisterLogger(consoleLogger));
Assert.True(_initializedService.RegisterLogger(regularILogger));
Assert.False(_initializedService.RegisterLogger(regularILogger));
Assert.NotNull(_initializedService.RegisteredLoggerTypeNames);
Assert.Equal(3, _initializedService.RegisteredLoggerTypeNames.Count);
Assert.Contains("Microsoft.Build.BackEnd.Logging.CentralForwardingLogger", _initializedService.RegisteredLoggerTypeNames);
Assert.Contains("Microsoft.Build.UnitTests.Logging.LoggingService_Tests+RegularILogger", _initializedService.RegisteredLoggerTypeNames);
Assert.Contains("Microsoft.Build.Logging.ConsoleLogger", _initializedService.RegisteredLoggerTypeNames);
// Should have 1 event sink
Assert.NotNull(_initializedService.RegisteredSinkNames);
Assert.Single(_initializedService.RegisteredSinkNames);
}
#endregion
#region RegisterDistributedLogger
/// <summary>
/// Verify we get an exception when a null logger forwarding logger is passed in
/// </summary>
[Fact]
public void NullForwardingLogger()
{
Assert.Throws<InternalErrorException>(() =>
{
_initializedService.RegisterDistributedLogger(null, null);
});
}
/// <summary>
/// Verify we get an exception when we try and register a distributed logger
/// and the system has already shutdown
/// </summary>
[Fact]
public void RegisterDistributedLoggerServiceShutdown()
{
Assert.Throws<InternalErrorException>(() =>
{
_initializedService.ShutdownComponent();
string className = "Microsoft.Build.Logging.ConfigurableForwardingLogger";
#if FEATURE_ASSEMBLY_LOCATION
LoggerDescription description = CreateLoggerDescription(className, Assembly.GetAssembly(typeof(ProjectCollection)).FullName, true);
#else
LoggerDescription description = CreateLoggerDescription(className, typeof(ProjectCollection).GetTypeInfo().Assembly.FullName, true);
#endif
_initializedService.RegisterDistributedLogger(null, description);
});
}
/// <summary>
/// Register both a good central logger and a good forwarding logger
/// </summary>
[Fact]
public void RegisterGoodDistributedAndCentralLogger()
{
string configurableClassName = "Microsoft.Build.Logging.ConfigurableForwardingLogger";
string distributedClassName = "Microsoft.Build.Logging.DistributedFileLogger";
#if FEATURE_ASSEMBLY_LOCATION
LoggerDescription configurableDescription = CreateLoggerDescription(configurableClassName, Assembly.GetAssembly(typeof(ProjectCollection)).FullName, true);
LoggerDescription distributedDescription = CreateLoggerDescription(distributedClassName, Assembly.GetAssembly(typeof(ProjectCollection)).FullName, true);
#else
LoggerDescription configurableDescription = CreateLoggerDescription(configurableClassName, typeof(ProjectCollection).GetTypeInfo().Assembly.FullName, true);
LoggerDescription distributedDescription = CreateLoggerDescription(distributedClassName, typeof(ProjectCollection).GetTypeInfo().Assembly.FullName, true);
#endif
DistributedFileLogger fileLogger = new DistributedFileLogger();
RegularILogger regularILogger = new RegularILogger();
Assert.True(_initializedService.RegisterDistributedLogger(regularILogger, configurableDescription));
Assert.True(_initializedService.RegisterDistributedLogger(null, distributedDescription));
Assert.NotNull(_initializedService.RegisteredLoggerTypeNames);
// Should have 2 central loggers and 2 forwarding logger
Assert.Equal(4, _initializedService.RegisteredLoggerTypeNames.Count);
Assert.Contains("Microsoft.Build.Logging.ConfigurableForwardingLogger", _initializedService.RegisteredLoggerTypeNames);
Assert.Contains("Microsoft.Build.UnitTests.Logging.LoggingService_Tests+RegularILogger", _initializedService.RegisteredLoggerTypeNames);
Assert.Contains("Microsoft.Build.Logging.DistributedFileLogger", _initializedService.RegisteredLoggerTypeNames);
Assert.Contains("Microsoft.Build.BackEnd.Logging.NullCentralLogger", _initializedService.RegisteredLoggerTypeNames);
// Should have 2 event sink
Assert.NotNull(_initializedService.RegisteredSinkNames);
Assert.Equal(2, _initializedService.RegisteredSinkNames.Count);
Assert.Equal(2, _initializedService.LoggerDescriptions.Count);
}
/// <summary>
/// Have a one forwarding logger which forwards build started and finished and have one which does not and a regular logger. Expect the central loggers to all get
/// one build started and one build finished event only.
/// </summary>
[Fact]
public void RegisterGoodDistributedAndCentralLoggerTestBuildStartedFinished()
{
string configurableClassNameA = "Microsoft.Build.Logging.ConfigurableForwardingLogger";
string configurableClassNameB = "Microsoft.Build.Logging.ConfigurableForwardingLogger";
#if FEATURE_ASSEMBLY_LOCATION
LoggerDescription configurableDescriptionA = CreateLoggerDescription(configurableClassNameA, Assembly.GetAssembly(typeof(ProjectCollection)).FullName, true);
LoggerDescription configurableDescriptionB = CreateLoggerDescription(configurableClassNameB, Assembly.GetAssembly(typeof(ProjectCollection)).FullName, true);
#else
LoggerDescription configurableDescriptionA = CreateLoggerDescription(configurableClassNameA, typeof(ProjectCollection).GetTypeInfo().Assembly.FullName, true);
LoggerDescription configurableDescriptionB = CreateLoggerDescription(configurableClassNameB, typeof(ProjectCollection).GetTypeInfo().Assembly.FullName, true);
#endif
RegularILogger regularILoggerA = new RegularILogger();
RegularILogger regularILoggerB = new RegularILogger();
RegularILogger regularILoggerC = new RegularILogger();
Assert.True(_initializedService.RegisterDistributedLogger(regularILoggerA, configurableDescriptionA));
Assert.True(_initializedService.RegisterDistributedLogger(regularILoggerB, configurableDescriptionB));
Assert.True(_initializedService.RegisterLogger(regularILoggerC));
Assert.NotNull(_initializedService.RegisteredLoggerTypeNames);
_initializedService.LogBuildStarted();
Assert.Equal(1, regularILoggerA.BuildStartedCount);
Assert.Equal(1, regularILoggerB.BuildStartedCount);
Assert.Equal(1, regularILoggerC.BuildStartedCount);
_initializedService.LogBuildFinished(true);
Assert.Equal(1, regularILoggerA.BuildFinishedCount);
Assert.Equal(1, regularILoggerB.BuildFinishedCount);
Assert.Equal(1, regularILoggerC.BuildFinishedCount);
// Make sure if we call build started again we only get one other build started event.
_initializedService.LogBuildStarted();
Assert.Equal(2, regularILoggerA.BuildStartedCount);
Assert.Equal(2, regularILoggerB.BuildStartedCount);
Assert.Equal(2, regularILoggerC.BuildStartedCount);
// Make sure if we call build finished again we only get one other build finished event.
_initializedService.LogBuildFinished(true);
Assert.Equal(2, regularILoggerA.BuildFinishedCount);
Assert.Equal(2, regularILoggerB.BuildFinishedCount);
Assert.Equal(2, regularILoggerC.BuildFinishedCount);
}
/// <summary>
/// Try and register a duplicate central logger
/// </summary>
[Fact]
public void RegisterDuplicateCentralLogger()
{
string className = "Microsoft.Build.Logging.ConfigurableForwardingLogger";
#if FEATURE_ASSEMBLY_LOCATION
LoggerDescription description = CreateLoggerDescription(className, Assembly.GetAssembly(typeof(ProjectCollection)).FullName, true);
#else
LoggerDescription description = CreateLoggerDescription(className, typeof(ProjectCollection).GetTypeInfo().Assembly.FullName, true);
#endif
RegularILogger regularILogger = new RegularILogger();
Assert.True(_initializedService.RegisterDistributedLogger(regularILogger, description));
Assert.False(_initializedService.RegisterDistributedLogger(regularILogger, description));
// Should have 2 central loggers and 1 forwarding logger
Assert.Equal(2, _initializedService.RegisteredLoggerTypeNames.Count);
Assert.Contains("Microsoft.Build.Logging.ConfigurableForwardingLogger", _initializedService.RegisteredLoggerTypeNames);
Assert.Contains("Microsoft.Build.UnitTests.Logging.LoggingService_Tests+RegularILogger", _initializedService.RegisteredLoggerTypeNames);
// Should have 1 sink
Assert.NotNull(_initializedService.RegisteredSinkNames);
Assert.Single(_initializedService.RegisteredSinkNames);
Assert.Single(_initializedService.LoggerDescriptions);
}
/// <summary>
/// Try and register a duplicate Forwarding logger
/// </summary>
[Fact]
public void RegisterDuplicateForwardingLoggerLogger()
{
string className = "Microsoft.Build.Logging.ConfigurableForwardingLogger";
#if FEATURE_ASSEMBLY_LOCATION
LoggerDescription description = CreateLoggerDescription(className, Assembly.GetAssembly(typeof(ProjectCollection)).FullName, true);
#else
LoggerDescription description = CreateLoggerDescription(className, typeof(ProjectCollection).GetTypeInfo().Assembly.FullName, true);
#endif
RegularILogger regularILogger = new RegularILogger();
Assert.True(_initializedService.RegisterDistributedLogger(regularILogger, description));
Assert.True(_initializedService.RegisterDistributedLogger(null, description));
Assert.Equal(4, _initializedService.RegisteredLoggerTypeNames.Count);
// Verify there are two versions in the type names, one for each description
int countForwardingLogger = 0;
foreach (string loggerName in _initializedService.RegisteredLoggerTypeNames)
{
if (String.Equals("Microsoft.Build.Logging.ConfigurableForwardingLogger", loggerName, StringComparison.OrdinalIgnoreCase))
{
countForwardingLogger++;
}
}
Assert.Equal(2, countForwardingLogger);
Assert.Contains("Microsoft.Build.BackEnd.Logging.NullCentralLogger", _initializedService.RegisteredLoggerTypeNames);
Assert.Contains("Microsoft.Build.UnitTests.Logging.LoggingService_Tests+RegularILogger", _initializedService.RegisteredLoggerTypeNames);
// Should have 2 sink
Assert.NotNull(_initializedService.RegisteredSinkNames);
Assert.Equal(2, _initializedService.RegisteredSinkNames.Count);
Assert.Equal(2, _initializedService.LoggerDescriptions.Count);
}
#endregion
#region RegisterLoggerDescriptions
/// <summary>
/// Verify we get an exception when a null description collection is passed in
/// </summary>
[Fact]
public void NullDescriptionCollection()
{
Assert.Throws<InternalErrorException>(() =>
{
_initializedService.InitializeNodeLoggers(null, new EventSourceSink(), 3);
});
}
/// <summary>
/// Verify we get an exception when an empty description collection is passed in
/// </summary>
[Fact]
public void EmptyDescriptionCollection()
{
Assert.Throws<InternalErrorException>(() =>
{
_initializedService.InitializeNodeLoggers(new List<LoggerDescription>(), new EventSourceSink(), 3);
});
}
/// <summary>
/// Verify we get an exception when we try and register a description and the component has already shutdown
/// </summary>
[Fact]
public void NullForwardingLoggerSink()
{
Assert.Throws<InternalErrorException>(() =>
{
string className = "Microsoft.Build.Logging.ConfigurableForwardingLogger";
#if FEATURE_ASSEMBLY_LOCATION
LoggerDescription description = CreateLoggerDescription(className, Assembly.GetAssembly(typeof(ProjectCollection)).FullName, true);
#else
LoggerDescription description = CreateLoggerDescription(className, typeof(ProjectCollection).GetTypeInfo().Assembly.FullName, true);
#endif
_initializedService.ShutdownComponent();
List<LoggerDescription> tempList = new List<LoggerDescription>();
tempList.Add(description);
_initializedService.InitializeNodeLoggers(tempList, new EventSourceSink(), 2);
});
}
/// <summary>
/// Register both a good central logger and a good forwarding logger
/// </summary>
[Fact]
public void RegisterGoodDiscriptions()
{
string configurableClassName = "Microsoft.Build.Logging.ConfigurableForwardingLogger";
string distributedClassName = "Microsoft.Build.BackEnd.Logging.CentralForwardingLogger";
EventSourceSink sink = new EventSourceSink();
EventSourceSink sink2 = new EventSourceSink();
List<LoggerDescription> loggerDescriptions = new List<LoggerDescription>();
#if FEATURE_ASSEMBLY_LOCATION
loggerDescriptions.Add(CreateLoggerDescription(configurableClassName, Assembly.GetAssembly(typeof(ProjectCollection)).FullName, true));
loggerDescriptions.Add(CreateLoggerDescription(distributedClassName, Assembly.GetAssembly(typeof(ProjectCollection)).FullName, true));
#else
loggerDescriptions.Add(CreateLoggerDescription(configurableClassName, typeof(ProjectCollection).GetTypeInfo().Assembly.FullName, true));
loggerDescriptions.Add(CreateLoggerDescription(distributedClassName, typeof(ProjectCollection).GetTypeInfo().Assembly.FullName, true));
#endif
// Register some descriptions with a sink
_initializedService.InitializeNodeLoggers(loggerDescriptions, sink, 1);
// Register the same descriptions with another sink (so we can see that another sink was added)
_initializedService.InitializeNodeLoggers(loggerDescriptions, sink2, 1);
// Register the descriptions again with the same sink so we can verify that another sink was not created
_initializedService.InitializeNodeLoggers(loggerDescriptions, sink, 1);
Assert.NotNull(_initializedService.RegisteredLoggerTypeNames);
// Should have 6 forwarding logger. three of each type
Assert.Equal(6, _initializedService.RegisteredLoggerTypeNames.Count);
Assert.Contains("Microsoft.Build.Logging.ConfigurableForwardingLogger", _initializedService.RegisteredLoggerTypeNames);
Assert.Contains("Microsoft.Build.BackEnd.Logging.CentralForwardingLogger", _initializedService.RegisteredLoggerTypeNames);
int countForwardingLogger = 0;
foreach (string loggerName in _initializedService.RegisteredLoggerTypeNames)
{
if (String.Equals("Microsoft.Build.Logging.ConfigurableForwardingLogger", loggerName, StringComparison.OrdinalIgnoreCase))
{
countForwardingLogger++;
}
}
// Should be 3, one for each call to RegisterLoggerDescriptions
Assert.Equal(3, countForwardingLogger);
countForwardingLogger = 0;
foreach (string loggerName in _initializedService.RegisteredLoggerTypeNames)
{
if (String.Equals("Microsoft.Build.BackEnd.Logging.CentralForwardingLogger", loggerName, StringComparison.OrdinalIgnoreCase))
{
countForwardingLogger++;
}
}
// Should be 3, one for each call to RegisterLoggerDescriptions
Assert.Equal(3, countForwardingLogger);
// Should have 2 event sink
Assert.NotNull(_initializedService.RegisteredSinkNames);
Assert.Equal(2, _initializedService.RegisteredSinkNames.Count);
// There should not be any (this method is to be called on a child node)
Assert.Empty(_initializedService.LoggerDescriptions);
}
/// <summary>
/// Try and register a duplicate central logger
/// </summary>
[Fact]
public void RegisterDuplicateDistributedCentralLogger()
{
string className = "Microsoft.Build.Logging.ConfigurableForwardingLogger";
#if FEATURE_ASSEMBLY_LOCATION
LoggerDescription description = CreateLoggerDescription(className, Assembly.GetAssembly(typeof(ProjectCollection)).FullName, true);
#else
LoggerDescription description = CreateLoggerDescription(className, typeof(ProjectCollection).GetTypeInfo().Assembly.FullName, true);
#endif
RegularILogger regularILogger = new RegularILogger();
Assert.True(_initializedService.RegisterDistributedLogger(regularILogger, description));
Assert.False(_initializedService.RegisterDistributedLogger(regularILogger, description));
// Should have 2 central loggers and 1 forwarding logger
Assert.Equal(2, _initializedService.RegisteredLoggerTypeNames.Count);
Assert.Contains("Microsoft.Build.Logging.ConfigurableForwardingLogger", _initializedService.RegisteredLoggerTypeNames);
Assert.Contains("Microsoft.Build.UnitTests.Logging.LoggingService_Tests+RegularILogger", _initializedService.RegisteredLoggerTypeNames);
// Should have 1 sink
Assert.NotNull(_initializedService.RegisteredSinkNames);
Assert.Single(_initializedService.RegisteredSinkNames);
Assert.Single(_initializedService.LoggerDescriptions);
}
#endregion
#region Test Properties
/// <summary>
/// Verify the getters and setters for the properties work.
/// </summary>
[Fact]
public void Properties()
{
// Test OnlyLogCriticalEvents
LoggingService loggingService = (LoggingService)LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1);
Assert.False(loggingService.OnlyLogCriticalEvents); // "Expected only log critical events to be false"
loggingService.OnlyLogCriticalEvents = true;
Assert.True(loggingService.OnlyLogCriticalEvents); // "Expected only log critical events to be true"
// Test LoggingMode
Assert.Equal(LoggerMode.Synchronous, loggingService.LoggingMode); // "Expected Logging mode to be Synchronous"
// Test LoggerDescriptions
Assert.Empty(loggingService.LoggerDescriptions); // "Expected LoggerDescriptions to be empty"
// Test Number of InitialNodes
Assert.Equal(1, loggingService.MaxCPUCount);
loggingService.MaxCPUCount = 5;
Assert.Equal(5, loggingService.MaxCPUCount);
// Test MinimumRequiredMessageImportance
Assert.Equal(MessageImportance.Low, loggingService.MinimumRequiredMessageImportance);
loggingService.RegisterLogger(new ConsoleLogger(LoggerVerbosity.Normal));
Assert.Equal(MessageImportance.Normal, loggingService.MinimumRequiredMessageImportance);
}
#endregion
#region PacketHandling Tests
/// <summary>
/// Verify how a null packet is handled. There should be an InternalErrorException thrown
/// </summary>
[Fact]
public void NullPacketReceived()
{
Assert.Throws<InternalErrorException>(() =>
{
LoggingService loggingService = (LoggingService)LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1);
loggingService.PacketReceived(1, null);
});
}
/// <summary>
/// Verify when a non logging packet is received.
/// An invalid operation should be thrown
/// </summary>
[Fact]
public void NonLoggingPacketPacketReceived()
{
Assert.Throws<InternalErrorException>(() =>
{
LoggingService loggingService = (LoggingService)LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1);
NonLoggingPacket packet = new NonLoggingPacket();
loggingService.PacketReceived(1, packet);
});
}
/// <summary>
/// Verify when a logging packet is received the build event is
/// properly passed to ProcessLoggingEvent
/// An invalid operation should be thrown
/// </summary>
[Fact]
public void LoggingPacketReceived()
{
LoggingServicesLogMethod_Tests.ProcessBuildEventHelper loggingService = (LoggingServicesLogMethod_Tests.ProcessBuildEventHelper)LoggingServicesLogMethod_Tests.ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1);
BuildMessageEventArgs messageEvent = new BuildMessageEventArgs("MyMessage", "HelpKeyword", "Sender", MessageImportance.High);
LogMessagePacket packet = new LogMessagePacket(new KeyValuePair<int, BuildEventArgs>(1, messageEvent));
loggingService.PacketReceived(1, packet);
BuildMessageEventArgs messageEventFromPacket = loggingService.ProcessedBuildEvent as BuildMessageEventArgs;
Assert.NotNull(messageEventFromPacket);
Assert.Equal(messageEventFromPacket, messageEvent); // "Expected messages to match"
}
#endregion
#region WarningsAsErrors Tests
private static readonly BuildWarningEventArgs BuildWarningEventForTreatAsErrorOrMessageTests = new BuildWarningEventArgs("subcategory", "C94A41A90FFB4EF592BF98BA59BEE8AF", "file", 1, 2, 3, 4, "message", "helpKeyword", "senderName");
/// <summary>
/// Verifies that a warning is logged as an error when it's warning code specified.
/// </summary>
[Theory]
[InlineData(0, 1)]
[InlineData(0, 2)]
[InlineData(1, 1)]
[InlineData(1, 2)]
public void TreatWarningsAsErrorWhenSpecified(int loggerMode, int nodeId)
{
HashSet<string> warningsAsErrors = new HashSet<string>
{
"123",
BuildWarningEventForTreatAsErrorOrMessageTests.Code,
"ABC",
};
MockLogger logger = GetLoggedEventsWithWarningsAsErrorsOrMessages(BuildWarningEventForTreatAsErrorOrMessageTests, (LoggerMode)loggerMode, nodeId, warningsAsErrors);
BuildErrorEventArgs actualBuildEvent = logger.Errors.ShouldHaveSingleItem();
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.Code, actualBuildEvent.Code);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.File, actualBuildEvent.File);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.ProjectFile, actualBuildEvent.ProjectFile);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.Subcategory, actualBuildEvent.Subcategory);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.HelpKeyword, actualBuildEvent.HelpKeyword);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.Message, actualBuildEvent.Message);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.SenderName, actualBuildEvent.SenderName);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.ColumnNumber, actualBuildEvent.ColumnNumber);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.EndColumnNumber, actualBuildEvent.EndColumnNumber);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.EndLineNumber, actualBuildEvent.EndLineNumber);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.LineNumber, actualBuildEvent.LineNumber);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.BuildEventContext, actualBuildEvent.BuildEventContext);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.Timestamp, actualBuildEvent.Timestamp);
}
/// <summary>
/// Verifies that a warning is not treated as an error when other warning codes are specified.
/// </summary>
[Fact]
public void NotTreatWarningsAsErrorWhenNotSpecified()
{
HashSet<string> warningsAsErrors = new HashSet<string>
{
"123",
"ABC",
};
MockLogger logger = GetLoggedEventsWithWarningsAsErrorsOrMessages(BuildWarningEventForTreatAsErrorOrMessageTests, warningsAsErrors: warningsAsErrors);
var actualEvent = logger.Warnings.ShouldHaveSingleItem();
actualEvent.ShouldBe(BuildWarningEventForTreatAsErrorOrMessageTests);
}
/// <summary>
/// Verifies that a warning is not treated as an error when other warning codes are specified.
/// </summary>
[Theory]
[InlineData(0, 1)]
[InlineData(0, 2)]
[InlineData(1, 1)]
[InlineData(1, 2)]
public void TreatWarningsAsErrorWhenAllSpecified(int loggerMode, int nodeId)
{
HashSet<string> warningsAsErrors = new HashSet<string>();
MockLogger logger = GetLoggedEventsWithWarningsAsErrorsOrMessages(BuildWarningEventForTreatAsErrorOrMessageTests, (LoggerMode)loggerMode, nodeId, warningsAsErrors);
logger.Errors.ShouldHaveSingleItem();
}
[Fact]
public void VerifyWarningsPromotedToErrorsAreCounted()
{
ILoggingService ls = LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1);
ls.WarningsAsErrors = new HashSet<string>();
ls.WarningsAsErrors.Add("FOR123");
BuildWarningEventArgs warningArgs = new("abc", "FOR123", "", 0, 0, 0, 0, "warning message", "keyword", "sender");
warningArgs.BuildEventContext = new BuildEventContext(1, 2, BuildEventContext.InvalidProjectContextId, BuildEventContext.InvalidProjectContextId, 5, 6);
ls.LogBuildEvent(warningArgs);
ls.HasBuildSubmissionLoggedErrors(1).ShouldBeTrue();
}
/// <summary>
/// Verifies that a warning is logged as a low importance message when it's warning code is specified.
/// </summary>
[Theory]
[InlineData(0, 1)]
[InlineData(0, 2)]
[InlineData(1, 1)]
[InlineData(1, 2)]
public void TreatWarningsAsMessagesWhenSpecified(int loggerMode, int nodeId)
{
HashSet<string> warningsAsMessages = new HashSet<string>
{
"FOO",
BuildWarningEventForTreatAsErrorOrMessageTests.Code,
"BAR",
};
MockLogger logger = GetLoggedEventsWithWarningsAsErrorsOrMessages(BuildWarningEventForTreatAsErrorOrMessageTests, (LoggerMode)loggerMode, nodeId, warningsAsMessages: warningsAsMessages);
BuildMessageEventArgs actualBuildEvent = logger.BuildMessageEvents.ShouldHaveSingleItem();
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.BuildEventContext, actualBuildEvent.BuildEventContext);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.Code, actualBuildEvent.Code);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.ColumnNumber, actualBuildEvent.ColumnNumber);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.EndColumnNumber, actualBuildEvent.EndColumnNumber);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.EndLineNumber, actualBuildEvent.EndLineNumber);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.File, actualBuildEvent.File);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.HelpKeyword, actualBuildEvent.HelpKeyword);
Assert.Equal(MessageImportance.Low, actualBuildEvent.Importance);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.LineNumber, actualBuildEvent.LineNumber);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.Message, actualBuildEvent.Message);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.ProjectFile, actualBuildEvent.ProjectFile);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.SenderName, actualBuildEvent.SenderName);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.Subcategory, actualBuildEvent.Subcategory);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.Timestamp, actualBuildEvent.Timestamp);
}
/// <summary>
/// Verifies that a warning is not treated as a low importance message when other warning codes are specified.
/// </summary>
[Fact]
public void NotTreatWarningsAsMessagesWhenNotSpecified()
{
HashSet<string> warningsAsMessages = new HashSet<string>
{
"FOO",
"BAR",
};
MockLogger logger = GetLoggedEventsWithWarningsAsErrorsOrMessages(BuildWarningEventForTreatAsErrorOrMessageTests, warningsAsMessages: warningsAsMessages);
logger.Warnings.ShouldHaveSingleItem();
}
/// <summary>
/// Verifies that warnings are treated as an error for a particular project when codes are specified.
/// </summary>
[Theory]
[InlineData(0, 1)]
[InlineData(0, 2)]
[InlineData(1, 1)]
[InlineData(1, 2)]
public void TreatWarningsAsErrorByProjectWhenSpecified(int loggerMode, int nodeId)
{
HashSet<string> warningsAsErrorsForProject = new HashSet<string>
{
"123",
BuildWarningEventForTreatAsErrorOrMessageTests.Code,
"ABC"
};
MockLogger logger = GetLoggedEventsWithWarningsAsErrorsOrMessages(BuildWarningEventForTreatAsErrorOrMessageTests, (LoggerMode)loggerMode, nodeId, warningsAsErrorsForProject: warningsAsErrorsForProject);
BuildErrorEventArgs actualBuildEvent = logger.Errors.ShouldHaveSingleItem();
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.Code, actualBuildEvent.Code);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.File, actualBuildEvent.File);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.ProjectFile, actualBuildEvent.ProjectFile);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.Subcategory, actualBuildEvent.Subcategory);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.HelpKeyword, actualBuildEvent.HelpKeyword);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.Message, actualBuildEvent.Message);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.SenderName, actualBuildEvent.SenderName);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.ColumnNumber, actualBuildEvent.ColumnNumber);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.EndColumnNumber, actualBuildEvent.EndColumnNumber);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.EndLineNumber, actualBuildEvent.EndLineNumber);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.LineNumber, actualBuildEvent.LineNumber);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.BuildEventContext, actualBuildEvent.BuildEventContext);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.Timestamp, actualBuildEvent.Timestamp);
}
/// <summary>
/// Verifies that all warnings are treated as errors for a particular project.
/// </summary>
[Theory]
[InlineData(0, 1)]
[InlineData(0, 2)]
[InlineData(1, 1)]
[InlineData(1, 2)]
public void TreatWarningsAsErrorByProjectWhenAllSpecified(int loggerMode, int nodeId)
{
HashSet<string> warningsAsErrorsForProject = new HashSet<string>();
MockLogger logger = GetLoggedEventsWithWarningsAsErrorsOrMessages(BuildWarningEventForTreatAsErrorOrMessageTests, (LoggerMode)loggerMode, nodeId, warningsAsErrorsForProject: warningsAsErrorsForProject);
logger.Errors.ShouldHaveSingleItem();
}
/// <summary>
/// Verifies that warnings are treated as messages for a particular project.
/// </summary>
[Theory]
[InlineData(0, 1)]
[InlineData(0, 2)]
[InlineData(1, 1)]
[InlineData(1, 2)]
public void TreatWarningsAsMessagesByProjectWhenSpecified(int loggerMode, int nodeId)
{
HashSet<string> warningsAsMessagesForProject = new HashSet<string>
{
"123",
BuildWarningEventForTreatAsErrorOrMessageTests.Code,
"ABC"
};
MockLogger logger = GetLoggedEventsWithWarningsAsErrorsOrMessages(BuildWarningEventForTreatAsErrorOrMessageTests, (LoggerMode)loggerMode, nodeId, warningsAsMessagesForProject: warningsAsMessagesForProject);
BuildMessageEventArgs actualBuildEvent = logger.BuildMessageEvents.ShouldHaveSingleItem();
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.BuildEventContext, actualBuildEvent.BuildEventContext);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.Code, actualBuildEvent.Code);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.ColumnNumber, actualBuildEvent.ColumnNumber);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.EndColumnNumber, actualBuildEvent.EndColumnNumber);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.EndLineNumber, actualBuildEvent.EndLineNumber);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.File, actualBuildEvent.File);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.HelpKeyword, actualBuildEvent.HelpKeyword);
Assert.Equal(MessageImportance.Low, actualBuildEvent.Importance);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.LineNumber, actualBuildEvent.LineNumber);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.Message, actualBuildEvent.Message);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.ProjectFile, actualBuildEvent.ProjectFile);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.SenderName, actualBuildEvent.SenderName);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.Subcategory, actualBuildEvent.Subcategory);
Assert.Equal(BuildWarningEventForTreatAsErrorOrMessageTests.Timestamp, actualBuildEvent.Timestamp);
}
private MockLogger GetLoggedEventsWithWarningsAsErrorsOrMessages(
BuildEventArgs buildEvent,
LoggerMode loggerMode = LoggerMode.Synchronous,
int nodeId = 1,
ISet<string> warningsAsErrors = null,
ISet<string> warningsAsMessages = null,
ISet<string> warningsAsErrorsForProject = null,
ISet<string> warningsAsMessagesForProject = null)
{
IBuildComponentHost host = new MockHost();
BuildEventContext buildEventContext = new BuildEventContext(
submissionId: 0,
nodeId: 1,
projectInstanceId: 2,
projectContextId: -1,
targetId: -1,
taskId: -1);
BuildRequestData buildRequestData = new BuildRequestData("projectFile", new Dictionary<string, string>(), "Current", new[] { "Build" }, null);
ConfigCache configCache = host.GetComponent(BuildComponentType.ConfigCache) as ConfigCache;
configCache.AddConfiguration(new BuildRequestConfiguration(buildEventContext.ProjectInstanceId, buildRequestData, buildRequestData.ExplicitlySpecifiedToolsVersion));
MockLogger logger = new MockLogger();
ILoggingService loggingService = LoggingService.CreateLoggingService(loggerMode, nodeId);
((IBuildComponent)loggingService).InitializeComponent(host);
loggingService.RegisterLogger(logger);
BuildEventContext projectStarted = loggingService.LogProjectStarted(buildEventContext, 0, buildEventContext.ProjectInstanceId, BuildEventContext.Invalid, "projectFile", "Build", Enumerable.Empty<DictionaryEntry>(), Enumerable.Empty<DictionaryEntry>());
if (warningsAsErrorsForProject != null)
{
loggingService.AddWarningsAsErrors(projectStarted, warningsAsErrorsForProject);
}
if (warningsAsMessagesForProject != null)
{
loggingService.AddWarningsAsMessages(projectStarted, warningsAsMessagesForProject);
}
loggingService.WarningsAsErrors = warningsAsErrors;
loggingService.WarningsAsMessages = warningsAsMessages;
buildEvent.BuildEventContext = projectStarted;
loggingService.LogBuildEvent(buildEvent);
loggingService.LogProjectFinished(projectStarted, "projectFile", true);
while (logger.ProjectFinishedEvents.Count == 0)
{
Thread.Sleep(100);