Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public async void Get_Not_Exists()
        {
            VoteControllerMockFacade mock = new VoteControllerMockFacade();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiVoteResponseModel>(null));
            VoteController controller = new VoteController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Get(default(int));

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Ejemplo n.º 3
0
        private void AssertGetFails(HttpStatusCode resultCode)
        {
            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;

            Assert.AreEqual(resultCode, response.StatusCode);
            this.mockVoteRepository.Verify(storage => storage.GetVote(It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Guid>(), It.IsAny <string>()), Times.Never());
        }
Ejemplo n.º 4
0
        public async void Get_Exists()
        {
            VoteControllerMockFacade mock = new VoteControllerMockFacade();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new ApiVoteServerResponseModel()));
            VoteController controller = new VoteController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Get(default(int));

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var record = (response as OkObjectResult).Value as ApiVoteServerResponseModel;

            record.Should().NotBeNull();
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }