Skip to content

Commit ec14256

Browse files
committed
✅ fix tests
1 parent fa8488b commit ec14256

File tree

5 files changed

+179
-114
lines changed

5 files changed

+179
-114
lines changed
Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,79 @@
11
using System.IO;
22
using System.Linq;
33
using System.Threading.Tasks;
4+
using Passingwind.CSharpScriptEngine;
45
using Shouldly;
56
using Xunit;
67

78
namespace Passingwind.Abp.ElsaModule.CSharp;
89

9-
public class NuGetPackageService_Tests : ElsaModuleExtensionTestBase
10+
public class NuGetPackageServiceTests : ElsaModuleExtensionTestBase
1011
{
1112
private readonly INuGetPackageService _service;
1213

13-
public NuGetPackageService_Tests()
14+
public NuGetPackageServiceTests()
1415
{
1516
_service = GetRequiredService<INuGetPackageService>();
1617
}
1718

1819
[Fact]
19-
public async Task GetReferencesAsyncTest_01()
20+
public async Task GetReferencesAsyncTest01()
2021
{
21-
var files = await _service.GetReferencesAsync("Newtonsoft.Json", "13.0.2", "net6.0", false, false);
22+
var files = await _service.GetReferencesAsync("Newtonsoft.Json", "13.0.2", "net6.0", false);
2223

2324
files.ShouldNotBeEmpty();
24-
files.Count().ShouldBe(1);
25+
files.Count.ShouldBe(1);
2526
}
2627

2728
[Fact]
28-
public async Task GetReferencesAsyncTest_02()
29+
public async Task GetReferencesAsyncTest02()
2930
{
30-
var files = await _service.GetReferencesAsync("System.Text.Json", "7.0.2", "net6.0", true, false);
31+
var files = await _service.GetReferencesAsync("System.Text.Json", "7.0.2", "net6.0", true);
3132

3233
files.ShouldNotBeEmpty();
33-
files.Count().ShouldBe(3);
34+
files.Count.ShouldBe(3);
3435
}
3536

3637
[Fact]
37-
public async Task GetReferencesAsyncTest_03()
38+
public async Task GetReferencesAsyncTest03()
3839
{
39-
var files = await _service.GetReferencesAsync("Newtonsoft.Json", "13.0.2", "net6.0", false, true);
40+
var files = await _service.GetReferencesAsync("Newtonsoft.Json", "13.0.2", "net6.0", false);
4041

4142
files.ShouldNotBeEmpty();
4243

4344
files.ShouldAllBe(x => File.Exists(x));
4445
}
4546

4647
[Fact]
47-
public async Task GetReferencesAsyncTest_04()
48+
public async Task GetReferencesAsyncTest04()
4849
{
49-
var files = await _service.GetReferencesAsync("MongoDB.Driver", "2.19.0", "net6.0", resolveDependency: true, downloadPackage: true);
50+
var files = await _service.GetReferencesAsync("MongoDB.Driver", "2.19.0", "net6.0", true);
5051

5152
files.ShouldNotBeEmpty();
5253

5354
files.ShouldAllBe(x => File.Exists(x));
5455
}
5556

5657
[Fact]
57-
public async Task DownloadAsyncTest_01()
58+
public async Task DownloadAsyncTest01()
5859
{
59-
await _service.DownloadAsync("Newtonsoft.Json", "13.0.2", "net6.0");
60-
}
61-
62-
[Fact]
63-
public async Task DownloadAsyncTest_02()
64-
{
65-
await _service.DownloadAsync("System.Text.Json", "7.0.2", "net6.0", true);
60+
await _service.DownloadAsync("Newtonsoft.Json", "13.0.2");
61+
await _service.DownloadAsync("System.Text.Json", "7.0.2");
6662
}
6763

6864
[Fact]
6965
public async Task SearchAsyncTest()
7066
{
7167
var packages = await _service.SearchAsync("json");
7268

73-
packages.Count().ShouldBe(10);
69+
packages.Count.ShouldBeGreaterThan(0);
7470
}
7571

7672
[Fact]
7773
public async Task GetPackageVersionsAsyncTest()
7874
{
79-
var version = await _service.GetPackageVersionsAsync("Newtonsoft.Json");
75+
var version = await _service.GetVersionsAsync("Newtonsoft.Json");
8076

81-
version.Count().ShouldBeGreaterThan(0);
77+
version.Count.ShouldBeGreaterThan(0);
8278
}
8379
}
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using NSubstitute;
4+
using Passingwind.CSharpScriptEngine;
5+
using Shouldly;
6+
using Xunit;
7+
8+
namespace Passingwind.Abp.ElsaModule;
9+
10+
public class CSharpScriptHostTests : ElsaModuleExtensionTestBase
11+
{
12+
private readonly ICSharpScriptHost _cSharpScriptHost;
13+
14+
public CSharpScriptHostTests()
15+
{
16+
_cSharpScriptHost = GetRequiredService<ICSharpScriptHost>();
17+
}
18+
19+
[Fact]
20+
public async Task CompileTest1()
21+
{
22+
const string code = @"using System;
23+
24+
Console.WriteLine(""Hello, World!"");"
25+
;
26+
var result = await _cSharpScriptHost.CompileAsync(new CSharpScriptCompileContext(code));
27+
28+
result.Success.ShouldBeTrue();
29+
}
30+
31+
[Fact]
32+
public async Task CompileTest2()
33+
{
34+
const string code = @"
35+
Console.WriteLine(""Hello, World!"");"
36+
;
37+
var result = await _cSharpScriptHost.CompileAsync(new CSharpScriptCompileContext(code));
38+
39+
result.Success.ShouldBeFalse();
40+
}
41+
42+
[Fact]
43+
public async Task CompileTest3()
44+
{
45+
const string code = @"
46+
#r ""nuget: Newtonsoft.Json, 13.0.3""
47+
48+
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(new { a = 1 }));
49+
50+
"
51+
;
52+
var result = await _cSharpScriptHost.CompileAsync(new CSharpScriptCompileContext(code));
53+
54+
result.Success.ShouldBeTrue();
55+
}
56+
57+
[Fact]
58+
public async Task CompileTest4()
59+
{
60+
const string code = @"
61+
#r ""System.Private.Uri""
62+
63+
using System.IO;
64+
using System.Net;
65+
66+
var url = ""https://download.microsoft.com/download/4/C/8/4C830C0C-101F-4BF2-8FCB-32D9A8BA906A/Import_User_Sample_en.csv"";
67+
var request = WebRequest.Create(url);
68+
var response = request.GetResponse();
69+
var dataStream = response.GetResponseStream();
70+
var reader = new StreamReader(dataStream);
71+
var csv = await reader.ReadToEndAsync();
72+
reader.Close();
73+
dataStream.Close();
74+
response.Close();
75+
var users = csv.Split('\n').Skip(1)
76+
.Select(line => line.Split(','))
77+
.Where(values => values.Length == 15)
78+
.Select(values => new {
79+
firstName = values[1],
80+
lastName = values[2],
81+
officeNumber = int.Parse(values[6])
82+
});
83+
84+
foreach (var u in users)
85+
Console.WriteLine(u);
86+
"
87+
;
88+
var result = await _cSharpScriptHost.CompileAsync(new CSharpScriptCompileContext(code));
89+
90+
result.Success.ShouldBeTrue();
91+
}
92+
93+
[Fact]
94+
public async Task RunTest1()
95+
{
96+
const string code = @"
97+
#r ""System.Private.Uri""
98+
99+
using System.IO;
100+
using System.Net;
101+
102+
var url = ""https://download.microsoft.com/download/4/C/8/4C830C0C-101F-4BF2-8FCB-32D9A8BA906A/Import_User_Sample_en.csv"";
103+
var request = WebRequest.Create(url);
104+
var response = request.GetResponse();
105+
var dataStream = response.GetResponseStream();
106+
var reader = new StreamReader(dataStream);
107+
var csv = await reader.ReadToEndAsync();
108+
reader.Close();
109+
dataStream.Close();
110+
response.Close();
111+
var users = csv.Split('\n').Skip(1)
112+
.Select(line => line.Split(','))
113+
.Where(values => values.Length == 15)
114+
.Select(values => new {
115+
firstName = values[1],
116+
lastName = values[2],
117+
officeNumber = int.Parse(values[6])
118+
});
119+
120+
foreach (var u in users)
121+
Console.WriteLine(u);
122+
"
123+
;
124+
var _ = await _cSharpScriptHost.RunAsync(new CSharpScriptCompileContext(code));
125+
}
126+
127+
[Fact]
128+
public async Task RunTest2()
129+
{
130+
const string code = @"
131+
#r ""nuget: Newtonsoft.Json, 13.0.3""
132+
133+
return Newtonsoft.Json.JsonConvert.SerializeObject(new { a = 1 });
134+
135+
"
136+
;
137+
var result = await _cSharpScriptHost.RunAsync(new CSharpScriptCompileContext(code));
138+
139+
result.GetType().ShouldBe(typeof(string));
140+
}
141+
142+
[Fact]
143+
public async Task RunTest3()
144+
{
145+
const string code = @"
146+
return 1;
147+
"
148+
;
149+
var result = await _cSharpScriptHost.RunAsync(new CSharpScriptCompileContext(code));
150+
151+
result.GetType().ShouldBe(typeof(int));
152+
}
153+
}

