public async Task SimpleSignUp() { // ARRANGE var email = Configuration["email"]; var username = Configuration["username"]; var password = Configuration["password"]; var appId = Configuration["appid"]; var config = new Config(appId); var localData = new LocalData(new FakeLocalData(), new FakeLocalData()); var logger = new TestLogger(_output); var api = new AuthApi(config); var ws = new WsWrapper(config, api, logger, localData); var auth = new AuthMain(config, api, localData, ws, logger); var request = new SignUpRequest { Username = username, Password = password, RememberMe = "none", Email = email }; // ACT var response = await auth.SignUp(request); // ASSERT Assert.NotNull(response.UserId); Assert.NotNull(response.Username); Assert.NotNull(response.Email); }
private async Task <byte[]> GetServerPublicKey() { if (_serverPublicKey != null) { return(_serverPublicKey); } var response = await _api.GetServerPublicKey(); if (response.IsSuccessStatusCode) { _serverPublicKey = await response.Content.ReadAsByteArrayAsync(); return(_serverPublicKey); } var one = AuthMain.ParseGenericErrors(await response.Content.ReadAsStringAsync(), response.StatusCode); if (one != null) { throw one; } throw new Exception($"Unknown error during SignIn: {response.StatusCode}"); }
public async Task CompleteTest() { // ARRANGE var username = Configuration["username"]; var password = Configuration["password"]; var appId = Configuration["appid"]; var config = new Config(appId); var localData = new LocalData(new FakeLocalData(), new FakeLocalData()); var logger = new TestLogger(_output); var api = new AuthApi(config); var ws = new WsWrapper(config, api, logger, localData); var auth = new AuthMain(config, api, localData, ws, logger); var signInRequest = new SignInRequest { Username = username, Password = password, RememberMe = "none" }; var db = new Db(ws); void ChangeHandler(List <Database.Item> items) { var output = _output; output.WriteLine($"Received {items.Count} items from database."); } // ACT var response = await auth.SignIn(signInRequest); var promise = new TaskCompletionSource <int>(); #pragma warning disable 4014 Task.Factory.StartNew(async() => #pragma warning restore 4014 { var scopedWs = ws; var scopedLogger = logger; while (!scopedWs.Keys.Init) { } await scopedLogger.Log("KEYS INIT DONE"); promise.SetResult(0); }); await promise.Task; await db.OpenDatabase(new OpenDatabaseRequest { DatabaseName = "todos", ChangeHandler = ChangeHandler }); // ASSERT Assert.NotNull(response.UserId); Assert.NotNull(response.Username); Assert.NotNull(response.Email); }
public async Task SimpleSignIn() { // ARRANGE var userId = Configuration["userid"]; var username = Configuration["username"]; var password = Configuration["password"]; var appId = Configuration["appid"]; var config = new Config(appId); var localData = new LocalData(new FakeLocalData(), new FakeLocalData()); var logger = new TestLogger(_output); var api = new AuthApi(config); var ws = new WsWrapper(config, api, logger, localData); var auth = new AuthMain(config, api, localData, ws, logger); var request = new SignInRequest { Username = username, Password = password, RememberMe = "none" }; // ACT var sw = Stopwatch.StartNew(); var response = await auth.SignIn(request); while (ws.Instance4Net == null) { } while (ws.Instance4Net != null && ws.Instance4Net.State != WebSocketState.Closed) { if (sw.Elapsed.TotalSeconds > 20) { ws.Instance4Net.Close("Stop Test"); } } sw.Stop(); // ASSERT Assert.NotNull(response.UserId); Assert.Equal(userId, response.UserId); Assert.NotNull(response.Username); }