Skip to content

Commit 1ec68a5

Browse files
authored
Add e2e tests (#45)
1 parent e87db40 commit 1ec68a5

File tree

10 files changed

+505
-3
lines changed

10 files changed

+505
-3
lines changed
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
// Copyright (c) Jeff Kluge. All rights reserved.
2+
//
3+
// Licensed under the MIT license.
4+
5+
using log4net;
6+
using log4net.Core;
7+
using System;
8+
using System.Collections.Generic;
9+
using System.Diagnostics;
10+
using System.IO;
11+
using System.Text.RegularExpressions;
12+
using System.Threading;
13+
using Xunit;
14+
using Xunit.Abstractions;
15+
16+
namespace PackagesConfigConverter.UnitTests
17+
{
18+
public class E2ETests : TestBase
19+
{
20+
private const string BaseTestCaseDir = @"TestData\E2ETests";
21+
private const string BaseWorkingDir = @"_work";
22+
private const string NuGetConfigFile = "NuGet.config";
23+
private const string PackagesConfigFileName = "packages.config";
24+
private const string BeforeProjectName = "before.csproj";
25+
private const string AfterProjectName = "after.csproj";
26+
27+
private static readonly Regex ConverterInclude = new Regex($"{BeforeProjectName}$", RegexOptions.Compiled);
28+
29+
public E2ETests(ITestOutputHelper testOutputHelper)
30+
: base(testOutputHelper)
31+
{
32+
}
33+
34+
public static IEnumerable<object[]> TestCases()
35+
{
36+
foreach (string dir in Directory.EnumerateDirectories(BaseTestCaseDir))
37+
{
38+
string testCase = Path.GetFileName(dir);
39+
yield return new object[] { testCase };
40+
}
41+
}
42+
43+
[Theory]
44+
[MemberData(nameof(TestCases))]
45+
public void E2ETest(string testCase)
46+
{
47+
// Copy test files to a working dir
48+
string testCaseDir = Path.Combine(BaseTestCaseDir, testCase);
49+
string workingDir = Path.Combine(BaseWorkingDir, testCase);
50+
51+
if (Directory.Exists(workingDir))
52+
{
53+
Directory.Delete(workingDir, recursive: true);
54+
}
55+
56+
Directory.CreateDirectory(workingDir);
57+
foreach (string file in Directory.EnumerateFiles(testCaseDir, "*", SearchOption.AllDirectories))
58+
{
59+
string relativePath = file.Substring(testCaseDir.Length + 1);
60+
string destintion = Path.Combine(workingDir, relativePath);
61+
File.Copy(file, destintion);
62+
}
63+
64+
File.Copy(Path.Combine(BaseTestCaseDir, NuGetConfigFile), Path.Combine(workingDir, NuGetConfigFile));
65+
66+
string packagesConfigFile = Path.Combine(workingDir, PackagesConfigFileName);
67+
Assert.True(File.Exists(packagesConfigFile));
68+
69+
// Restore the project
70+
var process = new Process()
71+
{
72+
StartInfo = new ProcessStartInfo()
73+
{
74+
FileName = "nuget.exe",
75+
Arguments = "restore",
76+
WorkingDirectory = workingDir,
77+
UseShellExecute = false,
78+
CreateNoWindow = true,
79+
RedirectStandardOutput = true,
80+
RedirectStandardError = true,
81+
},
82+
EnableRaisingEvents = true,
83+
};
84+
85+
process.OutputDataReceived += (sender, eventArgs) =>
86+
{
87+
if (eventArgs.Data != null)
88+
{
89+
TestOutputHelper.WriteLine(eventArgs.Data);
90+
}
91+
};
92+
93+
process.ErrorDataReceived += (sender, eventArgs) =>
94+
{
95+
if (eventArgs.Data != null)
96+
{
97+
TestOutputHelper.WriteLine(eventArgs.Data);
98+
}
99+
};
100+
101+
process.Start();
102+
process.BeginOutputReadLine();
103+
process.BeginErrorReadLine();
104+
process.WaitForExit();
105+
Assert.Equal(0, process.ExitCode);
106+
107+
// Run the conversion
108+
var converterSettings = new ProjectConverterSettings()
109+
{
110+
Include = ConverterInclude,
111+
Log = new TestLog(TestOutputHelper),
112+
RepositoryRoot = workingDir,
113+
};
114+
var converter = new ProjectConverter(converterSettings);
115+
converter.ConvertRepository(CancellationToken.None);
116+
117+
// File was deleted
118+
Assert.False(File.Exists(packagesConfigFile));
119+
120+
string expectedProjectContent = File.ReadAllText(Path.Combine(testCaseDir, AfterProjectName));
121+
string actualProjectContent = File.ReadAllText(Path.Combine(workingDir, BeforeProjectName));
122+
Assert.Equal(expectedProjectContent, actualProjectContent);
123+
}
124+
125+
private sealed class TestLog : ILog
126+
{
127+
private const string DebugLevel = "Debug";
128+
private const string ErrorLevel = "Error";
129+
private const string FatalLevel = "Fatal";
130+
private const string InfoLevel = "Info";
131+
private const string WarnLevel = "Warn";
132+
133+
private readonly ITestOutputHelper _testOutputHelper;
134+
135+
public TestLog(ITestOutputHelper testOutputHelper)
136+
{
137+
_testOutputHelper = testOutputHelper;
138+
}
139+
140+
public bool IsDebugEnabled => true;
141+
142+
public bool IsInfoEnabled => true;
143+
144+
public bool IsWarnEnabled => true;
145+
146+
public bool IsErrorEnabled => true;
147+
148+
public bool IsFatalEnabled => true;
149+
150+
public ILogger Logger => throw new NotImplementedException();
151+
152+
public void Debug(object message) => Log(DebugLevel, message);
153+
154+
public void Debug(object message, Exception exception) => Log(DebugLevel, message, exception);
155+
156+
public void DebugFormat(string format, params object[] args) => Log(DebugLevel, format, args);
157+
158+
public void DebugFormat(string format, object arg0) => Log(DebugLevel, string.Format(format, arg0));
159+
160+
public void DebugFormat(string format, object arg0, object arg1) => Log(DebugLevel, string.Format(format, arg0, arg1));
161+
162+
public void DebugFormat(string format, object arg0, object arg1, object arg2) => Log(DebugLevel, string.Format(format, arg0, arg2));
163+
164+
public void DebugFormat(IFormatProvider provider, string format, params object[] args) => Log(DebugLevel, string.Format(provider, format, args));
165+
166+
public void Error(object message) => Log(ErrorLevel, message);
167+
168+
public void Error(object message, Exception exception) => Log(ErrorLevel, message, exception);
169+
170+
public void ErrorFormat(string format, params object[] args) => Log(ErrorLevel, format, args);
171+
172+
public void ErrorFormat(string format, object arg0) => Log(ErrorLevel, string.Format(format, arg0));
173+
174+
public void ErrorFormat(string format, object arg0, object arg1) => Log(ErrorLevel, string.Format(format, arg0, arg1));
175+
176+
public void ErrorFormat(string format, object arg0, object arg1, object arg2) => Log(ErrorLevel, string.Format(format, arg0, arg2));
177+
178+
public void ErrorFormat(IFormatProvider provider, string format, params object[] args) => Log(ErrorLevel, string.Format(provider, format, args));
179+
180+
public void Fatal(object message) => Log(FatalLevel, message);
181+
182+
public void Fatal(object message, Exception exception) => Log(FatalLevel, message, exception);
183+
184+
public void FatalFormat(string format, params object[] args) => Log(FatalLevel, format, args);
185+
186+
public void FatalFormat(string format, object arg0) => Log(FatalLevel, string.Format(format, arg0));
187+
188+
public void FatalFormat(string format, object arg0, object arg1) => Log(FatalLevel, string.Format(format, arg0, arg1));
189+
190+
public void FatalFormat(string format, object arg0, object arg1, object arg2) => Log(FatalLevel, string.Format(format, arg0, arg2));
191+
192+
public void FatalFormat(IFormatProvider provider, string format, params object[] args) => Log(FatalLevel, string.Format(provider, format, args));
193+
194+
public void Info(object message) => Log(InfoLevel, message);
195+
196+
public void Info(object message, Exception exception) => Log(InfoLevel, message, exception);
197+
198+
public void InfoFormat(string format, params object[] args) => Log(InfoLevel, format, args);
199+
200+
public void InfoFormat(string format, object arg0) => Log(InfoLevel, string.Format(format, arg0));
201+
202+
public void InfoFormat(string format, object arg0, object arg1) => Log(InfoLevel, string.Format(format, arg0, arg1));
203+
204+
public void InfoFormat(string format, object arg0, object arg1, object arg2) => Log(InfoLevel, string.Format(format, arg0, arg2));
205+
206+
public void InfoFormat(IFormatProvider provider, string format, params object[] args) => Log(InfoLevel, string.Format(provider, format, args));
207+
208+
public void Warn(object message) => Log(WarnLevel, message);
209+
210+
public void Warn(object message, Exception exception) => Log(WarnLevel, message, exception);
211+
212+
public void WarnFormat(string format, params object[] args) => Log(WarnLevel, format, args);
213+
214+
public void WarnFormat(string format, object arg0) => Log(WarnLevel, string.Format(format, arg0));
215+
216+
public void WarnFormat(string format, object arg0, object arg1) => Log(WarnLevel, string.Format(format, arg0, arg1));
217+
218+
public void WarnFormat(string format, object arg0, object arg1, object arg2) => Log(WarnLevel, string.Format(format, arg0, arg2));
219+
220+
public void WarnFormat(IFormatProvider provider, string format, params object[] args) => Log(WarnLevel, string.Format(provider, format, args));
221+
222+
private void Log(string level, object message) => _testOutputHelper.WriteLine($"[{level}] {message}");
223+
224+
private void Log(string level, object message, Exception exception) => _testOutputHelper.WriteLine($"[{level}] {message}. Exception: {exception}");
225+
226+
private void Log(string level, string format, params object[] args) => _testOutputHelper.WriteLine($"[{level}] {format}", args);
227+
}
228+
}
229+
}

src/PackagesConfigConverter.UnitTests/PackagesConfigConverter.UnitTests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@
1212
<ItemGroup>
1313
<ProjectReference Include="..\PackagesConfigConverter\PackagesConfigConverter.csproj" />
1414
</ItemGroup>
15+
<ItemGroup>
16+
<Content Include="TestData\**">
17+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
18+
</Content>
19+
</ItemGroup>
1520
</Project>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{526743F1-40C3-4E9D-A23B-927EE3FC8583}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>SomeProject</RootNamespace>
11+
<AssemblyName>SomeProject</AssemblyName>
12+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
13+
</PropertyGroup>
14+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
15+
<DebugSymbols>true</DebugSymbols>
16+
<DebugType>full</DebugType>
17+
<Optimize>false</Optimize>
18+
<OutputPath>bin\Debug\</OutputPath>
19+
<DefineConstants>DEBUG;TRACE</DefineConstants>
20+
<ErrorReport>prompt</ErrorReport>
21+
<WarningLevel>4</WarningLevel>
22+
</PropertyGroup>
23+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
24+
<DebugType>pdbonly</DebugType>
25+
<Optimize>true</Optimize>
26+
<OutputPath>bin\Release\</OutputPath>
27+
<DefineConstants>TRACE</DefineConstants>
28+
<ErrorReport>prompt</ErrorReport>
29+
<WarningLevel>4</WarningLevel>
30+
</PropertyGroup>
31+
<ItemGroup>
32+
<Reference Include="System" />
33+
<Reference Include="System.Xml.Linq" />
34+
<Reference Include="System.Data.DataSetExtensions" />
35+
<Reference Include="Microsoft.CSharp" />
36+
<Reference Include="System.Data" />
37+
<Reference Include="System.Xml" />
38+
<Reference Include="WindowsBase" />
39+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" ExcludeAssets="Runtime, Compile" />
40+
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
41+
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" ExcludeAssets="Build" />
42+
</ItemGroup>
43+
<ItemGroup>
44+
<Compile Include="SomeCompile.cs" />
45+
</ItemGroup>
46+
<ItemGroup>
47+
<None Include="app.config" />
48+
</ItemGroup>
49+
<ItemGroup>
50+
<Folder Include="Properties\" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<Content Include="SomeContent.txt" />
54+
</ItemGroup>
55+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
56+
</Project>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\..\..\..\packages\MSTest.TestAdapter.3.1.1\build\net462\MSTest.TestAdapter.props" Condition="Exists('..\..\..\..\packages\MSTest.TestAdapter.3.1.1\build\net462\MSTest.TestAdapter.props')" />
4+
<Import Project="..\..\..\..\packages\Microsoft.NET.Test.Sdk.17.6.0\build\net462\Microsoft.NET.Test.Sdk.props" Condition="Exists('..\..\..\..\packages\Microsoft.NET.Test.Sdk.17.6.0\build\net462\Microsoft.NET.Test.Sdk.props')" />
5+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
6+
<PropertyGroup>
7+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
8+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
9+
<ProjectGuid>{526743F1-40C3-4E9D-A23B-927EE3FC8583}</ProjectGuid>
10+
<OutputType>Library</OutputType>
11+
<AppDesignerFolder>Properties</AppDesignerFolder>
12+
<RootNamespace>SomeProject</RootNamespace>
13+
<AssemblyName>SomeProject</AssemblyName>
14+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
35+
<HintPath>..\packages\MSTest.TestFramework.3.1.1\lib\net462\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
36+
</Reference>
37+
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
38+
<HintPath>..\packages\MSTest.TestFramework.3.1.1\lib\net462\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
39+
</Reference>
40+
<Reference Include="System" />
41+
<Reference Include="System.Xml.Linq" />
42+
<Reference Include="System.Data.DataSetExtensions" />
43+
<Reference Include="Microsoft.CSharp" />
44+
<Reference Include="System.Data" />
45+
<Reference Include="System.Xml" />
46+
<Reference Include="WindowsBase" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<Compile Include="SomeCompile.cs" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<None Include="app.config" />
53+
<None Include="packages.config" />
54+
</ItemGroup>
55+
<ItemGroup>
56+
<Folder Include="Properties\" />
57+
</ItemGroup>
58+
<ItemGroup>
59+
<Content Include="SomeContent.txt" />
60+
</ItemGroup>
61+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
62+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
63+
<PropertyGroup>
64+
<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>
65+
</PropertyGroup>
66+
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.NET.Test.Sdk.17.6.0\build\net462\Microsoft.NET.Test.Sdk.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.NET.Test.Sdk.17.6.0\build\net462\Microsoft.NET.Test.Sdk.props'))" />
67+
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.NET.Test.Sdk.17.6.0\build\net462\Microsoft.NET.Test.Sdk.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.NET.Test.Sdk.17.6.0\build\net462\Microsoft.NET.Test.Sdk.targets'))" />
68+
<Error Condition="!Exists('..\..\..\..\packages\MSTest.TestAdapter.3.1.1\build\net462\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\MSTest.TestAdapter.3.1.1\build\net462\MSTest.TestAdapter.props'))" />
69+
<Error Condition="!Exists('..\..\..\..\packages\MSTest.TestAdapter.3.1.1\build\net462\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\MSTest.TestAdapter.3.1.1\build\net462\MSTest.TestAdapter.targets'))" />
70+
</Target>
71+
<Import Project="..\..\..\..\packages\Microsoft.NET.Test.Sdk.17.6.0\build\net462\Microsoft.NET.Test.Sdk.targets" Condition="Exists('..\..\..\..\packages\Microsoft.NET.Test.Sdk.17.6.0\build\net462\Microsoft.NET.Test.Sdk.targets')" />
72+
<Import Project="..\..\..\..\packages\MSTest.TestAdapter.3.1.1\build\net462\MSTest.TestAdapter.targets" Condition="Exists('..\..\..\..\packages\MSTest.TestAdapter.3.1.1\build\net462\MSTest.TestAdapter.targets')" />
73+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Microsoft.NET.Test.Sdk" version="17.6.0" targetFramework="net462" />
4+
<package id="MSTest.TestAdapter" version="3.1.1" targetFramework="net462" />
5+
<package id="MSTest.TestFramework" version="3.1.1" targetFramework="net462" />
6+
</packages>

0 commit comments

Comments
 (0)