public void Create_WhenPostTextNull_ShouldSaveToDatabase()
        {
            var testUser = new UserModel()
            {
                Username = "******",
                Nickname = "NewVALIDNICK",
                AuthCode = new string('b', 40)
            };
            var httpServer = new InMemoryHttpServer("http://localhost/");
            var userResponse = httpServer.CreatePostRequest("api/users/register", testUser);
            var userContentString = userResponse.Content.ReadAsStringAsync().Result;
            var userModel = JsonConvert.DeserializeObject<UserLoggedModel>(userContentString);

            var testPost = new PostNewModel()
            {
                Title = "Title",
                Text = null,
                Tags = { }
            };

            var response = httpServer.CreatePostRequest("api/posts", testPost,
                "application/json", userModel.SessionKey);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
        public void CreatePost_WhenUserModelValid_ShouldSaveToDatabase()
        {
            var testUser = new UserModel()
            {
                UserName = "******",
                DisplayName = "ValidNick",
                AuthCode = new string('b', 40)
            };

            var httpServer = new InMemoryHttpServer("http://localhost/");
            var response = httpServer.CreatePostRequest("api/users/register", testUser);
            var contentString = response.Content.ReadAsStringAsync().Result;
            var userModel = JsonConvert.DeserializeObject<UserLoggedModel>(contentString);

            var testPost = new PostModel
            {
                Title = "NEW POST",
                Tags = new List<string>() { "post" },
                Text = "this is just a test post"
            };

            var headers = new Dictionary<string, string>();
            headers["X-sessionKey"] = userModel.SessionKey;

            //var postResponse = httpServer.CreatePostRequest("api/posts", testPost, headers);

            //Assert.AreEqual(HttpStatusCode.Created, postResponse.StatusCode);
            //Assert.IsNotNull(postResponse.Content);

            //var contentString = response.Content.ReadAsStringAsync().Result;
            //var model = JsonConvert.DeserializeObject<CreatePostResponseModel>(contentString);
            //Assert.AreEqual(testPost.Title, model.Title);
            //Assert.IsNotNull(model.Id > 0);
        }
        public void Create_WhenPostModelValid_ShouldSaveToDatabase()
        {
            var testUser = new UserModel()
            {
                Username = "******",
                Nickname = "NewVALIDNICK",
                AuthCode = new string('b', 40)
            };
            var httpServer = new InMemoryHttpServer("http://localhost/");
            var userResponse = httpServer.CreatePostRequest("api/users/register", testUser);
            var userContentString = userResponse.Content.ReadAsStringAsync().Result;
            var userModel = JsonConvert.DeserializeObject<UserLoggedModel>(userContentString);

            var testPost = new PostNewModel()
            {
                Title = "Post",
                Text = "ValidText",
                Tags = new string[] { "valid" }
            };

            var response = httpServer.CreatePostRequest("api/posts", testPost,
                "application/json", userModel.SessionKey);

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
            Assert.IsNotNull(response.Content);

            var contentString = response.Content.ReadAsStringAsync().Result;
            var model = JsonConvert.DeserializeObject<PostCreatedModel>(contentString);
            Assert.AreEqual(testPost.Title, model.Title);
            Assert.IsTrue(model.Id != 0);
        }
        public void GetAll_WhenDataInDatabase_ShouldReturnData()
        {
            var httpServer = new InMemoryHttpServer("http://localhost/");

            var response = httpServer.CreateGetRequest("api/threads");

            //Assert
        }
        public void Register_WhenNicknameNotValid_ShouldSaveToDatabase()
        {
            var testUser = new UserModel()
            {
                Username = "******",
                Nickname = "not---?",
                AuthCode = new string('b', 40)
            };
            var httpServer = new InMemoryHttpServer("http://localhost/");
            var response = httpServer.CreatePostRequest("api/users/register", testUser);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
        public void GetByTags_WhenPostModelValidMany_ShouldSaveToDatabase()
        {
            var testUser = new UserModel()
            {
                Username = "******",
                Nickname = "NewVALIDNICK",
                AuthCode = new string('b', 40)
            };
            var httpServer = new InMemoryHttpServer("http://localhost/");
            var userResponse = httpServer.CreatePostRequest("api/users/register", testUser);
            var userContentString = userResponse.Content.ReadAsStringAsync().Result;
            var userModel = JsonConvert.DeserializeObject<UserLoggedModel>(userContentString);

            var testPostOne = new PostNewModel()
            {
                Title = "Post",
                Text = "ValidText",
                Tags = new string[] { "other" }
            };

            var testPostTwo = new PostNewModel()
            {
                Title = "Next Post",
                Text = "NextText",
                Tags = new string[] { "other" }
            };

            var testPostThree = new PostNewModel()
            {
                Title = "Third Post",
                Text = "Some",
                Tags = new string[] { "other" }
            };

            httpServer.CreatePostRequest("api/posts", testPostOne,
                "application/json", userModel.SessionKey);
            httpServer.CreatePostRequest("api/posts", testPostTwo,
                "application/json", userModel.SessionKey);
            httpServer.CreatePostRequest("api/posts", testPostThree,
                "application/json", userModel.SessionKey);

            var response = httpServer.CreateGetRequest("api/posts?tags=other",
                "application/json", userModel.SessionKey);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNotNull(response.Content);

            var contentString = response.Content.ReadAsStringAsync().Result;
            var model = JsonConvert.DeserializeObject<List<PostModel>>(contentString);
            Assert.AreEqual(3, model.Count);
        }
        public void Register_WhenUserModelValid_ShouldSaveToDatabase()
        {
            var testUser = new UserModel()
            {
                UserName = "******",
                DisplayName = "ValidNick1",
                AuthCode = new string('a', 40)
            };

            var httpServer = new InMemoryHttpServer("http://localhost/");
            var response = httpServer.CreatePostRequest("api/users/register", testUser);

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
            Assert.IsNotNull(response.Content);

            var contentString = response.Content.ReadAsStringAsync().Result;
            var model = JsonConvert.DeserializeObject<UserLoggedModel>(contentString);
            Assert.AreEqual(testUser.DisplayName, model.DisplayName);
            Assert.IsNotNull(model.SessionKey);
        }
        public void Create_WhenSessionKeyNotValid_ShouldSaveToDatabase()
        {
            var testPost = new PostNewModel()
            {
                Title = "Post",
                Text = "ValidText",
                Tags = { }
            };

            var httpServer = new InMemoryHttpServer("http://localhost/");
            var response = httpServer.CreatePostRequest("api/posts", testPost,
                "application/json", new string('a', 50));

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }