예제 #1
0
        public void CreateBugWithComments_ListBugComments_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 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);

            // Act -> find bug 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(null, 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(null, commentsFromService[1].Author);
            Assert.IsTrue(commentsFromService[1].DateCreated - DateTime.Now < TimeSpan.FromMinutes(1));
        }
예제 #2
0
        public void Get_Comments_For_Existing_GivenBug_Should_Return200Ok_And_All_Comments()
        {
            // 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 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);

            // Act
            var response = TestingEngine.HttpClient.GetAsync("api/bugs/" + submittedBug.Id + "/comments").Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            var commentsFromService = response.Content.ReadAsAsync <List <BugDetailsCommentViewModel> >().Result;

            Assert.AreEqual(2, commentsFromService.Count);
            Assert.IsTrue(commentsFromService[0].Id > 0);
            Assert.AreEqual("Comment 2", commentsFromService[0].Text);
            Assert.AreEqual(null, 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(null, commentsFromService[1].Author);
            Assert.IsTrue(commentsFromService[1].DateCreated - DateTime.Now < TimeSpan.FromMinutes(1));
        }
예제 #3
0
        public void RegisterUser_EmptyDb_ShouldReturn200Ok_AccessToken()
        {
            // Arrange
            TestingEngine.CleanDatabase();
            var username = "******";

            // Act
            var postContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("username", username),
                new KeyValuePair <string, string>("password", "pAssW@rd#123456")
            });
            var httpResponse = TestingEngine.HttpClient.PostAsync("/api/user/register", postContent).Result;

            Assert.AreEqual(HttpStatusCode.OK, httpResponse.StatusCode);
            var userSession = httpResponse.Content.ReadAsAsync <UserSessionModel>().Result;

            // Assert
            Assert.AreEqual(userSession.UserName, username);
            Assert.IsNotNull(userSession.Access_Token);
        }
예제 #4
0
        public void CreateBugs_ListBugsByFilter_ShouldReturnsBugsCorrectly()
        {
            // Arrange -> prepare a few bugs
            TestingEngine.CleanDatabase();

            var httpResponseBug1 = TestingEngine.SubmitBugHttpPost("First Bug", null);

            Assert.AreEqual(HttpStatusCode.Created, httpResponseBug1.StatusCode);
            var submittedBug      = httpResponseBug1.Content.ReadAsAsync <BugModel>().Result;
            var httpPatchResponse = TestingEngine.EditBugHttpPatch(
                submittedBug.Id, null, null, "Fixed");

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

            var httpResponseBug2 = TestingEngine.SubmitBugHttpPost("Second Bug", "Second Description");

            Assert.AreEqual(HttpStatusCode.Created, httpResponseBug2.StatusCode);
            Thread.Sleep(2);

            var httpResponseBug3 = TestingEngine.SubmitBugHttpPost("Strange Issue", null);

            Assert.AreEqual(HttpStatusCode.Created, httpResponseBug3.StatusCode);
            Thread.Sleep(2);

            // Act -> filter bugs
            var httpResponseFilterBugs = TestingEngine.FilterBugsHttpGet("Bug", "Fixed|Open", null);

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

            // Assert -> list the bugs and assert their count, order and content are correct
            var bugsFromService = httpResponseFilterBugs.Content.ReadAsAsync <List <BugModel> >().Result;

            Assert.AreEqual(2, bugsFromService.Count());
            Assert.AreEqual("Second Bug", bugsFromService[0].Title);
            Assert.AreEqual("First Bug", bugsFromService[1].Title);
        }