public async Task LikingAndUnlikingCommentTest() { HttpClient client = _testServer.CreateClient(1); CommentLikeDto commentLikeDto = new CommentLikeDto { CommentId = 1 }; HttpResponseMessage createResponse = await client.PostAsync(_apiEndpoint + "api/commentLike/post", commentLikeDto, new JsonMediaTypeFormatter()); Assert.AreEqual(HttpStatusCode.Created, createResponse.StatusCode); HttpResponseMessage duplicateCreateResponse = await client.PostAsync(_apiEndpoint + "api/commentLike/post", commentLikeDto, new JsonMediaTypeFormatter()); Assert.AreEqual(HttpStatusCode.OK, duplicateCreateResponse.StatusCode); HttpResponseMessage deleteResponse = await client.PostAsync(_apiEndpoint + "api/commentLike/delete", commentLikeDto, new JsonMediaTypeFormatter()); Assert.AreEqual(HttpStatusCode.OK, deleteResponse.StatusCode); HttpResponseMessage duplicateDeleteResponse = await client.PostAsync(_apiEndpoint + "api/commentLike/delete", commentLikeDto, new JsonMediaTypeFormatter()); Assert.AreEqual(HttpStatusCode.NoContent, duplicateDeleteResponse.StatusCode); }
public async Task GetCommentsTestInvalidPostId() { HttpClient client = _testServer.CreateClient(); HttpResponseMessage response = await client.GetAsync(_apiEndpoint + "api/Comment/Get/-1"); Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode); }
public async Task PostInvalidOneTimeTokenTest() { HttpClient client = _testServer.CreateClient(); OneTimeTokenDto invalidToken = new OneTimeTokenDto { TokenId = "testToken" }; HttpResponseMessage response = await client.PostAsync(_apiEndpoint + "api/user/google", invalidToken, new JsonMediaTypeFormatter()); Assert.AreEqual(HttpStatusCode.Unauthorized, response.StatusCode); }
public async Task GetUserStatsTest() { HttpClient client = _testServer.CreateClient(1); HttpResponseMessage response = await client.GetAsync(_apiEndpoint + $"api/user/Stats"); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); UserStatsDto content = await response.Content.ReadAsAsync <UserStatsDto>(); Assert.AreEqual(content.CreatePostCount, 3); Assert.AreEqual(content.FavouritePostCount, 3); }
public async Task FavouriteAndUnfavouritePostTest() { HttpClient client = _testServer.CreateClient(2); FavouriteDto postLikeDto = new FavouriteDto { PostId = 1 }; HttpResponseMessage createResponse = await client.PostAsync(_apiEndpoint + "api/favourite/post", postLikeDto, new JsonMediaTypeFormatter()); Assert.AreEqual(HttpStatusCode.Created, createResponse.StatusCode); HttpResponseMessage duplicateCreateResponse = await client.PostAsync(_apiEndpoint + "api/favourite/post", postLikeDto, new JsonMediaTypeFormatter()); Assert.AreEqual(HttpStatusCode.OK, duplicateCreateResponse.StatusCode); HttpResponseMessage deleteResponse = await client.PostAsync(_apiEndpoint + "api/favourite/delete", postLikeDto, new JsonMediaTypeFormatter()); Assert.AreEqual(HttpStatusCode.OK, deleteResponse.StatusCode); HttpResponseMessage duplicateDeleteResponse = await client.PostAsync(_apiEndpoint + "api/favourite/delete", postLikeDto, new JsonMediaTypeFormatter()); Assert.AreEqual(HttpStatusCode.NoContent, duplicateDeleteResponse.StatusCode); }
public async Task GetPostTypeTest() { using (HttpClient client = _testServer.CreateClient()) { HttpResponseMessage response = await client.GetAsync(_apiEndpoint + "api/PostType/"); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); List <PostTypeDto> content = await response.Content.ReadAsAsync <List <PostTypeDto> >(); Assert.AreEqual(MockDBContextInitializer.InitialPostTypes().Length, content.Count); } }