Skip to content

Commit

Permalink
Convert unit test to SDK style project (#25)
Browse files Browse the repository at this point in the history
* Convert unit test to SDK style project
  • Loading branch information
jeffkl authored May 4, 2018
1 parent fce1943 commit 3126c4a
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 153 deletions.
15 changes: 0 additions & 15 deletions src/SlnGen.Build.Tasks.UnitTests/App.config

This file was deleted.

2 changes: 1 addition & 1 deletion src/SlnGen.Build.Tasks.UnitTests/MockBuildEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace SlnGen.Build.Tasks.UnitTests
{
public class MockBuildEngine : IBuildEngine5
internal class MockBuildEngine : IBuildEngine5
{
private readonly List<BuildEventArgs> _events = new List<BuildEventArgs>();

Expand Down
2 changes: 1 addition & 1 deletion src/SlnGen.Build.Tasks.UnitTests/MockProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace SlnGen.Build.Tasks.UnitTests
{
public static class MockProject
internal static class MockProject
{
public const string MockToolsVersion = "1.0";

Expand Down
2 changes: 1 addition & 1 deletion src/SlnGen.Build.Tasks.UnitTests/MockTaskItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace SlnGen.Build.Tasks.UnitTests
{
public class MockTaskItem : Dictionary<string, string>, ITaskItem
internal class MockTaskItem : Dictionary<string, string>, ITaskItem
{
public MockTaskItem()
: base(StringComparer.OrdinalIgnoreCase)
Expand Down
2 changes: 0 additions & 2 deletions src/SlnGen.Build.Tasks.UnitTests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

using System.Reflection;

[assembly: AssemblyTitle("SlnGen.Build.Tasks.UnitTests")]
[assembly: AssemblyProduct("SlnGen.Build.Tasks.UnitTests")]
[assembly: AssemblyCopyright("Copyright © 2017")]
14 changes: 7 additions & 7 deletions src/SlnGen.Build.Tasks.UnitTests/SlnFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
// Licensed under the MIT license.

using Microsoft.Build.Construction;
using NUnit.Framework;
using Shouldly;
using SlnGen.Build.Tasks.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
using MSBuildSolutionFile = Microsoft.Build.Construction.SolutionFile;

namespace SlnGen.Build.Tasks.UnitTests
{
[TestFixture]
public class SlnFileTests : TestBase
{
// TODO: Test hierarchy
[Test]
[Fact]
public void LotsOfProjects()
{
const int projectCount = 1000;
Expand All @@ -39,7 +39,7 @@ public void LotsOfProjects()
ValidateProjectInSolution(projects);
}

[Test]
[Fact]
public void MultipleProjects()
{
SlnProject projectA = new SlnProject(GetTempFileName(), "ProjectA", Guid.Parse("C95D800E-F016-4167-8E1B-1D3FF94CE2E2"), "88152E7E-47E3-45C8-B5D3-DDB15B2F0435", new[] { "Debug" }, new[] { "x64" }, isMainProject: true);
Expand All @@ -48,7 +48,7 @@ public void MultipleProjects()
ValidateProjectInSolution(projectA, projectB);
}

[Test]
[Fact]
public void SingleProject()
{
SlnProject projectA = new SlnProject(GetTempFileName(), "ProjectA", Guid.Parse("C95D800E-F016-4167-8E1B-1D3FF94CE2E2"), "88152E7E-47E3-45C8-B5D3-DDB15B2F0435", new[] { "Debug" }, new[] { "x64" }, isMainProject: true);
Expand Down Expand Up @@ -76,9 +76,9 @@ private void ValidateProjectInSolution(Action<SlnProject, ProjectInSolution> cus
projectInSolution.ProjectGuid.ShouldBe(slnProject.ProjectGuid.ToSolutionString());
projectInSolution.ProjectName.ShouldBe(slnProject.Name);

var configurationPlatforms = from configuration in slnProject.Configurations from platform in slnProject.Platforms select $"{configuration}|{platform}";
IEnumerable<string> configurationPlatforms = from configuration in slnProject.Configurations from platform in slnProject.Platforms select $"{configuration}|{platform}";

CollectionAssert.AreEquivalent(projectInSolution.ProjectConfigurations.Keys, configurationPlatforms);
configurationPlatforms.ShouldBe(projectInSolution.ProjectConfigurations.Keys, ignoreOrder: true);

customValidator?.Invoke(slnProject, projectInSolution);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,86 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7DBBDCF0-30F5-4455-96DE-BF37D1949CB4}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SlnGen.Build.Tasks.UnitTests</RootNamespace>
<AssemblyName>SlnGen.Build.Tasks.UnitTests</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TestProjectType>UnitTest</TestProjectType>
<TargetFrameworkProfile />
<TargetFramework>net46</TargetFramework>
<IsPackable>false</IsPackable>
</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="$(MSBuildBinPath)\Microsoft.Build.dll">
<Name>Microsoft.Build</Name>
<Private>true</Private>
</Reference>
<Reference Include="$(MSBuildBinPath)\Microsoft.Build.Framework.dll">
<Name>Microsoft.Build.Framework</Name>
<Private>true</Private>
</Reference>
<Reference Include="Microsoft.Build.Utilities.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ExtensionMethods.cs" />
<Compile Include="MockBuildEngine.cs" />
<Compile Include="MockProject.cs" />
<Compile Include="MockTaskItem.cs" />
<Compile Include="SlnFileTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SlnGenTests.cs" />
<Compile Include="SlnProjectTests.cs" />
<Compile Include="TestBase.cs" />
<Compile Include="ToFullPathInCorrectCaseTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SlnGen.Build.Tasks\SlnGen.Build.Tasks.csproj">
<Project>{b21c529b-e539-4a24-b190-db57b1fb4e8c}</Project>
<Name>SlnGen.Build.Tasks</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="NUnit">
<Version>3.9.0</Version>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter">
<Version>3.9.0</Version>
</PackageReference>
<PackageReference Include="Shouldly">
<Version>2.8.3</Version>
</PackageReference>
</ItemGroup>

<ItemGroup>
<None Include="App.config" />
<PackageReference Include="Microsoft.Build" Version="15.6.85" ExcludeAssets="Runtime" />
<PackageReference Include="Microsoft.Build.Framework" Version="15.6.85" ExcludeAssets="Runtime" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.0.13" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="Shouldly" Version="3.0.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />

<ProjectReference Include="..\SlnGen.Build.Tasks\SlnGen.Build.Tasks.csproj" />
</ItemGroup>

<ItemGroup>
<Content Include="TestFiles\SampleProject.csproj">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
11 changes: 5 additions & 6 deletions src/SlnGen.Build.Tasks.UnitTests/SlnGenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
// Licensed under the MIT license.

using Microsoft.Build.Framework;
using NUnit.Framework;
using Shouldly;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Xunit;

namespace SlnGen.Build.Tasks.UnitTests
{
[TestFixture]
public sealed class SlnGenTests : TestBase
{
[Test]
[Fact]
public void ParseCustomProjectTypeGuidsDeduplicatesList()
{
const string expectedProjectTypeGuid = "{C139C737-2894-46A0-B1EB-DDD052FD8DCB}";
Expand All @@ -34,7 +33,7 @@ public void ParseCustomProjectTypeGuidsDeduplicatesList()
ValidateParseCustomProjectTypeGuids(customProjectTypeGuids, ".foo", expectedProjectTypeGuid);
}

[Test]
[Fact]
public void ParseCustomProjectTypeGuidsFormatsFileExtensionAndGuid()
{
ValidateParseCustomProjectTypeGuids(
Expand All @@ -44,7 +43,7 @@ public void ParseCustomProjectTypeGuidsFormatsFileExtensionAndGuid()
"{9D933978-2D2A-4FB2-B72D-8746D88E73B7}");
}

[Test]
[Fact]
public void ParseCustomProjectTypeGuidsIgnoresNonFileExtensions()
{
const string expectedProjectTypeGuid = "{C139C737-2894-46A0-B1EB-DDD052FD8DCB}";
Expand All @@ -64,7 +63,7 @@ public void ParseCustomProjectTypeGuidsIgnoresNonFileExtensions()
ValidateParseCustomProjectTypeGuids(customProjectTypeGuids, ".foo", expectedProjectTypeGuid);
}

[Test]
[Fact]
public void SolutionItems()
{
Dictionary<string, string> solutionItems = new Dictionary<string, string>
Expand Down
Loading

0 comments on commit 3126c4a

Please sign in to comment.