Skip to content

Commit 63ab205

Browse files
committed
Add e2e tests
1 parent e87db40 commit 63ab205

File tree

10 files changed

+514
-3
lines changed

10 files changed

+514
-3
lines changed
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
// Copyright (c) Jeff Kluge. All rights reserved.
2+
//
3+
// Licensed under the MIT license.
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Diagnostics;
8+
using System.IO;
9+
using System.Text.RegularExpressions;
10+
using System.Threading;
11+
using log4net;
12+
using log4net.Core;
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($"{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+
ProcessStartInfo startInfo = new()
71+
{
72+
FileName = "nuget.exe",
73+
Arguments = "restore",
74+
UseShellExecute = false,
75+
CreateNoWindow = true,
76+
RedirectStandardOutput = true,
77+
RedirectStandardError = true,
78+
};
79+
Process process = new Process()
80+
{
81+
StartInfo = new ProcessStartInfo()
82+
{
83+
FileName = "nuget.exe",
84+
Arguments = "restore",
85+
WorkingDirectory = workingDir,
86+
UseShellExecute = false,
87+
CreateNoWindow = true,
88+
RedirectStandardOutput = true,
89+
RedirectStandardError = true,
90+
},
91+
EnableRaisingEvents = true,
92+
};
93+
94+
process.OutputDataReceived += (sender, eventArgs) =>
95+
{
96+
if (eventArgs.Data != null)
97+
{
98+
TestOutputHelper.WriteLine(eventArgs.Data);
99+
}
100+
};
101+
102+
process.ErrorDataReceived += (sender, eventArgs) =>
103+
{
104+
if (eventArgs.Data != null)
105+
{
106+
TestOutputHelper.WriteLine(eventArgs.Data);
107+
}
108+
};
109+
110+
process.Start();
111+
process.BeginOutputReadLine();
112+
process.BeginErrorReadLine();
113+
process.WaitForExit();
114+
Assert.Equal(0, process.ExitCode);
115+
116+
// Run the conversion
117+
ProjectConverterSettings converterSettings = new()
118+
{
119+
Include = ConverterInclude,
120+
Log = new TestLog(TestOutputHelper),
121+
RepositoryRoot = workingDir,
122+
};
123+
ProjectConverter converter = new(converterSettings);
124+
converter.ConvertRepository(CancellationToken.None);
125+
126+
// File was deleted
127+
Assert.False(File.Exists(packagesConfigFile));
128+
129+
string expectedProjectContent = File.ReadAllText(Path.Combine(testCaseDir, AfterProjectName));
130+
string actualProjectContent = File.ReadAllText(Path.Combine(workingDir, BeforeProjectName));
131+
Assert.Equal(expectedProjectContent, actualProjectContent);
132+
}
133+
134+
private sealed class TestLog : ILog
135+
{
136+
private const string DebugLevel = "Debug";
137+
private const string ErrorLevel = "Error";
138+
private const string FatalLevel = "Fatal";
139+
private const string InfoLevel = "Info";
140+
private const string WarnLevel = "Warn";
141+
142+
private readonly ITestOutputHelper _testOutputHelper;
143+
144+
public TestLog(ITestOutputHelper testOutputHelper)
145+
{
146+
_testOutputHelper = testOutputHelper;
147+
}
148+
149+
public bool IsDebugEnabled => true;
150+
151+
public bool IsInfoEnabled => true;
152+
153+
public bool IsWarnEnabled => true;
154+
155+
public bool IsErrorEnabled => true;
156+
157+
public bool IsFatalEnabled => true;
158+
159+
public ILogger Logger => throw new NotImplementedException();
160+
161+
public void Debug(object message) => Log(DebugLevel, message);
162+
163+
public void Debug(object message, Exception exception) => Log(DebugLevel, message, exception);
164+
165+
public void DebugFormat(string format, params object[] args) => Log(DebugLevel, format, args);
166+
167+
public void DebugFormat(string format, object arg0) => Log(DebugLevel, string.Format(format, arg0));
168+
169+
public void DebugFormat(string format, object arg0, object arg1) => Log(DebugLevel, string.Format(format, arg0, arg1));
170+
171+
public void DebugFormat(string format, object arg0, object arg1, object arg2) => Log(DebugLevel, string.Format(format, arg0, arg2));
172+
173+
public void DebugFormat(IFormatProvider provider, string format, params object[] args) => Log(DebugLevel, string.Format(provider, format, args));
174+
175+
public void Error(object message) => Log(ErrorLevel, message);
176+
177+
public void Error(object message, Exception exception) => Log(ErrorLevel, message, exception);
178+
179+
public void ErrorFormat(string format, params object[] args) => Log(ErrorLevel, format, args);
180+
181+
public void ErrorFormat(string format, object arg0) => Log(ErrorLevel, string.Format(format, arg0));
182+
183+
public void ErrorFormat(string format, object arg0, object arg1) => Log(ErrorLevel, string.Format(format, arg0, arg1));
184+
185+
public void ErrorFormat(string format, object arg0, object arg1, object arg2) => Log(ErrorLevel, string.Format(format, arg0, arg2));
186+
187+
public void ErrorFormat(IFormatProvider provider, string format, params object[] args) => Log(ErrorLevel, string.Format(provider, format, args));
188+
189+
public void Fatal(object message) => Log(FatalLevel, message);
190+
191+
public void Fatal(object message, Exception exception) => Log(FatalLevel, message, exception);
192+
193+
public void FatalFormat(string format, params object[] args) => Log(FatalLevel, format, args);
194+
195+
public void FatalFormat(string format, object arg0) => Log(FatalLevel, string.Format(format, arg0));
196+
197+
public void FatalFormat(string format, object arg0, object arg1) => Log(FatalLevel, string.Format(format, arg0, arg1));
198+
199+
public void FatalFormat(string format, object arg0, object arg1, object arg2) => Log(FatalLevel, string.Format(format, arg0, arg2));
200+
201+
public void FatalFormat(IFormatProvider provider, string format, params object[] args) => Log(FatalLevel, string.Format(provider, format, args));
202+
203+
public void Info(object message) => Log(InfoLevel, message);
204+
205+
public void Info(object message, Exception exception) => Log(InfoLevel, message, exception);
206+
207+
public void InfoFormat(string format, params object[] args) => Log(InfoLevel, format, args);
208+
209+
public void InfoFormat(string format, object arg0) => Log(InfoLevel, string.Format(format, arg0));
210+
211+
public void InfoFormat(string format, object arg0, object arg1) => Log(InfoLevel, string.Format(format, arg0, arg1));
212+
213+
public void InfoFormat(string format, object arg0, object arg1, object arg2) => Log(InfoLevel, string.Format(format, arg0, arg2));
214+
215+
public void InfoFormat(IFormatProvider provider, string format, params object[] args) => Log(InfoLevel, string.Format(provider, format, args));
216+
217+
public void Warn(object message) => Log(WarnLevel, message);
218+
219+
public void Warn(object message, Exception exception) => Log(WarnLevel, message, exception);
220+
221+
public void WarnFormat(string format, params object[] args) => Log(WarnLevel, format, args);
222+
223+
public void WarnFormat(string format, object arg0) => Log(WarnLevel, string.Format(format, arg0));
224+
225+
public void WarnFormat(string format, object arg0, object arg1) => Log(WarnLevel, string.Format(format, arg0, arg1));
226+
227+
public void WarnFormat(string format, object arg0, object arg1, object arg2) => Log(WarnLevel, string.Format(format, arg0, arg2));
228+
229+
public void WarnFormat(IFormatProvider provider, string format, params object[] args) => Log(WarnLevel, string.Format(provider, format, args));
230+
231+
private void Log(string level, object message) => _testOutputHelper.WriteLine($"[{level}] {message}");
232+
233+
private void Log(string level, object message, Exception exception) => _testOutputHelper.WriteLine($"[{level}] {message}. Exception: {exception}");
234+
235+
private void Log(string level, string format, params object[] args) => _testOutputHelper.WriteLine($"[{level}] {format}", args);
236+
}
237+
}
238+
}

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)