示例#1
0
        public void CommentPost_WhenSessionKeyIsNotCorrect_ShouldReturnStatusCode400()
        {
            var user = new User()
            {
                DisplayName = "JavaScript",
                Username    = "******",
                AuthCode    = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e",
                SessionKey  = "1zIzcHNYWhSKnWVrGNpBLxOzDDLPRMbHMeMjklumYmodzRTgAH"
            };

            var fakeUserRepo = new FakeUserRepository();

            fakeUserRepo.Add(user);

            var post = new Post()
            {
                PostDate = DateTime.Now,
                Text     = "Some text",
                Title    = "SomeTitle",
                User     = user
            };

            var fakePostRepo = new FakePostRepository();

            fakePostRepo.Add(post);

            var server   = new InMemoryHttpServer <Post>("http://localhost/", fakePostRepo);
            var response = server.CreateGetRequest("api/posts?sessionKey=1zIzcHNYWhSKnWVrGNpBLxOzDDLPRMbHMeMjklumYmodzRTgAH&tags");

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
示例#2
0
        public void Create_WhenPostTextIsNull_ShouldReturnStatusCode400()
        {
            var fakeUserRepo = new FakeUserRepository();
            var user         = new User()
            {
                DisplayName = "JavaScript",
                Username    = "******",
                AuthCode    = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e",
                SessionKey  = "1zIzcHNYWhSKnWVrGNpBLxOzDDLPRMbHMeMjklumYmodzRTgAH"
            };

            fakeUserRepo.Add(user);

            var fakePostRepo = new FakePostRepository();

            var server  = new InMemoryHttpServer <Post>("http://localhost/", fakePostRepo);
            var newPost = new
            {
                title = "some title",
                tags  = new string[] { "asd", "qwe" }
            };


            var response = server.CreatePostRequest("api/posts?sessionKey=1zIzcHNYWhSKnWVrGNpBLxOzDDLPRMbHMeMjklumYmodzRTgAH", newPost);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
示例#3
0
        public void GetByTags_WhenTagsAreNotCorrect_ShouldReturnNoContent()
        {
            var user = new User()
            {
                DisplayName = "JavaScript",
                Username    = "******",
                AuthCode    = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e",
                SessionKey  = "1zIzcHNYWhSKnWVrGNpBLxOzDDLPRMbHMeMjklumYmodzRTgAH"
            };

            var fakeUserRepo = new FakeUserRepository();

            fakeUserRepo.Add(user);

            var post = new Post()
            {
                PostDate = DateTime.Now,
                Text     = "Some text",
                Title    = "SomeTitle",
                User     = user
            };

            var fakePostRepo = new FakePostRepository();

            fakePostRepo.Add(post);

            var tags = new List <Tag>()
            {
                new Tag()
                {
                    Name  = "c#",
                    Posts = new List <Post>()
                    {
                        post
                    }
                },

                new Tag()
                {
                    Name  = "web",
                    Posts = new List <Post>()
                    {
                        post
                    }
                },
            };

            var fakeTagRepo = new FakeTagRepository();

            fakeTagRepo.Add(tags[0]);
            fakeTagRepo.Add(tags[1]);

            var server   = new InMemoryHttpServer <Post>("http://localhost/", fakePostRepo);
            var response = server.CreateGetRequest("api/posts?sessionKey=1zIzcHNYWhSKnWVrGNpBLxOzDDLPRMbHMeMjklumYmodzRTgAH&tags=js");

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.IsNotNull(response.Content);
        }
示例#4
0
        public void Register_WhenDisplayNameIsGreaterThan30Chars_ShouldReturnStatusCode400()
        {
            var fakeRepo = new FakeUserRepository();
            var server   = new InMemoryHttpServer <User>("http://localhost/", fakeRepo);

            var user = new User()
            {
                Username    = "******",
                DisplayName = "asgbfuaysdgfugsdfgyudgdyfdgyugyugyuasdgyuyugasyudgfusydgfuysdgf",
                AuthCode    = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e"
            };

            var response = server.CreatePostRequest("api/users/register", user);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
            Assert.AreEqual(1, fakeRepo.Entities.Count); // I put one user in the repository so that the ids begin from 1 (the first user is dummy)
        }
示例#5
0
        public void Register_WhenUsernameIsGreaterThan30Chars_ShouldReturnStatusCode400()
        {
            var fakeRepo = new FakeUserRepository();
            var server   = new InMemoryHttpServer <User>("http://localhost/", fakeRepo);

            var user = new User()
            {
                Username    = "******",
                DisplayName = "JavaScript",
                AuthCode    = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e"
            };

            var response = server.CreatePostRequest("api/users/register", user);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
            Assert.AreEqual(1, fakeRepo.Entities.Count); // I put one user in the repository so that the ids begin from 1 (the first user is dummy)
        }
示例#6
0
        public void Register_WhenAuthCodeIsShort_ShouldReturnStatusCode400()
        {
            var fakeRepo = new FakeUserRepository();
            var server   = new InMemoryHttpServer <User>("http://localhost/", fakeRepo);

            var user = new User()
            {
                Username    = "******",
                DisplayName = "Valid Display Name",
                AuthCode    = "asd"
            };

            var response = server.CreatePostRequest("api/users/register", user);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
            Assert.AreEqual(1, fakeRepo.Entities.Count); // I put one user in the repository so that the ids begin from 1 (the first user is dummy)
        }
示例#7
0
        public void Logout_WhenSessionKeyIsNotValid_ShouldReturnStatusCode400()
        {
            var fakeRepo = new FakeUserRepository();
            var user     = new User()
            {
                Username   = "******",
                AuthCode   = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e",
                SessionKey = "1zIzcHNYWhSKnWVrGNpBLxOzDDLPRMbHMeMjklumYmodzRTgAH"
            };

            fakeRepo.Add(user);

            var server = new InMemoryHttpServer <User>("http://localhost/", fakeRepo);

            var response = server.CreatePutRequest("api/users/logout?sessionKey=stupidKey", new { });

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
            Assert.IsNotNull(response.Content);
        }
示例#8
0
        public void Register_WhenUserIsValid_ShouldReturnStatusCode201_AndSessionKey()
        {
            var fakeRepo = new FakeUserRepository();
            var server   = new InMemoryHttpServer <User>("http://localhost/", fakeRepo);

            var user = new User()
            {
                Username    = "******",
                DisplayName = "Valid Display Name",
                AuthCode    = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e"
            };

            var response = server.CreatePostRequest("api/users/register", user);

            string          stringContent = response.Content.ReadAsStringAsync().Result;
            UserLoggedModel loggedUser    = JsonConvert.DeserializeObject <UserLoggedModel>(stringContent);

            Assert.AreEqual(HttpStatusCode.Created, response.StatusCode);
            Assert.AreEqual(2, fakeRepo.Entities.Count); // I put one user in the repository so that the ids begin from 1 (the first user is dummy)
            Assert.IsNotNull(loggedUser.SessionKey);
        }
示例#9
0
        public void Register_WhenDisplayNameAlreadyExists_ShouldReturnStatusCode400()
        {
            var fakeRepo = new FakeUserRepository();
            var server   = new InMemoryHttpServer <User>("http://localhost/", fakeRepo);

            var user = new User()
            {
                Username    = "******",
                DisplayName = "DisplayName",
                AuthCode    = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e"
            };

            fakeRepo.Add(new User
            {
                Username    = "******",
                DisplayName = "DisplayName",
                AuthCode    = "bfff2dd4f1b310eb0dbf593bd83f94dd8d34077e"
            });

            var response = server.CreatePostRequest("api/users/register", user);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
            Assert.AreEqual(2, fakeRepo.Entities.Count); // I put one user in the repository so that the ids begin from 1 (the first user is dummy)
        }