/// <summary> /// Initializes a new instance of the MobileServiceClient class based /// on an existing instance. /// </summary> /// <param name="service"> /// An existing instance of the MobileServices class to copy. /// </param> private MobileServiceClient(MobileServiceClient service) { Debug.Assert(service != null, "service cannot be null!"); this.ApplicationUri = service.ApplicationUri; this.ApplicationKey = service.ApplicationKey; this.CurrentUser = service.CurrentUser; this.filter = service.filter; this.login = new MobileServiceLogin(this); }
/// <summary> /// Initializes a new instance of the MobileServiceClient class. /// </summary> /// <param name="applicationUri"> /// The Uri to the Mobile Services application. /// </param> /// <param name="applicationKey"> /// The application name for the Mobile Services application. /// </param> public MobileServiceClient(Uri applicationUri, string applicationKey) { if (applicationUri == null) { throw new ArgumentNullException("applicationUri"); } this.ApplicationUri = applicationUri; this.ApplicationKey = applicationKey; this.login = new MobileServiceLogin(this); }
public void SendLoginAsyncThrows() { TestServiceFilter hijack = new TestServiceFilter(); MobileServiceClient client = new MobileServiceClient("http://www.test.com", "secret...").WithFilter(hijack); MobileServiceLogin login = new MobileServiceLogin(client, ignoreFilters: false); // Verify error cases ThrowsAsync<ArgumentNullException>(async () => await login.SendLoginAsync(null)); ThrowsAsync<ArgumentException>(async () => await login.SendLoginAsync("")); // Send back a failure and ensure it throws hijack.Response.Content = new JsonObject().Set("error", "login failed").Stringify(); hijack.Response.StatusCode = 401; ThrowsAsync<InvalidOperationException>(async () => { await login.SendLoginAsync("donkey"); }); }
public async Task SendLoginAsync() { TestServiceFilter hijack = new TestServiceFilter(); MobileServiceClient client = new MobileServiceClient("http://www.test.com", "secret...").WithFilter(hijack); MobileServiceLogin login = new MobileServiceLogin(client, ignoreFilters:false); // Send back a successful login response hijack.Response.Content = new JsonObject() .Set("authenticationToken", "rhubarb") .Set("user", new JsonObject() .Set("userId", "123456")).Stringify(); MobileServiceUser current = await login.SendLoginAsync("donkey"); Assert.IsNotNull(current); Assert.AreEqual("123456", current.UserId); Assert.AreEqual("rhubarb", current.MobileServiceAuthenticationToken); Assert.EndsWith(hijack.Request.Uri.ToString(), "login"); string input = JsonValue.Parse(hijack.Request.Content).Get("authenticationToken").AsString(); Assert.AreEqual("donkey", input); Assert.AreEqual("POST", hijack.Request.Method); Assert.AreSame(current, client.CurrentUser); }