public void GetPostCommenValidId() { var testUser = new UserModel() { Username = "******", DisplayName = "Valid DisplayName", AuthCode = new string('*', 40) }; var response = httpServer.Post("api/users/register", testUser); var contentString = response.Content.ReadAsStringAsync().Result; Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); var userModel = JsonConvert.DeserializeObject <LoggedUserModel>(contentString); var headers = new Dictionary <string, string>(); headers["X-sessionKey"] = userModel.SessionKey; var post = new PostModel() { Title = "Some title", Text = "Some text" }; var comment = new CommentModel() { Text = "some comment" }; var responseAdd = httpServer.Post("api/posts", post, headers); var responseGet = httpServer.Put("api/posts/" + responseAdd.Content.ReadAsStringAsync().Id + "/comment", comment, headers); Assert.AreEqual(HttpStatusCode.OK, responseGet.StatusCode); }
public void TestWithValidSessionKey_ShouldLogout() { var testUser = new UserModel() { Username = "******", DisplayName = "VALIDNICK", AuthCode = new string('b', 40) }; LoggedUserModel userModel = RegisterTestUser(httpServer, testUser); var headers = new Dictionary <string, string>(); headers["X-sessionKey"] = userModel.SessionKey; var response = httpServer.Put("api/users/logout", headers); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); }
public void LogoutWhenUserSessionIsCorrect() { var testUser = new UserModel() { Username = "******", DisplayName = "Valid DisplayName", AuthCode = new string('*', 40) }; var response = httpServer.Post("api/users/register", testUser); var contentString = response.Content.ReadAsStringAsync().Result; Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); var userModel = JsonConvert.DeserializeObject <LoggedUserModel>(contentString); var headers = new Dictionary <string, string>(); headers["X-sessionKey"] = userModel.SessionKey; var responseLogout = httpServer.Put("api/users/logout", headers); Assert.AreEqual(HttpStatusCode.OK, responseLogout.StatusCode); }
public void TestLogoutUser_SessionKeyIsValid_ShouldReturnOK() { var testUser = new UserDto { Username = "******", DisplayName = "Peter Petroff", AuthCode = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e" }; httpServer.Post("api/users/register", testUser); var response = httpServer.Post("api/users/login", testUser); string contentString = response.Content.ReadAsStringAsync().Result; var loggedUser = JsonConvert.DeserializeObject <LoggedUserDto>(contentString); var headers = new Dictionary <string, string>(); headers["X-SessionKey"] = loggedUser.SessionKey; var logoutResult = httpServer.Put("api/users/logout", headers); Assert.AreEqual(HttpStatusCode.OK, logoutResult.StatusCode); }
public void TestLeaveValidComment_ShouldReturnCreated() { //Create test user var testUser = new UserModel() { Username = "******", DisplayName = "VALIDNICK", AuthCode = new string('b', 40) }; LoggedUserModel userModel = RegisterTestUser(httpServer, testUser); var headers = new Dictionary <string, string>(); headers["X-sessionKey"] = userModel.SessionKey; //Create test post var testPost = new Post() { Title = "Test post", Tags = new List <Tag>() { new Tag() { Name = "technology" }, }, Text = "this is just a test post" }; var createPostResponse = httpServer.Post("api/posts", testPost, headers); string createPostResponseBody = createPostResponse.Content.ReadAsStringAsync().Result; var postResponse = JsonConvert.DeserializeObject <CreatePostResponseModel>(createPostResponseBody); var comment = new Comment() { PostDate = DateTime.Now, Text = "Abe kefi me toq post" }; var commentCreateResponse = httpServer.Put("api/posts/" + postResponse.PostId + "/comment", comment, headers); Assert.AreEqual(HttpStatusCode.Created, commentCreateResponse.StatusCode); }