test/Passingwind.Abp.ElsaModule.ElsaExtensionsTests/ElsaModuleExtensionTestModule.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Text;
55
using System.Threading.Tasks;
6+
using Passingwind.CSharpScriptEngine;
67
using Volo.Abp.Modularity;
78

89
namespace Passingwind.Abp.ElsaModule;
@@ -13,4 +14,8 @@ namespace Passingwind.Abp.ElsaModule;
1314
)]
1415
public class ElsaModuleExtensionTestModule : AbpModule
1516
{
17+
public override void ConfigureServices(ServiceConfigurationContext context)
18+
{
19+
context.Services.AddCSharpScriptEngine();
20+
}
1621
}

test/Passingwind.Abp.ElsaModule.ElsaExtensionsTests/Passingwind.Abp.ElsaModule.ElsaExtensionsTests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
<ItemGroup>
1111
<ProjectReference Include="..\..\src\Passingwind.Abp.ElsaModule.Application\Passingwind.Abp.ElsaModule.Application.csproj" />
12-
<ProjectReference Include="..\..\src\Passingwind.Abp.ElsaModule.ElsaExtensions\Passingwind.Abp.ElsaModule.ElsaExtensions.csproj" />
12+
<ProjectReference Include="..\..\src\Passingwind.Abp.ElsaModule.ElsaExtensions\Passingwind.Abp.ElsaModule.ElsaExtensions.csproj" />
13+
<ProjectReference Include="..\..\src\Passingwind.CSharpScript\Passingwind.CSharpScriptEngine.csproj" />
1314
<ProjectReference Include="..\Passingwind.Abp.ElsaModule.Domain.Tests\Passingwind.Abp.ElsaModule.Domain.Tests.csproj" />
1415
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
1516
</ItemGroup>

test/Passingwind.Abp.ElsaModule.ElsaExtensionsTests/Roslyn/RoslynHost_Test.cs

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)