예제 #1
0
        public void CreateBugWithUserComments_ListComments_ShouldListCommentsCorrectly()
        {
            // Arrange -> create a new bug with two comments
            TestingEngine.CleanDatabase();

            var bugTitle         = "bug title";
            var httpPostResponse = TestingEngine.SubmitBugHttpPost(bugTitle, null);

            Assert.AreEqual(HttpStatusCode.Created, httpPostResponse.StatusCode);
            var submittedBug = httpPostResponse.Content.ReadAsAsync <BugModel>().Result;

            var userSession = TestingEngine.RegisterUser("pepo", "pepo");

            TestingEngine.HttpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + userSession.Access_Token);

            var httpPostResponseFirstComment =
                TestingEngine.SubmitCommentHttpPost(submittedBug.Id, "Comment 1");

            Assert.AreEqual(HttpStatusCode.OK, httpPostResponseFirstComment.StatusCode);
            Thread.Sleep(2);

            var httpPostResponseSecondComment =
                TestingEngine.SubmitCommentHttpPost(submittedBug.Id, "Comment 2");

            Assert.AreEqual(HttpStatusCode.OK, httpPostResponseSecondComment.StatusCode);

            TestingEngine.HttpClient.DefaultRequestHeaders.Remove("Authorization");

            // Act -> find all comments
            var httpResponse = TestingEngine.HttpClient.GetAsync("/api/bugs/" + submittedBug.Id + "/comments").Result;

            // Assert -> check the returned comments
            Assert.AreEqual(HttpStatusCode.OK, httpResponse.StatusCode);
            var commentsFromService = httpResponse.Content.ReadAsAsync <List <CommentModel> >().Result;

            Assert.AreEqual(2, commentsFromService.Count());

            Assert.IsTrue(commentsFromService[0].Id > 0);
            Assert.AreEqual("Comment 2", commentsFromService[0].Text);
            Assert.AreEqual("pepo", commentsFromService[0].Author);
            Assert.IsTrue(commentsFromService[0].DateCreated - DateTime.Now < TimeSpan.FromMinutes(1));

            Assert.IsTrue(commentsFromService[1].Id > 0);
            Assert.AreEqual("Comment 1", commentsFromService[1].Text);
            Assert.AreEqual("pepo", commentsFromService[1].Author);
            Assert.IsTrue(commentsFromService[1].DateCreated - DateTime.Now < TimeSpan.FromMinutes(1));
        }
예제 #2
0
        public void UserLogin_ValidUser_ShouldReturn200Ok_AccessToken()
        {
            // Arrange
            TestingEngine.CleanDatabase();
            var username = "******";
            var password = "******";

            // Act
            var userSessionRegister = TestingEngine.RegisterUser(username, password);
            var userSessionLogin    = TestingEngine.LoginUser(username, password);

            // Assert
            Assert.AreEqual(username, userSessionRegister.UserName);
            Assert.AreEqual(username, userSessionLogin.UserName);
            Assert.AreEqual(userSessionLogin.UserName, userSessionRegister.UserName);
            Assert.AreNotEqual(userSessionLogin.Access_Token, userSessionRegister.Access_Token);
        }