public void LoginNonExistantUser() { try { using (MySqlDataManipulator manipulator = new MySqlDataManipulator()) { manipulator.Connect(TestingConstants.ConnectionString); Assert.IsTrue(manipulator.RemoveUserByEmail(TestingUserStorage.ValidUser2.Email)); object[] contextAndRequest = ServerTestingMessageSwitchback.SwitchbackMessage( TestingUserStorage.ValidUser2.ConstructLoginRequest(), "PUT"); var ctx = contextAndRequest[0] as HttpListenerContext; var req = contextAndRequest[1] as HttpWebRequest; TestApi.PUT(ctx); HttpWebResponse resp; try { resp = req.EndGetResponse(contextAndRequest[2] as IAsyncResult) as HttpWebResponse; Assert.Fail("Expected the response to be an error response. This was not the case."); } catch (WebException e) { resp = e.Response as HttpWebResponse; } Assert.AreEqual(HttpStatusCode.NotFound, resp.StatusCode); } } finally { TestingDatabaseCreationUtils.InitializeUsers(); } }
public void TestBadRequestOnAllEmptyFields() { try { MySqlDataManipulator manipulator = new MySqlDataManipulator(); using (manipulator) { manipulator.Connect(TestingConstants.ConnectionString); Assert.IsTrue(manipulator.RemoveUserByEmail(TestingUserStorage.ValidUser1.Email)); var creationMessage = new JsonDictionaryStringConstructor(); object[] contextAndRequest = ServerTestingMessageSwitchback.SwitchbackMessage( creationMessage, "POST"); var ctx = contextAndRequest[0] as HttpListenerContext; var req = contextAndRequest[1] as HttpWebRequest; HttpWebResponse resp; TestApi.POST(ctx); try { resp = req.EndGetResponse(contextAndRequest[2] as IAsyncResult) as HttpWebResponse; } catch (WebException e) { resp = e.Response as HttpWebResponse; } Assert.AreEqual(HttpStatusCode.BadRequest, resp.StatusCode); } } finally { TestingDatabaseCreationUtils.InitializeUsers(); } }
public static void InitializeClass(TestContext ctx) { if (!TestingDatabaseCreationUtils.InitializeDatabaseSchema()) { throw new Exception("Failed to initialize database schema. See logged error for details"); } TestApi = new UserSettingsApi(10000); if (!TestingDatabaseCreationUtils.InitializeUsers()) { throw new Exception("Failed to initialize users in database. See logged error for details"); } }
public static void SetupTests(TestContext context) { if (!TestingDatabaseCreationUtils.InitializeDatabaseSchema()) { throw new Exception("Failed to initalize database. See logged error"); } TestApi = new RepairJobReportApi(10000); if (!TestingDatabaseCreationUtils.InitializeUsers()) { throw new Exception("Failed to initialize users in database. See logged error"); } }
public void TestCreateValidUser1() { MySqlDataManipulator manipulator = new MySqlDataManipulator(); using (manipulator) { manipulator.Connect(TestingConstants.ConnectionString); Assert.IsTrue(manipulator.RemoveUserByEmail(TestingUserStorage.ValidUser1.Email)); object[] contextAndRequest = ServerTestingMessageSwitchback.SwitchbackMessage( TestingUserStorage.ValidUser1.ConstructCreationMessage(), "POST"); var ctx = contextAndRequest[0] as HttpListenerContext; var req = contextAndRequest[1] as HttpWebRequest; TestApi.POST(ctx); HttpWebResponse resp; try { resp = req.EndGetResponse(contextAndRequest[2] as IAsyncResult) as HttpWebResponse; } catch (WebException e) { resp = e.Response as HttpWebResponse; } try { Assert.AreEqual(HttpStatusCode.OK, resp.StatusCode); } catch (AssertFailedException e) { byte[] respData = new byte[resp.ContentLength]; resp.GetResponseStream().Read(respData, 0, respData.Length); Console.WriteLine(Encoding.UTF8.GetString(respData)); TestingDatabaseCreationUtils.InitializeUsers(); throw e; } var createdUser = manipulator.GetUsersWhere(string.Format("Email = \"{0}\"", TestingUserStorage.ValidUser1.Email)); Assert.IsNotNull(createdUser); Assert.AreEqual(1, createdUser.Count); Assert.AreEqual(TestingUserStorage.ValidUser1.Email, createdUser[0].Email); } }