public void TestGetReturns200_IfEverythingIsOk() { 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(true)); this.mockVoteRepository.Setup( repository => repository.GetVote(It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>(), It.IsAny <string>())) .Returns(Task.FromResult(new VoteBll { Value = 5 })); var voteController = new VoteController(this.mockNewsRepository.Object, this.mockVoteRepository.Object, this.inputValidation.Object, this.businessValidation.Object); var request = new HttpRequestMessage(HttpMethod.Get, 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, "GetVote", new HttpRoute(GOUriBuilder.NewsVoteTemplate)); voteController.User = new GenericPrincipal(new GenericIdentity(DefaultNickname), null); HttpResponseMessage response = voteController.Get(City, Date, Id.ToString()).Result; HttpContent content = response.Content; string jsonContent = content.ReadAsStringAsync().Result; var actualVote = JsonConvert.DeserializeObject <Vote>(jsonContent); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); Assert.AreEqual(5, actualVote.Value); }
private void AssertDeleteFails(HttpStatusCode resultCode) { var voteController = new VoteController(this.mockNewsRepository.Object, this.mockVoteRepository.Object, this.inputValidation.Object, this.businessValidation.Object); var request = new HttpRequestMessage(HttpMethod.Delete, 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, "DeleteVote", new HttpRoute(GOUriBuilder.NewsVoteTemplate)); voteController.User = new GenericPrincipal(new GenericIdentity(DefaultNickname), null); HttpResponseMessage response = voteController.Delete(City, Date, Id.ToString()).Result; Assert.AreEqual(resultCode, response.StatusCode); this.mockVoteRepository.Verify(storage => storage.DeleteVote(It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>(), It.IsAny <string>()), Times.Never()); }
public void TestDeleteReturns200_IfEverythingIsOk() { 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(true)); var voteController = new VoteController(this.mockNewsRepository.Object, this.mockVoteRepository.Object, this.inputValidation.Object, this.businessValidation.Object); var request = new HttpRequestMessage(HttpMethod.Delete, 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, "DeleteVote", new HttpRoute(GOUriBuilder.NewsVoteTemplate)); voteController.User = new GenericPrincipal(new GenericIdentity(DefaultNickname), null); HttpResponseMessage response = voteController.Delete(City, Date, Id.ToString()).Result; Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); this.mockVoteRepository.Verify(repository => repository.DeleteVote(It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>(), It.IsAny <string>()), Times.Once); }