public void UpvoteAndDownvoteSamePost() { // Arrange LoginData loginData = CreatePost(); PostController postController = new PostController(); var getPostResult = postController.Get(loginData.sessionkey, 1).Result; var createdPost = ((getPostResult as OkObjectResult).Value as ComplexAnswer).data as Post; VoteController voteController = new VoteController(); // Act voteController.Post(loginData.sessionkey, Mocks.downvote); voteController.Post(loginData.sessionkey, Mocks.upvote); // Assert var actionResult = postController.Get(loginData.sessionkey, 1).Result; var actual = ((actionResult as OkObjectResult).Value as ComplexAnswer).data as Post; Assert.Equal(Mocks.createPosts[0].title, actual.title); Assert.Equal(Mocks.createPosts[0].description, actual.description); Assert.Equal(Mocks.createPosts[0].path, actual.path); Assert.Equal(1, actual.upvotes); }
private void AssertPostFails(HttpStatusCode resultCode) { var voteController = new VoteController(this.mockNewsRepository.Object, this.mockVoteRepository.Object, this.inputValidation.Object, this.businessValidation.Object); var request = new HttpRequestMessage(HttpMethod.Post, GOUriBuilder.BuildAbsoluteVoteUri(Scheme, Host, Port, City, Date, Id.ToString())); request.Headers.Referrer = new Uri(GOUriBuilder.BuildAbsoluteVoteUri(Scheme, Host, Port, City, Date, Id.ToString())); voteController.ConfigureForTesting(request, "PostVote", new HttpRoute(GOUriBuilder.NewsVoteTemplate)); voteController.User = new GenericPrincipal(new GenericIdentity(DefaultNickname), null); HttpResponseMessage response = voteController.Post(City, Date, Id.ToString(), DefaultVote).Result; Assert.AreEqual(resultCode, response.StatusCode); this.mockVoteRepository.Verify(storage => storage.AddVote(It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <VoteBll>()), Times.Never()); }
public void Send_vote() { using (var loggerFactory = CreateLoggerFactory()) { var node = new Mock <INode>(); var controller = new VoteController(node.Object, loggerFactory.CreateLogger <VoteController>()); var vote = new Vote { ChoiceId = Guid.NewGuid() }; var response = controller.Post(vote); Assert.AreEqual((int)HttpStatusCode.Accepted, response.StatusCode); node.Verify(n => n.Add(It.IsAny <Vote>()), Times.Once); } }
public void TestPostReturns200_IfEverythingIsOk() { this.inputValidation.Setup(validation => validation.IsValidVote(It.IsAny <Vote>())).Returns(true); this.businessValidation.Setup(validation => validation.IsValidGetNews(this.mockNewsRepository.Object, It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>())).Returns(Task.FromResult(true)); this.businessValidation.Setup(validation => validation.IsValidGetVote(this.mockVoteRepository.Object, It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>(), It.IsAny <string>())).Returns(Task.FromResult(false)); var voteController = new VoteController(this.mockNewsRepository.Object, this.mockVoteRepository.Object, this.inputValidation.Object, this.businessValidation.Object); var request = new HttpRequestMessage(HttpMethod.Post, GOUriBuilder.BuildAbsoluteVoteUri(Scheme, Host, Port, City, Date, Id.ToString())); request.Headers.Referrer = new Uri(GOUriBuilder.BuildAbsoluteVoteUri(Scheme, Host, Port, City, Date, Id.ToString())); voteController.ConfigureForTesting(request, "PostVote", new HttpRoute(GOUriBuilder.NewsVoteTemplate)); voteController.User = new GenericPrincipal(new GenericIdentity(DefaultNickname), null); HttpResponseMessage response = voteController.Post(City, Date, Id.ToString(), new Vote { Value = 5 }).Result; Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); this.mockVoteRepository.Verify(repository => repository.AddVote(It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <VoteBll>()), Times.Once); }
public void _3_Vote() { try { var loginController = new LoginController(); var httpResponseMessage = loginController.Post(new Models.MyString(LoginControllerTest.UserTest)); var token = (JObject)JsonConvert.DeserializeObject(httpResponseMessage.Content.ReadAsStringAsync().Result); var httpResponseMessage2 = loginController.Get(token["token"].ToString()); var userInfo = (JObject)JsonConvert.DeserializeObject(httpResponseMessage2.Content.ReadAsStringAsync().Result); var movieController = new MovieController(); var httpResponseMessage3 = movieController.Get(userInfo["Id"].ToString()); var sharedList = JsonConvert.DeserializeObject <SharedView[]>(httpResponseMessage3.Content.ReadAsStringAsync().Result); foreach (var s in sharedList) { if (s.Url == TestUrl) { var voteController = new VoteController(); voteController.Post(new Vote() { MovieId = s.MovieId, UserId = Int64.Parse(userInfo["Id"].ToString()), IsUpVote = true }); //success QueryHelper.ClearUnitTestData(Int64.Parse(userInfo["Id"].ToString()), s.MovieId); Assert.IsTrue(true); return; } } //failed } catch (Exception) { //failed } Assert.Fail(); }