/// <summary> /// Sets the configuration asynchronous. /// </summary> /// <param name="serverUri">The server URI.</param> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <returns></returns> public async Task<Tuple<bool, String>> SetConfigurationAsync(Uri serverUri, String username, String password) { if(serverUri == null) { return new Tuple<bool, string>(false, "ServerUri cannot be null"); } if(username == null) { return new Tuple<bool, string>(false, "Username cannot be null"); } if(password == null) { return new Tuple<bool, string>(false, "Password cannot be null"); } settings.ServerUri = serverUri; settings.Username = username; settings.Password = password; var serverContext = new ServerContext(settings); var result = await serverContext.LoginAsync(settings.Username, settings.Password); if (result.Status == LoginStatus.Success) { return new Tuple<bool, string>(true, "Success"); } else { return new Tuple<bool, string>(false, "Error verifying with server"); } }
public async Task LoginAsyncTest() { var sett = new StubIServerSettings(); sett.ServerUri_Get(() => null); var create = new StubICreateHelper(); var serverContext = new ServerContext(sett, create); var result = await serverContext.LoginAsync(null, null); Assert.IsNotNull(result); Assert.AreEqual(LoginStatus.ServerUriNotSet, result.Status); Assert.AreEqual("Server Uri is not set", result.Message); sett.ServerUri_Get(() => new Uri("http://*****:*****@test.com", null); Assert.IsNotNull(result); Assert.AreEqual(LoginStatus.PasswordIsNull, result.Status); Assert.AreEqual("Password cannot be null", result.Message); result = await serverContext.LoginAsync("*****@*****.**", "testtest"); Assert.IsNotNull(result); Assert.AreEqual(LoginStatus.UnableToConnectToServer, result.Status); Assert.AreEqual("Unable to connect to server", result.Message); sett.ServerUri_Get(() => new Uri("http://*****:*****@test.com", "testtst"); Assert.IsNotNull(result); Assert.AreEqual(LoginStatus.Error, result.Status); Assert.AreEqual("Error Authenticating", result.Message); sett.ServerUri_Get(() => new Uri("http://*****:*****@test.com", "testtest"); Assert.IsNotNull(result); Assert.AreEqual(LoginStatus.Success, result.Status); Assert.IsNotNull(result.Message); }