-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
179 additions
and
114 deletions.
There are no files selected for viewing
42 changes: 19 additions & 23 deletions
42
test/Passingwind.Abp.ElsaModule.ElsaExtensionsTests/CSharp/NuGetPackageService_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,79 @@ | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Passingwind.CSharpScriptEngine; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace Passingwind.Abp.ElsaModule.CSharp; | ||
|
||
public class NuGetPackageService_Tests : ElsaModuleExtensionTestBase | ||
public class NuGetPackageServiceTests : ElsaModuleExtensionTestBase | ||
{ | ||
private readonly INuGetPackageService _service; | ||
|
||
public NuGetPackageService_Tests() | ||
public NuGetPackageServiceTests() | ||
{ | ||
_service = GetRequiredService<INuGetPackageService>(); | ||
} | ||
|
||
[Fact] | ||
public async Task GetReferencesAsyncTest_01() | ||
public async Task GetReferencesAsyncTest01() | ||
{ | ||
var files = await _service.GetReferencesAsync("Newtonsoft.Json", "13.0.2", "net6.0", false, false); | ||
var files = await _service.GetReferencesAsync("Newtonsoft.Json", "13.0.2", "net6.0", false); | ||
|
||
files.ShouldNotBeEmpty(); | ||
files.Count().ShouldBe(1); | ||
files.Count.ShouldBe(1); | ||
} | ||
|
||
[Fact] | ||
public async Task GetReferencesAsyncTest_02() | ||
public async Task GetReferencesAsyncTest02() | ||
{ | ||
var files = await _service.GetReferencesAsync("System.Text.Json", "7.0.2", "net6.0", true, false); | ||
var files = await _service.GetReferencesAsync("System.Text.Json", "7.0.2", "net6.0", true); | ||
|
||
files.ShouldNotBeEmpty(); | ||
files.Count().ShouldBe(3); | ||
files.Count.ShouldBe(3); | ||
} | ||
|
||
[Fact] | ||
public async Task GetReferencesAsyncTest_03() | ||
public async Task GetReferencesAsyncTest03() | ||
{ | ||
var files = await _service.GetReferencesAsync("Newtonsoft.Json", "13.0.2", "net6.0", false, true); | ||
var files = await _service.GetReferencesAsync("Newtonsoft.Json", "13.0.2", "net6.0", false); | ||
|
||
files.ShouldNotBeEmpty(); | ||
|
||
files.ShouldAllBe(x => File.Exists(x)); | ||
} | ||
|
||
[Fact] | ||
public async Task GetReferencesAsyncTest_04() | ||
public async Task GetReferencesAsyncTest04() | ||
{ | ||
var files = await _service.GetReferencesAsync("MongoDB.Driver", "2.19.0", "net6.0", resolveDependency: true, downloadPackage: true); | ||
var files = await _service.GetReferencesAsync("MongoDB.Driver", "2.19.0", "net6.0", true); | ||
|
||
files.ShouldNotBeEmpty(); | ||
|
||
files.ShouldAllBe(x => File.Exists(x)); | ||
} | ||
|
||
[Fact] | ||
public async Task DownloadAsyncTest_01() | ||
public async Task DownloadAsyncTest01() | ||
{ | ||
await _service.DownloadAsync("Newtonsoft.Json", "13.0.2", "net6.0"); | ||
} | ||
|
||
[Fact] | ||
public async Task DownloadAsyncTest_02() | ||
{ | ||
await _service.DownloadAsync("System.Text.Json", "7.0.2", "net6.0", true); | ||
await _service.DownloadAsync("Newtonsoft.Json", "13.0.2"); | ||
await _service.DownloadAsync("System.Text.Json", "7.0.2"); | ||
} | ||
|
||
[Fact] | ||
public async Task SearchAsyncTest() | ||
{ | ||
var packages = await _service.SearchAsync("json"); | ||
|
||
packages.Count().ShouldBe(10); | ||
packages.Count.ShouldBeGreaterThan(0); | ||
} | ||
|
||
[Fact] | ||
public async Task GetPackageVersionsAsyncTest() | ||
{ | ||
var version = await _service.GetPackageVersionsAsync("Newtonsoft.Json"); | ||
var version = await _service.GetVersionsAsync("Newtonsoft.Json"); | ||
|
||
version.Count().ShouldBeGreaterThan(0); | ||
version.Count.ShouldBeGreaterThan(0); | ||
} | ||
} |
153 changes: 153 additions & 0 deletions
153
test/Passingwind.Abp.ElsaModule.ElsaExtensionsTests/CSharpScriptHostTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using NSubstitute; | ||
using Passingwind.CSharpScriptEngine; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace Passingwind.Abp.ElsaModule; | ||
|
||
public class CSharpScriptHostTests : ElsaModuleExtensionTestBase | ||
{ | ||
private readonly ICSharpScriptHost _cSharpScriptHost; | ||
|
||
public CSharpScriptHostTests() | ||
{ | ||
_cSharpScriptHost = GetRequiredService<ICSharpScriptHost>(); | ||
} | ||
|
||
[Fact] | ||
public async Task CompileTest1() | ||
{ | ||
const string code = @"using System; | ||
Console.WriteLine(""Hello, World!"");" | ||
; | ||
var result = await _cSharpScriptHost.CompileAsync(new CSharpScriptCompileContext(code)); | ||
|
||
result.Success.ShouldBeTrue(); | ||
} | ||
|
||
[Fact] | ||
public async Task CompileTest2() | ||
{ | ||
const string code = @" | ||
Console.WriteLine(""Hello, World!"");" | ||
; | ||
var result = await _cSharpScriptHost.CompileAsync(new CSharpScriptCompileContext(code)); | ||
|
||
result.Success.ShouldBeFalse(); | ||
} | ||
|
||
[Fact] | ||
public async Task CompileTest3() | ||
{ | ||
const string code = @" | ||
#r ""nuget: Newtonsoft.Json, 13.0.3"" | ||
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(new { a = 1 })); | ||
" | ||
; | ||
var result = await _cSharpScriptHost.CompileAsync(new CSharpScriptCompileContext(code)); | ||
|
||
result.Success.ShouldBeTrue(); | ||
} | ||
|
||
[Fact] | ||
public async Task CompileTest4() | ||
{ | ||
const string code = @" | ||
#r ""System.Private.Uri"" | ||
using System.IO; | ||
using System.Net; | ||
var url = ""https://download.microsoft.com/download/4/C/8/4C830C0C-101F-4BF2-8FCB-32D9A8BA906A/Import_User_Sample_en.csv""; | ||
var request = WebRequest.Create(url); | ||
var response = request.GetResponse(); | ||
var dataStream = response.GetResponseStream(); | ||
var reader = new StreamReader(dataStream); | ||
var csv = await reader.ReadToEndAsync(); | ||
reader.Close(); | ||
dataStream.Close(); | ||
response.Close(); | ||
var users = csv.Split('\n').Skip(1) | ||
.Select(line => line.Split(',')) | ||
.Where(values => values.Length == 15) | ||
.Select(values => new { | ||
firstName = values[1], | ||
lastName = values[2], | ||
officeNumber = int.Parse(values[6]) | ||
}); | ||
foreach (var u in users) | ||
Console.WriteLine(u); | ||
" | ||
; | ||
var result = await _cSharpScriptHost.CompileAsync(new CSharpScriptCompileContext(code)); | ||
|
||
result.Success.ShouldBeTrue(); | ||
} | ||
|
||
[Fact] | ||
public async Task RunTest1() | ||
{ | ||
const string code = @" | ||
#r ""System.Private.Uri"" | ||
using System.IO; | ||
using System.Net; | ||
var url = ""https://download.microsoft.com/download/4/C/8/4C830C0C-101F-4BF2-8FCB-32D9A8BA906A/Import_User_Sample_en.csv""; | ||
var request = WebRequest.Create(url); | ||
var response = request.GetResponse(); | ||
var dataStream = response.GetResponseStream(); | ||
var reader = new StreamReader(dataStream); | ||
var csv = await reader.ReadToEndAsync(); | ||
reader.Close(); | ||
dataStream.Close(); | ||
response.Close(); | ||
var users = csv.Split('\n').Skip(1) | ||
.Select(line => line.Split(',')) | ||
.Where(values => values.Length == 15) | ||
.Select(values => new { | ||
firstName = values[1], | ||
lastName = values[2], | ||
officeNumber = int.Parse(values[6]) | ||
}); | ||
foreach (var u in users) | ||
Console.WriteLine(u); | ||
" | ||
; | ||
var _ = await _cSharpScriptHost.RunAsync(new CSharpScriptCompileContext(code)); | ||
} | ||
|
||
[Fact] | ||
public async Task RunTest2() | ||
{ | ||
const string code = @" | ||
#r ""nuget: Newtonsoft.Json, 13.0.3"" | ||
return Newtonsoft.Json.JsonConvert.SerializeObject(new { a = 1 }); | ||
" | ||
; | ||
var result = await _cSharpScriptHost.RunAsync(new CSharpScriptCompileContext(code)); | ||
|
||
result.GetType().ShouldBe(typeof(string)); | ||
} | ||
|
||
[Fact] | ||
public async Task RunTest3() | ||
{ | ||
const string code = @" | ||
return 1; | ||
" | ||
; | ||
var result = await _cSharpScriptHost.RunAsync(new CSharpScriptCompileContext(code)); | ||
|
||
result.GetType().ShouldBe(typeof(int)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 0 additions & 90 deletions
90
test/Passingwind.Abp.ElsaModule.ElsaExtensionsTests/Roslyn/RoslynHost_Test.cs
This file was deleted.
Oops, something went wrong.