|
| 1 | +using FineCodeCoverage.Engine.Model; |
| 2 | +using NUnit.Framework; |
| 3 | +using System.IO; |
| 4 | + |
| 5 | +namespace FineCodeCoverageTests |
| 6 | +{ |
| 7 | + public class CoverageProject_Tests |
| 8 | + { |
| 9 | + private string tempProjectFilePath; |
| 10 | + private CoverageProject coverageProject; |
| 11 | + |
| 12 | + [SetUp] |
| 13 | + public void SetUp() |
| 14 | + { |
| 15 | + coverageProject = new CoverageProject(null, null, null, null, null, false); |
| 16 | + tempProjectFilePath = Path.Combine(Path.GetTempPath(), "testproject.csproj"); |
| 17 | + coverageProject.ProjectFile = tempProjectFilePath; |
| 18 | + } |
| 19 | + |
| 20 | + [Test] |
| 21 | + public void Should_Be_An_Sdk_Project_When_Project_Element_Has_Sdk_Attribute() |
| 22 | + { |
| 23 | + Test(@"<Project Sdk=""My.Custom.Sdk/1.2.3""/>", true); |
| 24 | + } |
| 25 | + |
| 26 | + [Test] |
| 27 | + public void Should_Be_An_Sdk_Project_When_Project_Element_Has_Child_Sdk_Element() |
| 28 | + { |
| 29 | + Test(@"<Project> |
| 30 | +<Sdk Name=""My.Custom.Sdk"" Version=""1.2.3"" /> |
| 31 | +</Project> |
| 32 | +", true); |
| 33 | + } |
| 34 | + |
| 35 | + [Test] |
| 36 | + public void Should_be_An_Sdk_Project_When_Project_Element_Has_Child_Import_With_Sdk_Attribute() |
| 37 | + { |
| 38 | + Test(@"<Project> |
| 39 | + <PropertyGroup> |
| 40 | + <MyProperty>Value</MyProperty> |
| 41 | + </PropertyGroup> |
| 42 | + <Import Project=""Sdk.props"" Sdk=""My.Custom.Sdk"" /> |
| 43 | + </Project> |
| 44 | +", true); |
| 45 | + } |
| 46 | + |
| 47 | + [Test] |
| 48 | + public void Should_Not_Be_An_Sdk_Project_When_Is_Not() |
| 49 | + { |
| 50 | + Test(@"<Project ToolsVersion=""15.0"" DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> |
| 51 | + <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')"" /> |
| 52 | + <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')"" /> |
| 53 | + <Import Project=""$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"" Condition=""Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"" /> |
| 54 | + <PropertyGroup> |
| 55 | + <Configuration Condition="" '$(Configuration)' == '' "">Debug</Configuration> |
| 56 | + <Platform Condition="" '$(Platform)' == '' "">AnyCPU</Platform> |
| 57 | + <ProjectGuid>{F4B73E7F-F91D-4C95-A3CE-B8DA3A94BB90}</ProjectGuid> |
| 58 | + <OutputType>Library</OutputType> |
| 59 | + <AppDesignerFolder>Properties</AppDesignerFolder> |
| 60 | + <RootNamespace>NetFrameworkUnitTest</RootNamespace> |
| 61 | + <AssemblyName>NetFrameworkUnitTest</AssemblyName> |
| 62 | + <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> |
| 63 | + <FileAlignment>512</FileAlignment> |
| 64 | + <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> |
| 65 | + <VisualStudioVersion Condition=""'$(VisualStudioVersion)' == ''"">15.0</VisualStudioVersion> |
| 66 | + <VSToolsPath Condition=""'$(VSToolsPath)' == ''"">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> |
| 67 | + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath> |
| 68 | + <IsCodedUITest>False</IsCodedUITest> |
| 69 | + <TestProjectType>UnitTest</TestProjectType> |
| 70 | + <NuGetPackageImportStamp> |
| 71 | + </NuGetPackageImportStamp> |
| 72 | + <RunSettingsFilePath> |
| 73 | + </RunSettingsFilePath> |
| 74 | + </PropertyGroup> |
| 75 | + <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ""> |
| 76 | + <DebugSymbols>true</DebugSymbols> |
| 77 | + <DebugType>full</DebugType> |
| 78 | + <Optimize>false</Optimize> |
| 79 | + <OutputPath>bin\Debug\</OutputPath> |
| 80 | + <DefineConstants>DEBUG;TRACE</DefineConstants> |
| 81 | + <ErrorReport>prompt</ErrorReport> |
| 82 | + <WarningLevel>4</WarningLevel> |
| 83 | + </PropertyGroup> |
| 84 | + <PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ""> |
| 85 | + <DebugType>pdbonly</DebugType> |
| 86 | + <Optimize>true</Optimize> |
| 87 | + <OutputPath>bin\Release\</OutputPath> |
| 88 | + <DefineConstants>TRACE</DefineConstants> |
| 89 | + <ErrorReport>prompt</ErrorReport> |
| 90 | + <WarningLevel>4</WarningLevel> |
| 91 | + </PropertyGroup> |
| 92 | + <ItemGroup> |
| 93 | + <Reference Include=""Microsoft.VisualStudio.CodeCoverage.Shim, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL""> |
| 94 | + <HintPath>..\packages\Microsoft.CodeCoverage.17.12.0\lib\net462\Microsoft.VisualStudio.CodeCoverage.Shim.dll</HintPath> |
| 95 | + </Reference> |
| 96 | + <Reference Include=""Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL""> |
| 97 | + <HintPath>..\packages\MSTest.TestFramework.2.2.10\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath> |
| 98 | + </Reference> |
| 99 | + <Reference Include=""Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL""> |
| 100 | + <HintPath>..\packages\MSTest.TestFramework.2.2.10\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath> |
| 101 | + </Reference> |
| 102 | + <Reference Include=""System"" /> |
| 103 | + <Reference Include=""System.Core"" /> |
| 104 | + </ItemGroup> |
| 105 | + <ItemGroup> |
| 106 | + <Compile Include=""UnitTest1.cs"" /> |
| 107 | + <Compile Include=""Properties\AssemblyInfo.cs"" /> |
| 108 | + </ItemGroup> |
| 109 | + <ItemGroup> |
| 110 | + <None Include=""packages.config"" /> |
| 111 | + </ItemGroup> |
| 112 | + <ItemGroup> |
| 113 | + <ProjectReference Include=""..\DemoOpenCover\DemoOpenCover.csproj""> |
| 114 | + <Project>{9ef61906-87e7-42ac-b977-058fc55f74d8}</Project> |
| 115 | + <Name>DemoOpenCover</Name> |
| 116 | + </ProjectReference> |
| 117 | + <ProjectReference Include=""..\Exclude\Exclude.csproj""> |
| 118 | + <Project>{fa82235f-9590-410b-9840-daa224abb17e}</Project> |
| 119 | + <Name>Exclude</Name> |
| 120 | + </ProjectReference> |
| 121 | + </ItemGroup> |
| 122 | + <Import Project=""$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets"" Condition=""Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')"" /> |
| 123 | + <Import Project=""$(MSBuildToolsPath)\Microsoft.CSharp.targets"" /> |
| 124 | + <Target Name=""EnsureNuGetPackageBuildImports"" BeforeTargets=""PrepareForBuild""> |
| 125 | + <PropertyGroup> |
| 126 | + <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> |
| 127 | + </PropertyGroup> |
| 128 | + <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'))"" /> |
| 129 | + <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'))"" /> |
| 130 | + <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'))"" /> |
| 131 | + <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'))"" /> |
| 132 | + </Target> |
| 133 | + <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')"" /> |
| 134 | + <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')"" /> |
| 135 | +</Project>", false); |
| 136 | + } |
| 137 | + |
| 138 | + private void Test(string project, bool expectedIsSdkStyle) |
| 139 | + { |
| 140 | + var xmlDeclaration = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"; |
| 141 | + File.WriteAllText(tempProjectFilePath, $"{xmlDeclaration}{project}"); |
| 142 | + Assert.That(coverageProject.IsDotNetSdkStyle(), Is.EqualTo(expectedIsSdkStyle)); |
| 143 | + } |
| 144 | + |
| 145 | + [TearDown] |
| 146 | + public void Delete_ProjectFile() |
| 147 | + { |
| 148 | + File.Delete(tempProjectFilePath); |
| 149 | + } |
| 150 | + } |
| 151 | + |
| 152 | +} |
0 commit comments