public void GenerateAPIException() { var client = new Client("https://ciapi.cityindex.com/tradingapi", "ciapi.portable"); var t = client.LoginAsync("foo", "bar"); try { t.Wait(); } catch (AggregateException ex) { // TODO: make sure exceptions are constructed consistently so that // end user can easily respond. // probably a good strategy is when we catch and exception in the client, // if it is an aggregate with a single inner, just set exception to the inner, not the aggregate. var flattened = ex.Flatten(); Debugger.Break(); } }
public void CanLoginToCI() { var client = new Client("https://ciapi.cityindex.com/tradingapi", "ciapi.portable"); var loginTask = client.LoginAsync("xx663766", "password1"); // simple block till completion. Async completion can be used by getting the awaiter or setting a .ContinueWith task loginTask.Wait(); // the response dto is available in loginTask.Result if // you want to check passwordchangerequired etc but the client // has already intercepted the response and set it's SessionId // and fetched user's AccountInformation Assert.AreEqual("xx663766", client.Username); Assert.IsNotNullOrEmpty(client.SessionId); Assert.IsNotNull(client.CurrentAccountInformation); var logOutTask = client.LogOutAsync(); logOutTask.Wait(); Assert.IsNull(client.SessionId); Assert.IsNull(client.Username); Assert.IsNull(client.CurrentAccountInformation); }