1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
6
using ICSharpCode.CodeCoverage;
9
namespace ICSharpCode.CodeCoverage.Tests.Coverage
12
/// Tests that property methods (e.g. get_SomeValue) are identified by the CodeCoverageResults class
13
/// via the flags attribute in the code coverage results file.
16
public class CodeCoverageResultsPropertyFlagsTestFixture : CodeCoverageResultsTestsBase
19
public void SetUpFixture()
22
"<PartCoverReport ver=\"1.0.2796.35184\">\r\n" +
23
" <File id=\"1\" url=\"d:\\Projects\\test\\TestFixture1.cs\" />\r\n" +
24
" <Assembly id=\"1\" name=\"MyTests\" module=\"C:\\Projects\\Test\\MyTests\\bin\\MyTests.DLL\" domain=\"test-domain-MyTests.dll\" domainIdx=\"1\" />\r\n" +
25
" <Type asmref=\"1\" name=\"MyTests.Class1\" flags=\"2606412\">\r\n" +
26
" <Method name=\"set_Count\" sig=\"void (int)\" flags=\"2182\" iflags=\"0\">\r\n" +
27
" <pt visit=\"0\" pos=\"9\" len=\"1\" fid=\"1\" sl=\"34\" sc=\"4\" el=\"34\" ec=\"5\" />\r\n" +
28
" <pt visit=\"0\" pos=\"1\" len=\"8\" fid=\"1\" sl=\"33\" sc=\"5\" el=\"33\" ec=\"12\" />\r\n" +
29
" <pt visit=\"0\" pos=\"0\" len=\"1\" fid=\"1\" sl=\"32\" sc=\"8\" el=\"32\" ec=\"9\" />\r\n" +
31
" <Method name=\"get_Count\" sig=\"int ()\" flags=\"2182\" iflags=\"0\">\r\n" +
32
" <pt visit=\"0\" pos=\"6\" len=\"2\" fid=\"1\" sl=\"31\" sc=\"4\" el=\"31\" ec=\"5\" />\r\n" +
33
" <pt visit=\"0\" pos=\"1\" len=\"5\" fid=\"1\" sl=\"30\" sc=\"5\" el=\"30\" ec=\"15\" />\r\n" +
34
" <pt visit=\"0\" pos=\"0\" len=\"1\" fid=\"1\" sl=\"29\" sc=\"8\" el=\"29\" ec=\"9\" />\r\n" +
36
" <Method name=\"get_NotAProperty\" sig=\"void ()\" flags=\"134\" iflags=\"0\">\r\n" +
37
" <pt visit=\"0\" pos=\"1\" len=\"1\" fid=\"1\" sl=\"26\" sc=\"3\" el=\"26\" ec=\"4\" />\r\n" +
38
" <pt visit=\"0\" pos=\"0\" len=\"1\" fid=\"1\" sl=\"25\" sc=\"3\" el=\"25\" ec=\"4\" />\r\n" +
40
" <Method name=\"PropertyFlagsButJustAMethod\" sig=\"void ()\" flags=\"2182\" iflags=\"0\">\r\n" +
41
" <pt visit=\"0\" pos=\"8\" len=\"2\" fid=\"1\" sl=\"22\" sc=\"3\" el=\"22\" ec=\"4\" />\r\n" +
42
" <pt visit=\"0\" pos=\"7\" len=\"1\" fid=\"1\" sl=\"21\" sc=\"3\" el=\"21\" ec=\"4\" />\r\n" +
43
" <pt visit=\"0\" pos=\"0\" len=\"7\" fid=\"1\" sl=\"20\" sc=\"3\" el=\"20\" ec=\"18\" />\r\n" +
45
" <Method name=\"InvalidFlags\" sig=\"void ()\" flags=\"\" iflags=\"0\">\r\n" +
46
" <pt visit=\"0\" pos=\"8\" len=\"2\" fid=\"1\" sl=\"22\" sc=\"3\" el=\"22\" ec=\"4\" />\r\n" +
47
" <pt visit=\"0\" pos=\"7\" len=\"1\" fid=\"1\" sl=\"21\" sc=\"3\" el=\"21\" ec=\"4\" />\r\n" +
48
" <pt visit=\"0\" pos=\"0\" len=\"7\" fid=\"1\" sl=\"20\" sc=\"3\" el=\"20\" ec=\"18\" />\r\n" +
53
base.CreateCodeCoverageResults(xml);
57
public void MethodName_GetterMethod_ReturnsExpectedGetterName()
59
string name = GetterMethod.Name;
60
string expectedName = "get_Count";
61
Assert.AreEqual(expectedName, name);
64
CodeCoverageMethod GetterMethod {
65
get { return base.FirstModuleSecondMethod; }
69
public void MethodIsProperty_GetterMethod_ReturnsTrue()
71
bool result = GetterMethod.IsProperty;
72
Assert.IsTrue(result);
76
public void MethodName_NameOfMethodWithPropertyFlagsButInvalidName_ReturnsMethodName()
78
string name = MethodWithPropertyFlagsButInvalidName.Name;
79
string expectedName = "PropertyFlagsButJustAMethod";
80
Assert.AreEqual(expectedName, name);
83
CodeCoverageMethod MethodWithPropertyFlagsButInvalidName {
84
get { return FirstModule.Methods[3]; }
88
public void MethodName_SetterMethod_ReturnsSetterMethodName()
90
string name = SetterMethod.Name;
91
string expectedName = "set_Count";
92
Assert.AreEqual(expectedName, name);
95
CodeCoverageMethod SetterMethod {
96
get { return FirstModuleFirstMethod; }
100
public void MethodIsProperty_SetterMethod_ReturnsTrue()
102
bool result = SetterMethod.IsProperty;
103
Assert.IsTrue(result);
107
public void MethodName_OrdinaryMethod_ReturnsMethodName()
109
string name = OrdinaryMethod.Name;
110
string expectedName = "get_NotAProperty";
111
Assert.AreEqual(expectedName, name);
114
CodeCoverageMethod OrdinaryMethod {
115
get { return FirstModule.Methods[2]; }
119
public void MethodIsProperty_OrdinaryMethod_ReturnsFalse()
121
bool result = OrdinaryMethod.IsProperty;
122
Assert.IsFalse(result);
126
/// Only methods with get_ or set_ as the start of the name are marked as properties.
129
public void MethodIsProperty_MethodWithPropertyFlagButInvalidName_IsNotMarkedAsProperty()
131
bool result = MethodWithPropertyFlagsButInvalidName.IsProperty;
132
Assert.IsFalse(result);