Ejemplo n.º 1
0
        private UserLoggedModel RegisterTestUser(InMemoryHttpServer httpServer, UserModel testUser)
        {
            var response      = httpServer.Post("api/users/register", testUser);
            var contentString = response.Content.ReadAsStringAsync().Result;
            var userModel     = JsonConvert.DeserializeObject <UserLoggedModel>(contentString);

            return(userModel);
        }
        public void Create_WhenValid_ShouldReturnStatusCodeCreated()
        {
            PostModel model = new PostModel()
            {
                Text  = "some text",
                Title = "my post",
            };
            UserModel user = new UserModel()
            {
                Username    = "******",
                DisplayName = "Doncho Minkov1",
                AuthCode    = "tfff2dd4f1b310eb0dbf593bd83f94dd8d34077e"
            };

            var responseRegister = httpServer.Post("api/users/register", user);

            var contentString = responseRegister.Content.ReadAsStringAsync().Result;
            var userModel     = JsonConvert.DeserializeObject <UserLoggedModel>(contentString);

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

            headers["X-sessionKey"] = userModel.SessionKey;
            var postResponse = httpServer.Post("api/posts", model, headers);

            Assert.IsNotNull(postResponse.Content);
            Assert.AreEqual(HttpStatusCode.Created, postResponse.StatusCode);
        }
Ejemplo n.º 3
0
        public void Register_WhenValid_ShouldReturnSessionKey()
        {
            UserModel model = new UserModel()
            {
                Username    = "******",
                DisplayName = "Doncho Minkov1",
                AuthCode    = "tfff2dd4f1b310eb0dbf593bd83f94dd8d34077e"
            };

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

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
            Assert.IsNotNull(response.Content);
            var contentString = response.Content.ReadAsStringAsync().Result;
            var loggedModel   = JsonConvert.DeserializeObject <UserLoggedModel>(contentString);

            Assert.AreEqual(model.DisplayName, loggedModel.DisplayName);
            Assert.IsNotNull(loggedModel.SessionKey);
        }