Exemple #1
0
        public void CreatePostServiceShouldReturnCreatedStatusWhenDataIsValid()
        {
            var userModel = new UserModel
            {
                Username    = "******",
                DisplayName = "GeorgiIvaylov",
                AuthCode    = "1234567890123456789012345678901234567890"
            };

            var response = httpServer.Post("api/users/register", userModel);

            var content        = response.Content.ReadAsStringAsync().Result;
            var responseObject = JsonConvert.DeserializeObject <LoggedUserModel>(content);

            var sessionKey = responseObject.SessionKey;

            var headers = new Dictionary <string, string>();

            headers.Add("X-sessionKey", sessionKey);

            var postModel = new PostModel
            {
                Title = "SomePost",
                Text  = "SomeText",
                Tags  = new List <string>()
                {
                    "kef", "dva kefa", "tri kefa"
                }
            };

            response = httpServer.Post("api/posts", postModel, headers);

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
        }
        public static LoggedUserModel RegisterTestUser(InMemoryHttpServer httpServer, UserModel testUser)
        {
            var response = httpServer.Post("api/users/register", testUser);
            var contentString = response.Content.ReadAsStringAsync().Result;
            var userModel = JsonConvert.DeserializeObject<LoggedUserModel>(contentString);

            return userModel;
        }
        public void LogoutServiceShouldReturnOkStatusCode()
        {
            var userModel = new UserModel
            {
                Username    = "******",
                DisplayName = "GeorgiIvaylov",
                AuthCode    = "1234567890123456789012345678901234567890"
            };

            var response = httpServer.Post("api/users/register", userModel);

            var content        = response.Content.ReadAsStringAsync().Result;
            var responseObject = JsonConvert.DeserializeObject <LoggedUserModel>(content);

            var sessionKey = responseObject.SessionKey;

            var headers = new Dictionary <string, string>();

            headers.Add("X-sessionKey", sessionKey);

            //using post because PUT does not work for unknown to mankind reasons
            response = httpServer.Post("api/users/logout", null, headers);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
Exemple #4
0
        public void PostsByTagsServiceShouldReturnTwoPostsWhenDataIsValidWithOneTag()
        {
            var userModel = new UserModel
            {
                Username    = "******",
                DisplayName = "GeorgiIvaylov",
                AuthCode    = "1234567890123456789012345678901234567890"
            };

            var response = httpServer.Post("api/users/register", userModel);

            var content        = response.Content.ReadAsStringAsync().Result;
            var responseObject = JsonConvert.DeserializeObject <LoggedUserModel>(content);

            var sessionKey = responseObject.SessionKey;

            var headers = new Dictionary <string, string>();

            headers.Add("X-sessionKey", sessionKey);

            var postModel = new PostModel
            {
                Title = "SomePost",
                Text  = "SomeText",
                Tags  = new List <string>()
                {
                    "kef", "dva kefa", "tri kefa"
                }
            };

            response = httpServer.Post("api/posts", postModel, headers);

            postModel = new PostModel
            {
                Title = "SomePost2",
                Text  = "SomeText1",
                Tags  = new List <string>()
                {
                    "kef", "tri kefa"
                }
            };

            response = httpServer.Post("api/posts", postModel, headers);

            postModel = new PostModel
            {
                Title = "SomePost2",
                Text  = "SomeText1",
                Tags  = new List <string>()
                {
                    "dva kefa", "tri kefa"
                }
            };

            response = httpServer.Post("api/posts", postModel, headers);

            response = httpServer.Get("api/posts?tags=dva%20kefa", headers);

            content = response.Content.ReadAsStringAsync().Result;
            var resultPosts = JsonConvert.DeserializeObject <IEnumerable <PostModel> >(content);

            Assert.AreEqual(2, resultPosts.Count());
        }
        private PostModel PostCreateTag(InMemoryHttpServer httpServer, TagModel testTag)
        {
            LoggedUserModel loggedUser = RegisterTestUser(httpServer, testUser);
            var headers = new Dictionary<string, string>();
            headers["X-sessionKey"] = loggedUser.SessionKey;

            var response = httpServer.Post("api/posts/create", testTag, headers);
            var contentString = response.Content.ReadAsStringAsync().Result;
            var postModel = JsonConvert.DeserializeObject<PostModel>(contentString);
            return postModel;
        }
        public void RegisterServiceShouldReturnOkStatusWhenDataIsValid()
        {
            var userModel = new UserModel
            {
                Username    = "******",
                DisplayName = "GeorgiIvaylov",
                AuthCode    = "1234567890123456789012345678901234567890"
            };

            var response = httpServer.Post("api/users/register", userModel);

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
        }
Exemple #7
0
        //[TestMethod]
        //public void CreatePost()
        //{
        //    var testPost = new Post()
        //    {
        //        Title = "test post",
        //        Text = "test post content"
        //    };

        //    var testUser = new UserModel()
        //    {
        //        Username = "******",
        //        Nickname = "VALIDNICK",
        //        AuthCode = new string('b', 40)
        //    };

        //    var userModel = RegisterOrLoginTestUser("api/users/register", httpServer, testUser);

        //    var response = httpServer.Post("api/posts?sessionKey=" + userModel.SessionKey, testPost);
        //    var contentString = response.Content.ReadAsStringAsync().Result;
        //    var postModel = JsonConvert.DeserializeObject<PostModel>(contentString);

        //    Assert.AreEqual(testPost.Title, postModel.Title);
        //    Assert.AreEqual(testPost.Id, postModel.Id);
        //}

        private LoggedUserModel RegisterOrLoginTestUser(string requestUrl, InMemoryHttpServer httpServer, UserModel testUser)
        {
            var response = httpServer.Post(requestUrl, testUser);
            var contentString = response.Content.ReadAsStringAsync().Result;
            var userModel = JsonConvert.DeserializeObject<LoggedUserModel>(contentString);
            return userModel;
        }