public void TestInit()
        {

            var type = typeof(UsersController);
            tran = new TransactionScope();

            var routes = new List<Route>
            {
                //new Route(
                //    "ThreadsApi",
                //    "api/threads/{threadId}/posts",
                //    new
                //    {
                //        controller = "threads",
                //        action ="posts"
                //    }),
                //new Route(
                //     "UsersApi",
                //     "api/users/{action}",
                //     new
                //        {
                //            controller = "users"
                //        }),
                        
                new Route(
                    "DefaultApi",
                    "api/{controller}/{id}",
                    new { id = RouteParameter.Optional }),
            };
            this.httpServer = new InMemoryHttpServer("http://localhost/", routes);
        }
        public void TestInit()
        {
            var type = typeof(UsersController);

            tran = new TransactionScope();

            var routes = new List <Route>
            {
                new Route(
                    "CommentApi",
                    "api/posts/{postId}/comment",
                    new
                {
                    controller = "posts",
                    action     = "comment"
                }
                    ),
                new Route(
                    "UsersApi",
                    "api/users/{action}",
                    new { controller = "users" }),
                new Route(
                    "DefaultApi",
                    "api/{controller}/{id}",
                    new { id = RouteParameter.Optional }),
            };

            this.httpServer = new InMemoryHttpServer("http://localhost/", routes);
        }
        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;
        }
Beispiel #4
0
        public void TestInit()
        {
            var type = typeof(UsersController);
            tran = new TransactionScope();

            var routes = new List<Route>
            {
                new Route(
                "PostsByTagApi",
                "api/tags/{tagId}/posts",
                new
                {
                    controller = "tags",
                    action = "posts"
                }
            ),

            new Route(
                "CommentsApi",
                "api/posts/{postId}/comment",
                new
                {
                    controller = "posts",
                    action = "comment"
                }
            ),

            new Route(
                "PostsApi",
                "api/posts",
                new
                {
                    controller = "posts"
                }
            ),

            new Route(
                "UsersApi",
                "api/users/{action}",
                new
                {
                    controller = "users"
                }
            ),

            new Route(
                "DefaultApi",
                "api/{controller}/{id}",
                new { id = RouteParameter.Optional }
            )
            };

            this.httpServer = new InMemoryHttpServer("http://localhost:1418/", routes);
        }
        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;
        }
Beispiel #6
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;
        }