Exemplo n.º 1
0
        public void MapServerResponseToRequest()
        {
            var mapper = new ApiMessageServerModelMapper();
            var model  = new ApiMessageServerResponseModel();

            model.SetProperties(1, "A", 1);
            ApiMessageServerRequestModel response = mapper.MapServerResponseToRequest(model);

            response.Should().NotBeNull();
            response.Content.Should().Be("A");
            response.SenderUserId.Should().Be(1);
        }
Exemplo n.º 2
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiMessageServerResponseModel response = await this.MessageService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Exemplo n.º 3
0
        public async void Get_ShouldReturnNullBecauseRecordNotFound()
        {
            var mock = new ServiceMockFacade <IMessageService, IMessageRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Message>(null));
            var service = new MessageService(mock.LoggerMock.Object,
                                             mock.MediatorMock.Object,
                                             mock.RepositoryMock.Object,
                                             mock.ModelValidatorMockFactory.MessageModelValidatorMock.Object,
                                             mock.DALMapperMockFactory.DALMessageMapperMock,
                                             mock.DALMapperMockFactory.DALMessengerMapperMock);

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Exemplo n.º 4
0
        public async void Create_Errors()
        {
            MessageControllerMockFacade mock = new MessageControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiMessageServerResponseModel> >(null as ApiMessageServerResponseModel);
            var mockRecord   = new ApiMessageServerResponseModel();

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

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

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiMessageServerRequestModel>()));
        }
Exemplo n.º 5
0
        public async void All_Exists()
        {
            MessageControllerMockFacade mock = new MessageControllerMockFacade();
            var record  = new ApiMessageServerResponseModel();
            var records = new List <ApiMessageServerResponseModel>();

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

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

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()));
        }
Exemplo n.º 6
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiMessageServerRequestModel> patch)
        {
            ApiMessageServerResponseModel record = await this.MessageService.Get(id);

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

                UpdateResponse <ApiMessageServerResponseModel> result = await this.MessageService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }