public async Task TestQuery() { var provider = GetMockProvider <PersonResponse>(); var iconService = new IconService(provider.Object); iconService.AddConverterFactory <PersonResponse>(new TestQueryRpcConverterFactory()); var person = new Person { Name = "gold bug", Age = BigInteger.Parse("20"), HasPermission = false }; var call = new Call.Builder() .From(new Address("hxbe258ceb872e08851f1f59694dac2558708ece11")) .To(new Address("cx5bfdb090f43a808005ffc27c25b213145e80b7cd")) .Method("addUser") .Params(person) .BuildWith <PersonResponse>(); // ReSharper disable once UnusedVariable var query = await iconService.CallAsync(call); provider.Verify(x => x.SendRequestAsync(It.Is <Request>(request => TestQueryRequestCheck(request, person)), It.IsAny <IRpcConverter <PersonResponse> >()), Times.Once); }
private void TestCallBuilder() { var from = new Address("hx0000000000000000000000000000000000000000"); var to = new Address("cx1111111111111111111111111111111111111111"); const string method = "myMethod"; var person = new Person { Name = "gold bug", Age = BigInteger.Parse("20") }; var call = new Call.Builder() .From(from) .To(to) .Method(method) .Params(person) .BuildWith <PersonResponse>(); var properties = call.GetProperties(); var data = properties.GetItem("data").ToObject(); var dataParams = data.GetItem("params").ToObject(); Assert.Equal(from, properties.GetItem("from").ToAddress()); Assert.Equal(to, properties.GetItem("to").ToAddress()); Assert.Equal(method, data.GetItem("method").ToString()); Assert.Equal(person.Name, dataParams.GetItem("Name").ToString()); Assert.Equal(person.Age, dataParams.GetItem("Age").ToInteger()); Assert.Equal(typeof(PersonResponse), call.GetResponseType()); }
public async Task TestConverterNotfound() { var provider = GetMockProvider(); var iconService = new IconService(provider.Object); var person = new Person { Name = "gold bug", Age = BigInteger.Parse("20"), HasPermission = false }; var call = new Call.Builder() .From(new Address("hxbe258ceb872e08851f1f59694dac2558708ece11")) .To(new Address("cx5bfdb090f43a808005ffc27c25b213145e80b7cd")) .Method("addUser") .Params(person) .BuildWith <PersonResponse>(); await Assert.ThrowsAsync <ArgumentException>(async() => { await iconService.CallAsync(call); }); }