* CloudTest.cs: chore: 完善云引擎实现和测试
* LCCloud.cs: * LCDecoder.cs: * LCHttpClient.cs:
parent
cbdb4e409e
commit
788f0bf1c3
|
@ -1,32 +0,0 @@
|
||||||
using NUnit.Framework;
|
|
||||||
using LeanCloud;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace LeanCloud.Test {
|
|
||||||
public class CloudFunctionTest {
|
|
||||||
[SetUp]
|
|
||||||
public void SetUp() {
|
|
||||||
Utils.InitNorthChina();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public async Task Hello() {
|
|
||||||
AVClient.UseProduction = true;
|
|
||||||
string result = await AVCloud.CallFunctionAsync<string>("hello", new Dictionary<string, object> {
|
|
||||||
{ "word", "world" }
|
|
||||||
});
|
|
||||||
Assert.AreEqual(result, "hello, world");
|
|
||||||
TestContext.Out.WriteLine($"resutlt: {result}");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public async Task GetUsernameInCloud() {
|
|
||||||
AVClient.UseProduction = true;
|
|
||||||
await AVUser.LogInAsync("111111", "111111");
|
|
||||||
string result = await AVCloud.CallFunctionAsync<string>("getUsername");
|
|
||||||
Assert.AreEqual(result, "111111");
|
|
||||||
TestContext.Out.WriteLine($"resutlt: {result}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
using NUnit.Framework;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Linq;
|
||||||
|
using LeanCloud.Storage;
|
||||||
|
|
||||||
|
namespace LeanCloud.Test {
|
||||||
|
public class CloudTest {
|
||||||
|
[SetUp]
|
||||||
|
public void SetUp() {
|
||||||
|
Logger.LogDelegate += Utils.Print;
|
||||||
|
LeanCloud.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com");
|
||||||
|
}
|
||||||
|
|
||||||
|
[TearDown]
|
||||||
|
public void TearDown() {
|
||||||
|
Logger.LogDelegate -= Utils.Print;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task Call() {
|
||||||
|
Dictionary<string, object> response = await LCCloud.Run("hello", parameters: new Dictionary<string, object> {
|
||||||
|
{ "name", "world" }
|
||||||
|
});
|
||||||
|
TestContext.WriteLine(response["result"]);
|
||||||
|
Assert.AreEqual(response["result"], "hello, world");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task CallWithoutParams() {
|
||||||
|
await LCCloud.Run("hello");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public async Task RPC() {
|
||||||
|
List<object> result = await LCCloud.RPC("getTycoonList") as List<object>;
|
||||||
|
IEnumerable<LCObject> tycoonList = result.Cast<LCObject>();
|
||||||
|
foreach (LCObject item in tycoonList) {
|
||||||
|
TestContext.WriteLine(item.ObjectId);
|
||||||
|
Assert.NotNull(item.ObjectId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -36,6 +36,7 @@ namespace LeanCloud.Storage.Internal.Codec {
|
||||||
object v = Decode(o);
|
object v = Decode(o);
|
||||||
l.Add(v);
|
l.Add(v);
|
||||||
}
|
}
|
||||||
|
return l;
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,13 +89,17 @@ namespace LeanCloud.Storage.Internal.Http {
|
||||||
Dictionary<string, object> headers = null,
|
Dictionary<string, object> headers = null,
|
||||||
Dictionary<string, object> data = null,
|
Dictionary<string, object> data = null,
|
||||||
Dictionary<string, object> queryParams = null) {
|
Dictionary<string, object> queryParams = null) {
|
||||||
string content = (data != null) ? JsonConvert.SerializeObject(data) : null;
|
|
||||||
HttpRequestMessage request = new HttpRequestMessage {
|
HttpRequestMessage request = new HttpRequestMessage {
|
||||||
RequestUri = new Uri($"{server}/{apiVersion}/{path}"),
|
RequestUri = new Uri($"{server}/{apiVersion}/{path}"),
|
||||||
Method = HttpMethod.Post,
|
Method = HttpMethod.Post,
|
||||||
Content = new StringContent(content)
|
|
||||||
};
|
};
|
||||||
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
string content = null;
|
||||||
|
if (data != null) {
|
||||||
|
content = JsonConvert.SerializeObject(data);
|
||||||
|
StringContent requestContent = new StringContent(content);
|
||||||
|
request.Content = requestContent;
|
||||||
|
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
||||||
|
}
|
||||||
HttpUtils.PrintRequest(client, request, content);
|
HttpUtils.PrintRequest(client, request, content);
|
||||||
HttpResponseMessage response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
|
HttpResponseMessage response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
|
||||||
request.Dispose();
|
request.Dispose();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using LeanCloud.Storage.Internal.Codec;
|
||||||
|
|
||||||
namespace LeanCloud.Storage {
|
namespace LeanCloud.Storage {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -18,9 +19,10 @@ namespace LeanCloud.Storage {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<object> RPC(string name, Dictionary<string, object> parameters = null) {
|
public static async Task<object> RPC(string name, Dictionary<string, object> parameters = null) {
|
||||||
string path = $"call/{name}";
|
string path = $"call/{name}";
|
||||||
return null;
|
Dictionary<string, object> response = await LeanCloud.HttpClient.Post<Dictionary<string, object>>(path, data: parameters);
|
||||||
|
return LCDecoder.Decode(response["result"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue