Skip to content

Commit 14d93eb

Browse files
Get references working the same as before in tests at least
less important to have winforms in frontend since it only really works with multiple files
1 parent 6571042 commit 14d93eb

4 files changed

Lines changed: 24 additions & 16 deletions

File tree

CodeConverter/Common/DefaultReferences.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ public static class DefaultReferences
3232
typeof(System.Xml.Linq.XElement),
3333
typeof(System.Linq.Expressions.Expression),
3434
typeof(Microsoft.VisualBasic.Constants),
35-
typeof(System.Data.Common.DbCommand),
36-
typeof(Microsoft.VisualBasic.Devices.Computer),
37-
typeof(System.Windows.Forms.Form)
35+
typeof(System.Data.SqlClient.SqlCommand)
3836
// ReSharper restore RedundantNameQualifier
3937
}.Select(t => t.Assembly).Concat(
4038
new[] { Assembly.Load("System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") }

CommandLine/CodeConv/CodeConv.csproj

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
2020
<Nullable>enable</Nullable>
2121
<EmbedUntrackedSources>$(ContinuousIntegrationBuild)</EmbedUntrackedSources>
22-
<WarningsNotAsErrors>NU1510;NU1903</WarningsNotAsErrors>
2322
</PropertyGroup>
2423

2524
<ItemGroup>
@@ -40,12 +39,6 @@
4039
<PrivateAssets>all</PrivateAssets>
4140
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
4241
</PackageReference>
43-
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
44-
<PackageReference Include="System.Formats.Asn1" Version="8.0.1" />
45-
<PackageReference Include="System.Memory" Version="4.5.5" />
46-
<PackageReference Include="System.Net.Http" Version="4.3.4" />
47-
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
48-
4942
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.0.1" />
5043
</ItemGroup>
5144

Tests/TestRunners/ConverterTestBase.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,27 @@ public ConverterTestBase(string rootNamespace = null)
3636
.WithOptionCompareText(false)
3737
.WithOptionStrict(OptionStrict.Off)
3838
.WithOptionInfer(true);
39-
EmptyNamespaceOptionStrictOff = new TextConversionOptions(DefaultReferences.NetStandard2) {
39+
EmptyNamespaceOptionStrictOff = new TextConversionOptions(References) {
4040
RootNamespaceOverride = string.Empty, TargetCompilationOptionsOverride = options,
4141
ShowCompilationErrors = true
4242
};
43-
VisualBasic11 = new TextConversionOptions(DefaultReferences.NetStandard2) {
43+
VisualBasic11 = new TextConversionOptions(References) {
4444
RootNamespaceOverride = string.Empty,
4545
TargetCompilationOptionsOverride = options.WithParseOptions(new VisualBasicParseOptions(LanguageVersion.VisualBasic11)),
4646
ShowCompilationErrors = true
4747
};
4848
}
4949

50+
private static IReadOnlyCollection<PortableExecutableReference> References { get; } = DefaultReferences.With(
51+
typeof(System.Windows.Forms.Form).Assembly,
52+
typeof(Microsoft.VisualBasic.Devices.Computer).Assembly
53+
);
54+
5055
public async Task TestConversionCSharpToVisualBasicAsync(string csharpCode, string expectedVisualBasicCode, bool expectSurroundingMethodBlock = false, bool expectCompilationErrors = false, TextConversionOptions conversionOptions = null, bool hasLineCommentConversionIssue = false)
5156
{
5257
expectedVisualBasicCode = AddSurroundingMethodBlock(expectedVisualBasicCode, expectSurroundingMethodBlock);
5358

54-
conversionOptions ??= new TextConversionOptions(DefaultReferences.NetStandard2) { ShowCompilationErrors = !expectSurroundingMethodBlock };
59+
conversionOptions ??= new TextConversionOptions(References) { ShowCompilationErrors = !expectSurroundingMethodBlock };
5560
await AssertConvertedCodeResultEqualsAsync<CSToVBConversion>(csharpCode, expectedVisualBasicCode, conversionOptions);
5661
if (_testCstoVbCommentsByDefault && !hasLineCommentConversionIssue) {
5762
await AssertLineCommentsConvertedInSameOrderAsync<CSToVBConversion>(csharpCode, conversionOptions, "//", LineCanHaveCSharpComment);
@@ -109,7 +114,7 @@ public async Task TestConversionVisualBasicToCSharpAsync(string visualBasicCode,
109114
bool incompatibleWithAutomatedCommentTesting = false)
110115
{
111116
if (expectSurroundingBlock) expectedCsharpCode = SurroundWithBlock(expectedCsharpCode);
112-
var conversionOptions = new TextConversionOptions(DefaultReferences.NetStandard2) {
117+
var conversionOptions = new TextConversionOptions(References) {
113118
RootNamespaceOverride = _rootNamespace,
114119
ShowCompilationErrors = !expectSurroundingBlock
115120
};
@@ -143,7 +148,7 @@ private static string SurroundWithBlock(string expectedCsharpCode)
143148

144149
protected async Task<string> ConvertAsync<TLanguageConversion>(string inputCode, TextConversionOptions conversionOptions = default) where TLanguageConversion : ILanguageConversion, new()
145150
{
146-
var textConversionOptions = conversionOptions ?? new TextConversionOptions(DefaultReferences.NetStandard2) { RootNamespaceOverride = _rootNamespace, ShowCompilationErrors = true };
151+
var textConversionOptions = conversionOptions ?? new TextConversionOptions(References) { RootNamespaceOverride = _rootNamespace, ShowCompilationErrors = true };
147152
var conversionResult = await ProjectConversion.ConvertTextAsync<TLanguageConversion>(inputCode, textConversionOptions);
148153
return (conversionResult.ConvertedCode ?? "") + (conversionResult.GetExceptionsAsString() ?? "");
149154
}

Tests/Tests.csproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net10.0</TargetFramework>
3+
<TargetFramework>net10.0-windows</TargetFramework>
44
<OutputType>Library</OutputType>
55
<AssemblyName>ICSharpCode.CodeConverter.Tests</AssemblyName>
66
<RootNamespace>ICSharpCode.CodeConverter.Tests</RootNamespace>
77
<DisableMSBuildAssemblyCopyCheck>true</DisableMSBuildAssemblyCopyCheck>
88
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
99
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
10+
<UseWindowsForms>true</UseWindowsForms>
11+
<WarningsNotAsErrors>NU1510;NU1903</WarningsNotAsErrors>
1012
</PropertyGroup>
1113
<ItemGroup>
1214
<PackageReference Include="Moq" Version="4.20.72" />
@@ -21,6 +23,16 @@
2123
<PrivateAssets>all</PrivateAssets>
2224
</PackageReference>
2325
</ItemGroup>
26+
<ItemGroup>
27+
<!-- So we can reference commonly referenced assemblies in created compilations-->
28+
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
29+
<PackageReference Include="System.Formats.Asn1" Version="8.0.1" />
30+
<PackageReference Include="System.Memory" Version="4.5.5" />
31+
<PackageReference Include="System.Net.Http" Version="4.3.4" />
32+
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
33+
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
34+
<PackageReference Include="Microsoft.VisualBasic" Version="10.3.0" />
35+
</ItemGroup>
2436
<ItemGroup>
2537
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
2638
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />

0 commit comments

Comments
 (0)