コード例 #1
0
        public virtual ApiVotesResponseModel MapBOToModel(
            BOVotes boVotes)
        {
            var model = new ApiVotesResponseModel();

            model.SetProperties(boVotes.Id, boVotes.BountyAmount, boVotes.CreationDate, boVotes.PostId, boVotes.UserId, boVotes.VoteTypeId);

            return(model);
        }
コード例 #2
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiVotesResponseModel response = await this.VotesService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
コード例 #3
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiVotesModelMapper();
            var model  = new ApiVotesResponseModel();

            model.SetProperties(1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1);
            ApiVotesRequestModel response = mapper.MapResponseToRequest(model);

            response.BountyAmount.Should().Be(1);
            response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.PostId.Should().Be(1);
            response.UserId.Should().Be(1);
            response.VoteTypeId.Should().Be(1);
        }
コード例 #4
0
        public void MapBOToModel()
        {
            var     mapper = new BOLVotesMapper();
            BOVotes bo     = new BOVotes();

            bo.SetProperties(1, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1);
            ApiVotesResponseModel response = mapper.MapBOToModel(bo);

            response.BountyAmount.Should().Be(1);
            response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Id.Should().Be(1);
            response.PostId.Should().Be(1);
            response.UserId.Should().Be(1);
            response.VoteTypeId.Should().Be(1);
        }
コード例 #5
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IVotesRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Votes>(null));
            var service = new VotesService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.VotesModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLVotesMapperMock,
                                           mock.DALMapperMockFactory.DALVotesMapperMock);

            ApiVotesResponseModel response = await service.Get(default(int));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
コード例 #6
0
        public async void Create_Errors()
        {
            VotesControllerMockFacade mock = new VotesControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiVotesResponseModel> >(new FluentValidation.Results.ValidationResult());
            var mockRecord   = new ApiVotesResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiVotesRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiVotesResponseModel> >(mockResponse.Object));
            VotesController controller = new VotesController(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.Create(new ApiVotesRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiVotesRequestModel>()));
        }
コード例 #7
0
        public async void All_Exists()
        {
            VotesControllerMockFacade mock = new VotesControllerMockFacade();
            var record  = new ApiVotesResponseModel();
            var records = new List <ApiVotesResponseModel>();

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).Returns(Task.FromResult(records));
            VotesController controller = new VotesController(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.All(1000, 0);

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var items = (response as OkObjectResult).Value as List <ApiVotesResponseModel>;

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
コード例 #8
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiVotesRequestModel> patch)
        {
            ApiVotesResponseModel record = await this.VotesService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiVotesRequestModel model = await this.PatchModel(id, patch);

                UpdateResponse <ApiVotesResponseModel> result = await this.VotesService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
コード例 #9
0
        public async void TestGet()
        {
            ApiVotesResponseModel response = await this.Client.VotesGetAsync(1);

            response.Should().NotBeNull();
        }