public void RegisterUser_WhenUsernameIsInvalid_ShouldReturn400() { var testUser = new UserDto() { Username = "", DisplayName = "VALIDDISPLAYNAME", AuthCode = new string('b', 40) }; var response = httpServer.Post("api/users/register", testUser); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); }
public void Register_WhenUserModelValid_ShouldSaveToDatabase() { var testUser = new UserDto() { Username = "******", DisplayName = "VALIDDISPLAYNAME", AuthCode = new string('b', 40) }; var model = this.RegisterTestUser(httpServer, testUser); Assert.AreEqual(testUser.DisplayName, model.DisplayName); Assert.IsNotNull(model.SessionKey); }
public void Post_ShouldReturnData() { var testUser = new UserDto() { Username = "******", DisplayName = "VALIDDISPLAYNAME", AuthCode = new string('b', 40) }; var post = new PostDto() { Title = "Test Title", Content = "Test post text", Tags = new List<string>() { "tag1", "Tag2" } }; UserLogedDto userModel = RegisterTestUser(httpServer, testUser); var response = httpServer.Post("api/posts?sessionKey=" + userModel.SessionKey, post); Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); Assert.IsNotNull(response.Content); }
private UserLogedDto RegisterTestUser(InMemoryHttpServer httpServer, UserDto testUser) { var response = httpServer.Post("api/users/register", testUser); var contentString = response.Content.ReadAsStringAsync().Result; var userModel = JsonConvert.DeserializeObject<UserLogedDto>(contentString); return userModel; }
public void LogoutUser_WhenSessionKeyIsInvalid() { var testUser = new UserDto() { Username = "******", DisplayName = "VALIDDISPLAYNAME", AuthCode = new string('b', 40) }; var userModel = this.RegisterTestUser(httpServer, testUser); string invalidSessionKey = new string('b', 50); var responseLogout = httpServer.Put("api/users/logout?sessionKey=" + invalidSessionKey, testUser); Assert.AreEqual(HttpStatusCode.BadRequest, responseLogout.StatusCode); }
public void RegisterUser_WhenUserIsNull() { var testUserExistInDb = new UserDto(); var responseBadRequest = httpServer.Post("api/users/register", testUserExistInDb); Assert.AreEqual(HttpStatusCode.BadRequest, responseBadRequest.StatusCode); }
public void RegisterUser_WhenUserNameExistInDb() { var validTestUser = new UserDto() { Username = "******", DisplayName = "VALIDDISPLAYNAME1", AuthCode = new string('b', 40) }; var testUserExistInDb = new UserDto() { Username = "******", // Duplicated Username DisplayName = "VALIDDISPLAYNAME2", AuthCode = new string('b', 40) }; var responseOk = httpServer.Post("api/users/register", validTestUser); var responseBadRequest = httpServer.Post("api/users/register", testUserExistInDb); Assert.AreEqual(HttpStatusCode.Created, responseOk.StatusCode); Assert.AreEqual(HttpStatusCode.BadRequest, responseBadRequest.StatusCode); }
public void GetAllPostsByCountAndPage_ShouldReturnData() { var testUser = new UserDto() { Username = "******", DisplayName = "VALIDNICK", AuthCode = new string('b', 40) }; UserLogedDto userModel = RegisterTestUser(httpServer, testUser); var response = httpServer.Get("api/posts?sessionKey=" + userModel.SessionKey + "&page=0&count=2"); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.IsNotNull(response.Content); }
public void PutComment_ShouldReturnData() { var testUser = new UserDto() { Username = "******", DisplayName = "VALIDDISPLAYNAME", AuthCode = new string('b', 40) }; var post = new PostDto() { Title = "Test Title", Content = "Test post text", Tags = new List<string>() { "tag1", "Tag2" } }; var commentDto = new CommentDto() { Text = "Test comment" }; UserLogedDto userModel = RegisterTestUser(httpServer, testUser); var response = httpServer.Post("api/posts?sessionKey=" + userModel.SessionKey, post); var contentString = response.Content.ReadAsStringAsync().Result; var postDto = JsonConvert.DeserializeObject<PostDto>(contentString); var responsePutComment = httpServer.Put( "api/posts/" + postDto.Id + "/comment?sessionKey=" + userModel.SessionKey, commentDto); Assert.AreEqual(HttpStatusCode.OK, responsePutComment.StatusCode); Assert.IsNull(responsePutComment.Content); }
public void PostsByTags_ShouldReturnData() { var testUser = new UserDto() { Username = "******", DisplayName = "VALIDDISPLAYNAME", AuthCode = new string('b', 40) }; var post = new PostDto() { Title = "Test Title", Content = "Test post text", Tags = new List<string>() { "tag1", "Tag2" } // This chesk is searching is case insensitive }; UserLogedDto userModel = RegisterTestUser(httpServer, testUser); var response = httpServer.Post("api/posts?sessionKey=" + userModel.SessionKey, post); var responseByTags = httpServer.Get("api/posts?tags=tag1,tag2&sessionKey=" + userModel.SessionKey); // Check is post with tags added to database(in current transaction). Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); Assert.IsNotNull(response.Content); Assert.AreEqual(HttpStatusCode.OK, responseByTags.StatusCode); Assert.IsNotNull(responseByTags.Content); }