public void DeleteBug_WithComments_ShouldReturn200Ok_RemoveTheBug() { // Arrange -> create a new bug with two comments TestingEngine.CleanDatabase(); var bugTitle = "Bug title"; var bugDescription = "Bug description"; var httpPostResponse = TestingEngine.SubmitBugHttpPost(bugTitle, bugDescription); 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); var httpPostResponseSecondComment = TestingEngine.SubmitCommentHttpPost(submittedBug.Id, "Comment 2"); Assert.AreEqual(HttpStatusCode.OK, httpPostResponseSecondComment.StatusCode); // Act -> delete the bug by its ID var httpResponseDeleteBug = TestingEngine.HttpClient.DeleteAsync("/api/bugs/" + submittedBug.Id).Result; // Assert -> check if the bug by ID holds correct data Assert.AreEqual(HttpStatusCode.OK, httpResponseDeleteBug.StatusCode); var httpResponseGetBug = TestingEngine.HttpClient.GetAsync("/api/bugs/" + submittedBug.Id).Result; Assert.AreEqual(HttpStatusCode.NotFound, httpResponseGetBug.StatusCode); }
public void GetBugById_ExistingBug_ShouldReturn200Ok_TheBugWithComments() { // Arrange -> create a new bug with two comments TestingEngine.CleanDatabase(); var bugTitle = "Bug title"; var bugDescription = "Bug description"; var httpPostResponse = TestingEngine.SubmitBugHttpPost(bugTitle, bugDescription); 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 the bug by its ID var httpResponse = TestingEngine.HttpClient.GetAsync("/api/bugs/" + submittedBug.Id).Result; // Assert -> check if the bug by ID holds correct data Assert.AreEqual(HttpStatusCode.OK, httpResponse.StatusCode); var bugFromService = httpResponse.Content.ReadAsAsync <BugModel>().Result; Assert.IsTrue(bugFromService.Id > 0); Assert.AreEqual(bugTitle, bugFromService.Title); Assert.AreEqual(bugDescription, bugFromService.Description); Assert.AreEqual(null, bugFromService.Author); Assert.AreEqual("Open", bugFromService.Status.ToString()); Assert.IsTrue(bugFromService.DateCreated - DateTime.Now < TimeSpan.FromMinutes(1)); Assert.AreEqual(2, bugFromService.Comments.Count()); Assert.IsTrue(bugFromService.Comments[0].Id > 0); Assert.AreEqual("Comment 2", bugFromService.Comments[0].Text); Assert.AreEqual(null, bugFromService.Comments[0].Author); Assert.IsTrue(bugFromService.Comments[0].DateCreated - DateTime.Now < TimeSpan.FromMinutes(1)); Assert.IsTrue(bugFromService.Comments[1].Id > 0); Assert.AreEqual("Comment 1", bugFromService.Comments[1].Text); Assert.AreEqual(null, bugFromService.Comments[1].Author); Assert.IsTrue(bugFromService.Comments[1].DateCreated - DateTime.Now < TimeSpan.FromMinutes(1)); }
public void TestGetCommentForBugWhenBugExistAndThereAreCommentsShouldReturnCommentOrderedDescendingByDate() { // Arrange -> create a new bug with three 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); Thread.Sleep(2); var httpPostResponseThirdComment = TestingEngine.SubmitCommentHttpPost(submittedBug.Id, "Comment 3"); Assert.AreEqual(HttpStatusCode.OK, httpPostResponseThirdComment.StatusCode); // Act -> find all comments for the bug 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(3, commentsFromService.Count()); Assert.AreEqual("Comment 3", commentsFromService[0].Text); Assert.AreEqual(null, commentsFromService[0].Author); Assert.IsTrue(commentsFromService[0].DateCreated - DateTime.Now < TimeSpan.FromMinutes(1)); Assert.AreEqual("Comment 2", commentsFromService[1].Text); Assert.AreEqual(null, commentsFromService[1].Author); Assert.IsTrue(commentsFromService[1].DateCreated - DateTime.Now < TimeSpan.FromMinutes(1)); Assert.AreEqual("Comment 1", commentsFromService[2].Text); Assert.AreEqual(null, commentsFromService[2].Author); Assert.IsTrue(commentsFromService[2].DateCreated - DateTime.Now < TimeSpan.FromMinutes(1)); }
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)); }
public void CreateBugWithComments_ListAllComments_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 all comments var httpResponse = TestingEngine.HttpClient.GetAsync("/api/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.AreEqual(submittedBug.Id, commentsFromService[0].BugId); Assert.AreEqual(bugTitle, commentsFromService[0].BugTitle); 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)); Assert.AreEqual(submittedBug.Id, commentsFromService[1].BugId); Assert.AreEqual(bugTitle, commentsFromService[1].BugTitle); }
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)); }