public void Create_WhenPostTextIsNull_ShouldReturnStatusCode400() { var fakeUserRepo = new FakeUserRepository(); var user = new User() { DisplayName = "JavaScript", Username = "******", AuthCode = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e", SessionKey = "1zIzcHNYWhSKnWVrGNpBLxOzDDLPRMbHMeMjklumYmodzRTgAH" }; fakeUserRepo.Add(user); var fakePostRepo = new FakePostRepository(); var server = new InMemoryHttpServer <Post>("http://localhost/", fakePostRepo); var newPost = new { title = "some title", tags = new string[] { "asd", "qwe" } }; var response = server.CreatePostRequest("api/posts?sessionKey=1zIzcHNYWhSKnWVrGNpBLxOzDDLPRMbHMeMjklumYmodzRTgAH", newPost); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); }
public void Register_WhenDisplayNameIsGreaterThan30Chars_ShouldReturnStatusCode400() { var fakeRepo = new FakeUserRepository(); var server = new InMemoryHttpServer <User>("http://localhost/", fakeRepo); var user = new User() { Username = "******", DisplayName = "asgbfuaysdgfugsdfgyudgdyfdgyugyugyuasdgyuyugasyudgfusydgfuysdgf", AuthCode = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e" }; var response = server.CreatePostRequest("api/users/register", user); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); Assert.AreEqual(1, fakeRepo.Entities.Count); // I put one user in the repository so that the ids begin from 1 (the first user is dummy) }
public void Register_WhenUsernameIsGreaterThan30Chars_ShouldReturnStatusCode400() { var fakeRepo = new FakeUserRepository(); var server = new InMemoryHttpServer <User>("http://localhost/", fakeRepo); var user = new User() { Username = "******", DisplayName = "JavaScript", AuthCode = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e" }; var response = server.CreatePostRequest("api/users/register", user); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); Assert.AreEqual(1, fakeRepo.Entities.Count); // I put one user in the repository so that the ids begin from 1 (the first user is dummy) }
public void Register_WhenAuthCodeIsShort_ShouldReturnStatusCode400() { var fakeRepo = new FakeUserRepository(); var server = new InMemoryHttpServer <User>("http://localhost/", fakeRepo); var user = new User() { Username = "******", DisplayName = "Valid Display Name", AuthCode = "asd" }; var response = server.CreatePostRequest("api/users/register", user); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); Assert.AreEqual(1, fakeRepo.Entities.Count); // I put one user in the repository so that the ids begin from 1 (the first user is dummy) }
public void Register_WhenUserIsValid_ShouldReturnStatusCode201_AndSessionKey() { var fakeRepo = new FakeUserRepository(); var server = new InMemoryHttpServer <User>("http://localhost/", fakeRepo); var user = new User() { Username = "******", DisplayName = "Valid Display Name", AuthCode = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e" }; var response = server.CreatePostRequest("api/users/register", user); string stringContent = response.Content.ReadAsStringAsync().Result; UserLoggedModel loggedUser = JsonConvert.DeserializeObject <UserLoggedModel>(stringContent); Assert.AreEqual(HttpStatusCode.Created, response.StatusCode); Assert.AreEqual(2, fakeRepo.Entities.Count); // I put one user in the repository so that the ids begin from 1 (the first user is dummy) Assert.IsNotNull(loggedUser.SessionKey); }
public void Register_WhenDisplayNameAlreadyExists_ShouldReturnStatusCode400() { var fakeRepo = new FakeUserRepository(); var server = new InMemoryHttpServer <User>("http://localhost/", fakeRepo); var user = new User() { Username = "******", DisplayName = "DisplayName", AuthCode = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e" }; fakeRepo.Add(new User { Username = "******", DisplayName = "DisplayName", AuthCode = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e" }); var response = server.CreatePostRequest("api/users/register", user); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); Assert.AreEqual(2, fakeRepo.Entities.Count); // I put one user in the repository so that the ids begin from 1 (the first user is dummy) }