isn/test/isn.tests/PushTest.cs

59 lines
2.2 KiB
C#

1 year ago
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
using isn.Abstract;
using System.Linq;
using Xunit;
using isn.abst;
6 months ago
using System.Security.Cryptography;
1 year ago
namespace isn.tests
{
public class Tests
{
[Fact]
public async Task TestHttpClient()
{
string url = "https://isn.pschneider.fr"+Constants.ApiVersionPrefix+"/index.json" ;
1 year ago
HttpClient client = new HttpClient();
// var json = await client.GetStringAsync(new System.Uri(url));
var response = await client.GetAsync(url);
var json = await response.Content.ReadAsStringAsync();
var vm = JsonConvert.DeserializeObject<ApiIndexViewModel>(json);
Console.WriteLine(JsonConvert.SerializeObject(vm));
Assert.NotNull(vm);
Assert.NotNull(vm.Resources);
}
7 months ago
1 year ago
[Fact]
public void TestPush()
{
Program.LoadConfig();
6 months ago
var report = Program.PushPkg(new string[] { "./src/isn.abst/bin/Debug/isn.abst.1.0.1.nupkg" });
1 year ago
}
[Fact]
public void GetServerResourcesUsingHttpClientAsyncTest()
{
6 months ago
var model = SourceHelpers.GetServerResources("Https://isn.pschneider.fr/v3/index.json");
1 year ago
Console.WriteLine(JsonConvert.SerializeObject(model));
Assert.NotNull(model.Resources);
var pub = model.Resources.FirstOrDefault((r) => r.Type.StartsWith("PackagePublish/"));
Assert.True(pub != null);
}
6 months ago
[Fact]
public void TestSetApiKey()
{
string source = "http://localhost:3002/v3/index.json";
var setting = Settings.Create();
setting.Sources[source] = new SourceSettings{ Url=source };
string testingKey = "CfDJ8LF3SbIJ4FJAgs7uIQKhdCAYCNVXRwU6TEoaXOo1_ZpG2u8TCGFP2z13hw9xR0LC0gdbr1QGwNndiXUl4DI74nxyBi-T1oC33PWtE-5vgiJWeCH223PYtoSEdzDiWovwJZWJbQON0WqoG8vSfbrBXTmicD6oxF4ghwXXexY0RiRR";
var rsa = RSA.Create(setting.RSAParameters);
setting.Sources[source].SetApiKey(rsa,testingKey);
Assert.Equal(testingKey, setting.Sources[source].GetClearApiKey(rsa));
}
1 year ago
}
}