forked from microsoft/vstest
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
RunConfiguration.cs
926 lines (793 loc) · 35.7 KB
/
RunConfiguration.cs
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace Microsoft.VisualStudio.TestPlatform.ObjectModel
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Xml;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;
using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;
/// <summary>
/// Stores information about a test settings.
/// </summary>
public class RunConfiguration : TestRunSettings
{
#region Private Fields
/// <summary>
/// Platform architecture which rocksteady should use for discovery/execution
/// </summary>
private Architecture platform;
/// <summary>
/// Maximum number of cores that the engine can use to run tests in parallel
/// </summary>
private int maxCpuCount;
/// <summary>
/// .Net framework which rocksteady should use for discovery/execution
/// </summary>
private Framework framework;
/// <summary>
/// Specifies the frequency of the runStats/discoveredTests event
/// </summary>
private long batchSize;
/// <summary>
/// Specifies the Test Session Timeout in milliseconds
/// </summary>
private long testSessionTimeout;
/// <summary>
/// Directory in which rocksteady/adapter should keep their run specific data.
/// </summary>
private string resultsDirectory;
/// <summary>
/// Paths at which rocksteady should look for test adapters
/// </summary>
private string testAdaptersPaths;
/// <summary>
/// Indication to adapters to disable app domain.
/// </summary>
private bool disableAppDomain;
/// <summary>
/// Indication to adapters to disable parallelization.
/// </summary>
private bool disableParallelization;
/// <summary>
/// True if test run is triggered
/// </summary>
private bool designMode;
/// <summary>
/// Specify to run tests in isolation
/// </summary>
private bool inIsolation;
/// <summary>
/// False indicates that the test adapter should not collect source information for discovered tests
/// </summary>
private bool shouldCollectSourceInformation;
/// <summary>
/// Gets the targetDevice IP for UWP app deployment
/// </summary>
private string targetDevice;
#endregion
#region Constructor
/// <summary>
/// Initializes a new instance of the <see cref="RunConfiguration"/> class.
/// </summary>
public RunConfiguration() : base(Constants.RunConfigurationSettingsName)
{
// Set defaults for target platform, framework version type and results directory.
this.platform = Constants.DefaultPlatform;
this.framework = Framework.DefaultFramework;
this.resultsDirectory = Constants.DefaultResultsDirectory;
this.SolutionDirectory = null;
this.TreatTestAdapterErrorsAsWarnings = Constants.DefaultTreatTestAdapterErrorsAsWarnings;
this.BinariesRoot = null;
this.testAdaptersPaths = null;
this.maxCpuCount = Constants.DefaultCpuCount;
this.batchSize = Constants.DefaultBatchSize;
this.testSessionTimeout = 0;
this.disableAppDomain = false;
this.disableParallelization = false;
this.designMode = false;
this.inIsolation = false;
this.shouldCollectSourceInformation = false;
this.targetDevice = null;
this.ExecutionThreadApartmentState = Constants.DefaultExecutionThreadApartmentState;
}
#endregion
#region Properties
/// <summary>
/// Gets or sets the solution directory.
/// </summary>
public string SolutionDirectory
{
get;
set;
}
/// <summary>
/// Gets or sets the results directory.
/// </summary>
public string ResultsDirectory
{
get
{
return this.resultsDirectory;
}
set
{
this.resultsDirectory = value;
this.ResultsDirectorySet = true;
}
}
/// <summary>
/// Gets or sets the Parallel execution option. Should be non-negative integer.
/// </summary>
public int MaxCpuCount
{
get
{
return this.maxCpuCount;
}
set
{
this.maxCpuCount = value;
this.MaxCpuCountSet = true;
}
}
/// <summary>
/// Gets or sets the frequency of the runStats/discoveredTests event. Should be non-negative integer.
/// </summary>
public long BatchSize
{
get
{
return this.batchSize;
}
set
{
this.batchSize = value;
this.BatchSizeSet = true;
}
}
/// <summary>
/// Gets or sets the testSessionTimeout. Should be non-negative integer.
/// </summary>
public long TestSessionTimeout
{
get
{
return this.testSessionTimeout;
}
set
{
this.testSessionTimeout = value;
}
}
/// <summary>
/// Gets or sets the design mode value.
/// </summary>
public bool DesignMode
{
get
{
return this.designMode;
}
set
{
this.designMode = value;
this.DesignModeSet = true;
}
}
/// <summary>
/// Gets or sets a value indicating whether to run tests in isolation or not.
/// </summary>
public bool InIsolation
{
get
{
return this.inIsolation;
}
set
{
this.inIsolation = value;
}
}
/// <summary>
/// Gets a value indicating whether test adapter needs to collect source information for discovered tests
/// </summary>
public bool ShouldCollectSourceInformation
{
get
{
return (this.CollectSourceInformationSet) ? this.shouldCollectSourceInformation : this.designMode;
}
set
{
this.shouldCollectSourceInformation = value;
this.CollectSourceInformationSet = true;
}
}
/// <summary>
/// Gets or sets a value indicating whether app domain creation should be disabled.
/// </summary>
public bool DisableAppDomain
{
get
{
return this.disableAppDomain;
}
set
{
this.disableAppDomain = value;
this.DisableAppDomainSet = true;
}
}
/// <summary>
/// Gets a value indicating whether parallelism needs to be disabled by the adapters.
/// </summary>
public bool DisableParallelization
{
get
{
return this.disableParallelization;
}
set
{
this.disableParallelization = value;
this.DisableParallelizationSet = true;
}
}
/// <summary>
/// Gets or sets the Target platform this run is targeting. Possible values are <c>x86|x64|arm|anycpu</c>.
/// </summary>
public Architecture TargetPlatform
{
get
{
return this.platform;
}
set
{
this.platform = value;
this.TargetPlatformSet = true;
}
}
/// <summary>
/// Gets or sets the target Framework this run is targeting.
/// </summary>
public Framework TargetFramework
{
get
{
return this.framework;
}
set
{
this.framework = value;
this.TargetFrameworkSet = true;
}
}
/// <summary>
/// Gets or sets the target Framework this run is targeting. Possible values are Framework3.5|Framework4.0|Framework4.5
/// </summary>
[Obsolete("Use TargetFramework instead")]
public FrameworkVersion TargetFrameworkVersion
{
get
{
switch(this.framework?.Name)
{
case Constants.DotNetFramework35:
return FrameworkVersion.Framework35;
case Constants.DotNetFramework40:
return FrameworkVersion.Framework40;
case Constants.DotNetFramework45:
return FrameworkVersion.Framework45;
case Constants.DotNetFrameworkCore10:
return FrameworkVersion.FrameworkCore10;
case Constants.DotNetFrameworkUap10:
return FrameworkVersion.FrameworkUap10;
default:
return Constants.DefaultFramework;
}
}
set
{
this.framework = Framework.FromString(value.ToString());
this.TargetFrameworkSet = true;
}
}
/// <summary>
/// Gets or sets the target device IP. For Phone this value is Device, for emulators "Mobile Emulator 10.0.15063.0 WVGA 4 inch 1GB"
/// </summary>
public string TargetDevice
{
get
{
return this.targetDevice;
}
set
{
this.targetDevice = value;
}
}
/// <summary>
/// Gets or sets the paths used for test adapters lookup in test platform.
/// </summary>
public string TestAdaptersPaths
{
get
{
return this.testAdaptersPaths;
}
set
{
this.testAdaptersPaths = value;
if (this.testAdaptersPaths != null)
{
this.TestAdaptersPathsSet = true;
}
}
}
/// <summary>
/// Gets or sets the execution thread apartment state.
/// </summary>
[CLSCompliant(false)]
public PlatformApartmentState ExecutionThreadApartmentState
{
get;
set;
}
/// <summary>
/// Gets or sets a value indicating whether to treat the errors from test adapters as warnings.
/// </summary>
public bool TreatTestAdapterErrorsAsWarnings
{
get;
set;
}
/// <summary>
/// Gets a value indicating whether target platform set.
/// </summary>
public bool TargetPlatformSet
{
get;
private set;
}
/// <summary>
/// Gets a value indicating whether maximum parallelization count is set.
/// </summary>
public bool MaxCpuCountSet
{
get;
private set;
}
/// <summary>
/// Gets a value indicating batch size is set
/// </summary>
public bool BatchSizeSet
{
get;
private set;
}
/// <summary>
/// Gets a value indicating whether design mode is set.
/// </summary>
public bool DesignModeSet
{
get;
private set;
}
/// <summary>
/// Gets a value indicating whether disable appdomain is set.
/// </summary>
public bool DisableAppDomainSet
{
get;
private set;
}
/// <summary>
/// Gets a value indicating whether parallelism needs to be disabled by the adapters.
/// </summary>
public bool DisableParallelizationSet
{
get;
private set;
}
/// <summary>
/// Gets a value indicating whether target framework set.
/// </summary>
public bool TargetFrameworkSet
{
get;
private set;
}
/// <summary>
/// Gets a value indicating whether test adapters paths set.
/// </summary>
public bool TestAdaptersPathsSet
{
get;
private set;
}
/// <summary>
/// Gets a value indicating whether results directory is set.
/// </summary>
public bool ResultsDirectorySet
{
get;
private set;
}
/// <summary>
/// Gets the binaries root.
/// </summary>
public string BinariesRoot { get; private set; }
/// <summary>
/// Collect source information
/// </summary>
public bool CollectSourceInformationSet { get; private set; } = false;
/// <summary>
/// Default filter to use to filter tests
/// </summary>
public string TestCaseFilter { get; private set; }
/// Path to dotnet executable to be used to invoke testhost.dll. Specifying this will skip looking up testhost.exe and will force usage of the testhost.dll.
/// </summary>
public string DotnetHostPath { get; private set; }
#endregion
/// <inheritdoc/>
[SuppressMessage("Microsoft.Security.Xml", "CA3053:UseXmlSecureResolver",
Justification = "XmlDocument.XmlResolver is not available in core. Suppress until fxcop issue is fixed.")]
public override XmlElement ToXml()
{
XmlDocument doc = new XmlDocument();
XmlElement root = doc.CreateElement(Constants.RunConfigurationSettingsName);
XmlElement resultDirectory = doc.CreateElement("ResultsDirectory");
resultDirectory.InnerXml = this.ResultsDirectory;
root.AppendChild(resultDirectory);
XmlElement targetPlatform = doc.CreateElement("TargetPlatform");
targetPlatform.InnerXml = this.TargetPlatform.ToString();
root.AppendChild(targetPlatform);
XmlElement maxCpuCount = doc.CreateElement("MaxCpuCount");
maxCpuCount.InnerXml = this.MaxCpuCount.ToString();
root.AppendChild(maxCpuCount);
XmlElement batchSize = doc.CreateElement("BatchSize");
batchSize.InnerXml = this.BatchSize.ToString();
root.AppendChild(batchSize);
XmlElement testSessionTimeout = doc.CreateElement("TestSessionTimeout");
testSessionTimeout.InnerXml = this.TestSessionTimeout.ToString();
root.AppendChild(testSessionTimeout);
XmlElement designMode = doc.CreateElement("DesignMode");
designMode.InnerXml = this.DesignMode.ToString();
root.AppendChild(designMode);
XmlElement inIsolation = doc.CreateElement("InIsolation");
inIsolation.InnerXml = this.InIsolation.ToString();
root.AppendChild(inIsolation);
XmlElement collectSourceInformation = doc.CreateElement("CollectSourceInformation");
collectSourceInformation.InnerXml = this.ShouldCollectSourceInformation.ToString();
root.AppendChild(collectSourceInformation);
XmlElement disableAppDomain = doc.CreateElement("DisableAppDomain");
disableAppDomain.InnerXml = this.DisableAppDomain.ToString();
root.AppendChild(disableAppDomain);
XmlElement disableParallelization = doc.CreateElement("DisableParallelization");
disableParallelization.InnerXml = this.DisableParallelization.ToString();
root.AppendChild(disableParallelization);
XmlElement targetFrameworkVersion = doc.CreateElement("TargetFrameworkVersion");
targetFrameworkVersion.InnerXml = this.TargetFramework.ToString();
root.AppendChild(targetFrameworkVersion);
XmlElement executionThreadApartmentState = doc.CreateElement("ExecutionThreadApartmentState");
executionThreadApartmentState.InnerXml = this.ExecutionThreadApartmentState.ToString();
root.AppendChild(executionThreadApartmentState);
if (this.TestAdaptersPaths != null)
{
XmlElement testAdaptersPaths = doc.CreateElement("TestAdaptersPaths");
testAdaptersPaths.InnerXml = this.TestAdaptersPaths;
root.AppendChild(testAdaptersPaths);
}
XmlElement treatTestAdapterErrorsAsWarnings = doc.CreateElement("TreatTestAdapterErrorsAsWarnings");
treatTestAdapterErrorsAsWarnings.InnerXml = this.TreatTestAdapterErrorsAsWarnings.ToString();
root.AppendChild(treatTestAdapterErrorsAsWarnings);
if (this.BinariesRoot != null)
{
XmlElement binariesRoot = doc.CreateElement("BinariesRoot");
binariesRoot.InnerXml = this.BinariesRoot;
root.AppendChild(binariesRoot);
}
if(!string.IsNullOrEmpty(this.TargetDevice))
{
XmlElement targetDevice = doc.CreateElement("TargetDevice");
targetDevice.InnerXml = this.TargetDevice;
root.AppendChild(targetDevice);
}
if (!string.IsNullOrEmpty(this.TestCaseFilter))
{
XmlElement testCaseFilter = doc.CreateElement(nameof(TestCaseFilter));
testCaseFilter.InnerXml = this.TestCaseFilter;
root.AppendChild(testCaseFilter);
}
if (!string.IsNullOrEmpty(this.DotnetHostPath))
{
XmlElement dotnetHostPath = doc.CreateElement(nameof(DotnetHostPath));
dotnetHostPath.InnerXml = this.DotnetHostPath;
root.AppendChild(dotnetHostPath);
}
return root;
}
/// <summary>
/// Loads RunConfiguration from XmlReader.
/// </summary>
/// <param name="reader">XmlReader having run configuration node.</param>
/// <returns></returns>
public static RunConfiguration FromXml(XmlReader reader)
{
ValidateArg.NotNull<XmlReader>(reader, "reader");
var runConfiguration = new RunConfiguration();
var empty = reader.IsEmptyElement;
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
// Process the fields in Xml elements
reader.Read();
if (!empty)
{
while (reader.NodeType == XmlNodeType.Element)
{
string elementName = reader.Name;
switch (elementName)
{
case "ResultsDirectory":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
string resultsDir = reader.ReadElementContentAsString();
if(string.IsNullOrEmpty(resultsDir))
{
throw new SettingsException(
string.Format(
CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue,
Constants.RunConfigurationSettingsName,
resultsDir,
elementName));
}
runConfiguration.ResultsDirectory = resultsDir;
break;
case "CollectSourceInformation":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
string collectSourceInformationStr = reader.ReadElementContentAsString();
bool bCollectSourceInformation = true;
if (!bool.TryParse(collectSourceInformationStr, out bCollectSourceInformation))
{
throw new SettingsException(String.Format(CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, bCollectSourceInformation, elementName));
}
runConfiguration.ShouldCollectSourceInformation = bCollectSourceInformation;
break;
case "MaxCpuCount":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
string cpuCount = reader.ReadElementContentAsString();
int count;
if (!int.TryParse(cpuCount, out count) || count < 0)
{
throw new SettingsException(
string.Format(
CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue,
Constants.RunConfigurationSettingsName,
cpuCount,
elementName));
}
runConfiguration.MaxCpuCount = count;
break;
case "BatchSize":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
string batchSize = reader.ReadElementContentAsString();
long size;
if (!long.TryParse(batchSize, out size) || size < 0)
{
throw new SettingsException(
string.Format(
CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue,
Constants.RunConfigurationSettingsName,
batchSize,
elementName));
}
runConfiguration.BatchSize = size;
break;
case "TestSessionTimeout":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
string testSessionTimeout = reader.ReadElementContentAsString();
long sessionTimeout;
if (!long.TryParse(testSessionTimeout, out sessionTimeout) || sessionTimeout < 0)
{
throw new SettingsException(
string.Format(
CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue,
Constants.RunConfigurationSettingsName,
testSessionTimeout,
elementName));
}
runConfiguration.TestSessionTimeout = sessionTimeout;
break;
case "DesignMode":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
string designModeValueString = reader.ReadElementContentAsString();
bool designMode;
if (!bool.TryParse(designModeValueString, out designMode))
{
throw new SettingsException(String.Format(CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, designModeValueString, elementName));
}
runConfiguration.DesignMode = designMode;
break;
case "InIsolation":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
string inIsolationValueString = reader.ReadElementContentAsString();
bool inIsolation;
if (!bool.TryParse(inIsolationValueString, out inIsolation))
{
throw new SettingsException(String.Format(CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, inIsolationValueString, elementName));
}
runConfiguration.InIsolation = inIsolation;
break;
case "DisableAppDomain":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
string disableAppDomainValueString = reader.ReadElementContentAsString();
bool disableAppDomainCheck;
if (!bool.TryParse(disableAppDomainValueString, out disableAppDomainCheck))
{
throw new SettingsException(String.Format(CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, disableAppDomainValueString, elementName));
}
runConfiguration.DisableAppDomain = disableAppDomainCheck;
break;
case "DisableParallelization":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
string disableParallelizationValueString = reader.ReadElementContentAsString();
bool disableParallelizationCheck;
if (!bool.TryParse(disableParallelizationValueString, out disableParallelizationCheck))
{
throw new SettingsException(String.Format(CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, disableParallelizationValueString, elementName));
}
runConfiguration.DisableParallelization = disableParallelizationCheck;
break;
case "TargetPlatform":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
Architecture archType;
string value = reader.ReadElementContentAsString();
try
{
archType = (Architecture)Enum.Parse(typeof(Architecture), value, true);
if (archType != Architecture.X64 && archType != Architecture.X86 && archType != Architecture.ARM)
{
throw new SettingsException(
string.Format(
CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue,
Constants.RunConfigurationSettingsName,
value,
elementName));
}
}
catch (ArgumentException)
{
throw new SettingsException(string.Format(CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, value, elementName));
}
runConfiguration.TargetPlatform = archType;
break;
case "TargetFrameworkVersion":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
Framework frameworkType;
value = reader.ReadElementContentAsString();
try
{
frameworkType = Framework.FromString(value);
if (frameworkType == null)
{
throw new SettingsException(
string.Format(
CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue,
Constants.RunConfigurationSettingsName,
value,
elementName));
}
}
catch (ArgumentException)
{
throw new SettingsException(string.Format(CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, value, elementName));
}
runConfiguration.TargetFramework = frameworkType;
break;
case "TestAdaptersPaths":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
runConfiguration.TestAdaptersPaths = reader.ReadElementContentAsString();
break;
case "TreatTestAdapterErrorsAsWarnings":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
bool treatTestAdapterErrorsAsWarnings = false;
value = reader.ReadElementContentAsString();
try
{
treatTestAdapterErrorsAsWarnings = bool.Parse(value);
}
catch (ArgumentException)
{
throw new SettingsException(string.Format(CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, value, elementName));
}
catch (FormatException)
{
throw new SettingsException(string.Format(CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, value, elementName));
}
runConfiguration.TreatTestAdapterErrorsAsWarnings = treatTestAdapterErrorsAsWarnings;
break;
case "SolutionDirectory":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
string solutionDirectory = reader.ReadElementContentAsString();
solutionDirectory = Environment.ExpandEnvironmentVariables(solutionDirectory);
if (string.IsNullOrEmpty(solutionDirectory) || !Directory.Exists(solutionDirectory))
{
if (EqtTrace.IsErrorEnabled)
{
EqtTrace.Error(string.Format(CultureInfo.CurrentCulture, Resources.Resources.SolutionDirectoryNotExists, solutionDirectory));
}
solutionDirectory = null;
}
runConfiguration.SolutionDirectory = solutionDirectory;
break;
case "BinariesRoot":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
runConfiguration.BinariesRoot = reader.ReadElementContentAsString();
break;
case "ExecutionThreadApartmentState":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
string executionThreadApartmentState = reader.ReadElementContentAsString();
PlatformApartmentState apartmentState;
if (!Enum.TryParse(executionThreadApartmentState, out apartmentState))
{
throw new SettingsException(
string.Format(
CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue,
Constants.RunConfigurationSettingsName,
executionThreadApartmentState,
elementName));
}
runConfiguration.ExecutionThreadApartmentState = apartmentState;
break;
case "TargetDevice":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
runConfiguration.TargetDevice = reader.ReadElementContentAsString();
break;
case "TestCaseFilter":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
runConfiguration.TestCaseFilter = reader.ReadElementContentAsString();
break;
case "DotNetHostPath":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
runConfiguration.DotnetHostPath = reader.ReadElementContentAsString();
break;
default:
// Ignore a runsettings element that we don't understand. It could occur in the case
// the test runner is of a newer version, but the test host is of an earlier version.
if (EqtTrace.IsErrorEnabled)
{
EqtTrace.Warning(
string.Format(
CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsXmlElement,
Constants.RunConfigurationSettingsName,
reader.Name));
}
reader.Skip();
break;
}
}
reader.ReadEndElement();
}
return runConfiguration;
}
}
}