forked from FortuneN/FineCodeCoverage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoverageProject_Tests.cs
More file actions
152 lines (143 loc) · 8.21 KB
/
CoverageProject_Tests.cs
File metadata and controls
152 lines (143 loc) · 8.21 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
using FineCodeCoverage.Engine.Model;
using NUnit.Framework;
using System.IO;
namespace FineCodeCoverageTests
{
public class CoverageProject_Tests
{
private string tempProjectFilePath;
private CoverageProject coverageProject;
[SetUp]
public void SetUp()
{
coverageProject = new CoverageProject(null, null, null, null, null, false);
tempProjectFilePath = Path.Combine(Path.GetTempPath(), "testproject.csproj");
coverageProject.ProjectFile = tempProjectFilePath;
}
[Test]
public void Should_Be_An_Sdk_Project_When_Project_Element_Has_Sdk_Attribute()
{
Test(@"<Project Sdk=""My.Custom.Sdk/1.2.3""/>", true);
}
[Test]
public void Should_Be_An_Sdk_Project_When_Project_Element_Has_Child_Sdk_Element()
{
Test(@"<Project>
<Sdk Name=""My.Custom.Sdk"" Version=""1.2.3"" />
</Project>
", true);
}
[Test]
public void Should_be_An_Sdk_Project_When_Project_Element_Has_Child_Import_With_Sdk_Attribute()
{
Test(@"<Project>
<PropertyGroup>
<MyProperty>Value</MyProperty>
</PropertyGroup>
<Import Project=""Sdk.props"" Sdk=""My.Custom.Sdk"" />
</Project>
", true);
}
[Test]
public void Should_Not_Be_An_Sdk_Project_When_Is_Not()
{
Test(@"<Project ToolsVersion=""15.0"" DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<Import Project=""..\packages\Microsoft.CodeCoverage.17.12.0\build\netstandard2.0\Microsoft.CodeCoverage.props"" Condition=""Exists('..\packages\Microsoft.CodeCoverage.17.12.0\build\netstandard2.0\Microsoft.CodeCoverage.props')"" />
<Import Project=""..\packages\MSTest.TestAdapter.2.2.10\build\net46\MSTest.TestAdapter.props"" Condition=""Exists('..\packages\MSTest.TestAdapter.2.2.10\build\net46\MSTest.TestAdapter.props')"" />
<Import Project=""$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"" Condition=""Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"" />
<PropertyGroup>
<Configuration Condition="" '$(Configuration)' == '' "">Debug</Configuration>
<Platform Condition="" '$(Platform)' == '' "">AnyCPU</Platform>
<ProjectGuid>{F4B73E7F-F91D-4C95-A3CE-B8DA3A94BB90}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>NetFrameworkUnitTest</RootNamespace>
<AssemblyName>NetFrameworkUnitTest</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition=""'$(VisualStudioVersion)' == ''"">15.0</VisualStudioVersion>
<VSToolsPath Condition=""'$(VSToolsPath)' == ''"">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<RunSettingsFilePath>
</RunSettingsFilePath>
</PropertyGroup>
<PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include=""Microsoft.VisualStudio.CodeCoverage.Shim, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"">
<HintPath>..\packages\Microsoft.CodeCoverage.17.12.0\lib\net462\Microsoft.VisualStudio.CodeCoverage.Shim.dll</HintPath>
</Reference>
<Reference Include=""Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"">
<HintPath>..\packages\MSTest.TestFramework.2.2.10\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include=""Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"">
<HintPath>..\packages\MSTest.TestFramework.2.2.10\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
</Reference>
<Reference Include=""System"" />
<Reference Include=""System.Core"" />
</ItemGroup>
<ItemGroup>
<Compile Include=""UnitTest1.cs"" />
<Compile Include=""Properties\AssemblyInfo.cs"" />
</ItemGroup>
<ItemGroup>
<None Include=""packages.config"" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include=""..\DemoOpenCover\DemoOpenCover.csproj"">
<Project>{9ef61906-87e7-42ac-b977-058fc55f74d8}</Project>
<Name>DemoOpenCover</Name>
</ProjectReference>
<ProjectReference Include=""..\Exclude\Exclude.csproj"">
<Project>{fa82235f-9590-410b-9840-daa224abb17e}</Project>
<Name>Exclude</Name>
</ProjectReference>
</ItemGroup>
<Import Project=""$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets"" Condition=""Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')"" />
<Import Project=""$(MSBuildToolsPath)\Microsoft.CSharp.targets"" />
<Target Name=""EnsureNuGetPackageBuildImports"" BeforeTargets=""PrepareForBuild"">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition=""!Exists('..\packages\MSTest.TestAdapter.2.2.10\build\net46\MSTest.TestAdapter.props')"" Text=""$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.2.2.10\build\net46\MSTest.TestAdapter.props'))"" />
<Error Condition=""!Exists('..\packages\MSTest.TestAdapter.2.2.10\build\net46\MSTest.TestAdapter.targets')"" Text=""$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.2.2.10\build\net46\MSTest.TestAdapter.targets'))"" />
<Error Condition=""!Exists('..\packages\Microsoft.CodeCoverage.17.12.0\build\netstandard2.0\Microsoft.CodeCoverage.props')"" Text=""$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeCoverage.17.12.0\build\netstandard2.0\Microsoft.CodeCoverage.props'))"" />
<Error Condition=""!Exists('..\packages\Microsoft.CodeCoverage.17.12.0\build\netstandard2.0\Microsoft.CodeCoverage.targets')"" Text=""$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeCoverage.17.12.0\build\netstandard2.0\Microsoft.CodeCoverage.targets'))"" />
</Target>
<Import Project=""..\packages\MSTest.TestAdapter.2.2.10\build\net46\MSTest.TestAdapter.targets"" Condition=""Exists('..\packages\MSTest.TestAdapter.2.2.10\build\net46\MSTest.TestAdapter.targets')"" />
<Import Project=""..\packages\Microsoft.CodeCoverage.17.12.0\build\netstandard2.0\Microsoft.CodeCoverage.targets"" Condition=""Exists('..\packages\Microsoft.CodeCoverage.17.12.0\build\netstandard2.0\Microsoft.CodeCoverage.targets')"" />
</Project>", false);
}
private void Test(string project, bool expectedIsSdkStyle)
{
var xmlDeclaration = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
File.WriteAllText(tempProjectFilePath, $"{xmlDeclaration}{project}");
Assert.That(coverageProject.IsDotNetSdkStyle(), Is.EqualTo(expectedIsSdkStyle));
}
[TearDown]
public void Delete_ProjectFile()
{
File.Delete(tempProjectFilePath);
}
}
}