Exemplo n.º 1
0
        public async void TestDelete()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            var createModel = new ApiMessageRequestModel();

            createModel.SetProperties("B", 1);
            CreateResponse <ApiMessageResponseModel> createResult = await client.MessageCreateAsync(createModel);

            createResult.Success.Should().BeTrue();

            ApiMessageResponseModel getResponse = await client.MessageGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.MessageDeleteAsync(2);

            deleteResult.Success.Should().BeTrue();

            ApiMessageResponseModel verifyResponse = await client.MessageGetAsync(2);

            verifyResponse.Should().BeNull();
        }
Exemplo n.º 2
0
        public virtual ApiMessageResponseModel MapBOToModel(
            BOMessage boMessage)
        {
            var model = new ApiMessageResponseModel();

            model.SetProperties(boMessage.MessageId, boMessage.Content, boMessage.SenderUserId);

            return(model);
        }
Exemplo n.º 3
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiMessageModelMapper();
            var model  = new ApiMessageResponseModel();

            model.SetProperties(1, "A", 1);
            ApiMessageRequestModel response = mapper.MapResponseToRequest(model);

            response.Content.Should().Be("A");
            response.SenderUserId.Should().Be(1);
        }
Exemplo n.º 4
0
        public async void TestGet()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());
            ApiMessageResponseModel response = await client.MessageGetAsync(1);

            response.Should().NotBeNull();
        }
Exemplo n.º 5
0
        public void MapBOToModel()
        {
            var       mapper = new BOLMessageMapper();
            BOMessage bo     = new BOMessage();

            bo.SetProperties(1, "A", 1);
            ApiMessageResponseModel response = mapper.MapBOToModel(bo);

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

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

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

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Exemplo n.º 8
0
        public async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());

            ApiMessageResponseModel model = await client.MessageGetAsync(1);

            ApiMessageModelMapper mapper = new ApiMessageModelMapper();

            UpdateResponse <ApiMessageResponseModel> updateResponse = await client.MessageUpdateAsync(model.MessageId, mapper.MapResponseToRequest(model));

            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
        }
Exemplo n.º 9
0
        public async void Create_Errors()
        {
            MessageControllerMockFacade mock = new MessageControllerMockFacade();

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

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

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiMessageRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiMessageResponseModel> >(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 ApiMessageRequestModel());

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

            records.Add(record);
            mock.ServiceMock.Setup(x => x.All(It.IsAny <int>(), It.IsAny <int>())).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);

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

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

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

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

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