-
Notifications
You must be signed in to change notification settings - Fork 457
/
UseXmlReaderForSchemaReadTests.cs
103 lines (92 loc) · 2.65 KB
/
UseXmlReaderForSchemaReadTests.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
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Test.Utilities;
using Xunit;
namespace Microsoft.NetCore.Analyzers.Security.UnitTests
{
public class UseXmlReaderForSchemaReadTests : DiagnosticAnalyzerTestBase
{
[Fact]
public void TestReadWithStreamAndValidationEventHandlerParametersDiagnostic()
{
VerifyCSharp(@"
using System;
using System.IO;
using System.Xml.Schema;
class TestClass
{
public void TestMethod(Stream stream, ValidationEventHandler validationEventHandler)
{
XmlSchema.Read(stream, validationEventHandler);
}
}",
GetCSharpResultAt(10, 9, UseXmlReaderForSchemaRead.RealRule, "XmlSchema", "Read"));
}
[Fact]
public void TestTextReaderAndValidationEventHandlerParametersDiagnostic()
{
VerifyCSharp(@"
using System;
using System.IO;
using System.Xml.Schema;
class TestClass
{
public void TestMethod(TextReader reader, ValidationEventHandler validationEventHandler)
{
XmlSchema.Read(reader, validationEventHandler);
}
}",
GetCSharpResultAt(10, 9, UseXmlReaderForSchemaRead.RealRule, "XmlSchema", "Read"));
}
[Fact]
public void TestXmlReaderAndValidationEventHandlerParametersNoDiagnostic()
{
VerifyCSharp(@"
using System;
using System.Xml;
using System.Xml.Schema;
class TestClass
{
public void TestMethod(XmlReader reader, ValidationEventHandler validationEventHandler)
{
XmlSchema.Read(reader, validationEventHandler);
}
}");
}
[Fact]
public void XmlSchemaReadDocSample1_Solution()
{
VerifyCSharp(@"
using System.IO;
using System.Xml;
using System.Xml.Schema;
class TestClass
{
public XmlSchema Test
{
get
{
var src = """";
TextReader tr = new StreamReader(src);
XmlReader reader = XmlReader.Create(tr, new XmlReaderSettings() { XmlResolver = null });
XmlSchema schema = XmlSchema.Read(reader , null);
return schema;
}
}
}");
}
protected override DiagnosticAnalyzer GetBasicDiagnosticAnalyzer()
{
return new UseXmlReaderForSchemaRead();
}
protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
{
return new UseXmlReaderForSchemaRead();
}
}
}