Inheritance: UserLoginModel
        public static User ToEntity(UserRegisterModel userModel)
        {
            User userEntity = new User()
            {
                Username = userModel.Username.ToLower(),
                DisplayName = userModel.DisplayName,
                AuthCode = userModel.AuthCode
            };

            return userEntity;
        }
        public void Register_WhenValidUser_ShouldSaveToDatabase()
        {
            var testUser = new UserRegisterModel()
            {
                DisplayName = "Pesho Peshov",
                Username = "******",
                AuthCode = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e"
            };

            var httpResponse = this.httpServer.Post("api/users/register", testUser);
            var loggedUserModel = httpResponse.Content.ReadAsAsync<UserLoggedModel>().Result;

            Assert.AreEqual(HttpStatusCode.Created, httpResponse.StatusCode);
            Assert.IsNotNull(loggedUserModel);
            Assert.AreEqual(testUser.DisplayName, loggedUserModel.DisplayName);
            Assert.AreEqual(50, loggedUserModel.SessionKey.Length);
        }
        public void TestInitialize()
        {
            // Needed to load the assemlies of Services project
            PostsController postsController = new PostsController();

            transactionScope = new TransactionScope();

            var routes = new List<Route>()
            {
                new Route(
                    "PostsApi",
                    "api/posts/{postID}/{action}",
                    new 
                    { 
                        controller = "posts",
                        postID = RouteParameter.Optional,
                        action = RouteParameter.Optional 
                    }),
                new Route(
                    "UsersApi",
                    "api/users/{action}",
                    new { controller = "users" })
            };

            this.httpServer = new InMemoryHttpServer("http://localhost/", routes);

            // Register a user and user his session key for tests
            var testUser = new UserRegisterModel()
            {
                DisplayName = "Pesho Peshov",
                Username = "******",
                AuthCode = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e"
            };

            var httpResponse = this.httpServer.Post("api/users/register", testUser);
            var loggedUserModel = httpResponse.Content.ReadAsAsync<UserLoggedModel>().Result;
            this.sessionKeyHeader = new Dictionary<string, string>();
            this.sessionKeyHeader["X-sessionKey"] = loggedUserModel.SessionKey;
        }
        public void Register_WhenUserExists_ShouldReturnErrorResponse()
        {
            var testUser1 = new UserRegisterModel()
            {
                DisplayName = "Pesho Peshov",
                Username = "******",
                AuthCode = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e"
            };

            this.httpServer.Post("api/users/register", testUser1);

            // Existing user
            var testUser2 = new UserRegisterModel()
            {
                DisplayName = "Pesho Peshov",
                Username = "******",
                AuthCode = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e"
            };

            var httpResponse = this.httpServer.Post("api/users/register", testUser2);

            Assert.AreEqual(HttpStatusCode.BadRequest, httpResponse.StatusCode);
        }
        public void Logout_WhenLoggedUser_ShouldReturnSuccessResponse()
        {
            // First registers a new user and then logins
            var testUser = new UserRegisterModel()
            {
                DisplayName = "Pesho Peshov",
                Username = "******",
                AuthCode = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e"
            };

            var httpResponse = this.httpServer.Post("api/users/register", testUser);
            var loggedUserModel = httpResponse.Content.ReadAsAsync<UserLoggedModel>().Result;

            // Logout
            IDictionary<string, string> sessionKeyHeader = new Dictionary<string, string>();
            sessionKeyHeader["X-sessionKey"] = loggedUserModel.SessionKey;
            var httpLogoutResponse = this.httpServer.Put("api/users/logout", null, sessionKeyHeader);

            Assert.AreEqual(HttpStatusCode.OK, httpLogoutResponse.StatusCode);
        }