コード例 #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 ApiTicketStatuRequestModel();

            createModel.SetProperties("B");
            CreateResponse <ApiTicketStatuResponseModel> createResult = await client.TicketStatuCreateAsync(createModel);

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

            ApiTicketStatuResponseModel getResponse = await client.TicketStatuGetAsync(2);

            getResponse.Should().NotBeNull();

            ActionResponse deleteResult = await client.TicketStatuDeleteAsync(2);

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

            ApiTicketStatuResponseModel verifyResponse = await client.TicketStatuGetAsync(2);

            verifyResponse.Should().BeNull();
        }
コード例 #2
0
        public virtual ApiTicketStatuResponseModel MapBOToModel(
            BOTicketStatu boTicketStatu)
        {
            var model = new ApiTicketStatuResponseModel();

            model.SetProperties(boTicketStatu.Id, boTicketStatu.Name);

            return(model);
        }
コード例 #3
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiTicketStatuModelMapper();
            var model  = new ApiTicketStatuResponseModel();

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

            response.Name.Should().Be("A");
        }
コード例 #4
0
        public void MapBOToModel()
        {
            var           mapper = new BOLTicketStatuMapper();
            BOTicketStatu bo     = new BOTicketStatu();

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

            response.Id.Should().Be(1);
            response.Name.Should().Be("A");
        }
コード例 #5
0
        public async void TestGet()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());
            ApiTicketStatuResponseModel response = await client.TicketStatuGetAsync(1);

            response.Should().NotBeNull();
        }
コード例 #6
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiTicketStatuResponseModel response = await this.TicketStatuService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
コード例 #7
0
        public async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

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

            ApiTicketStatuResponseModel model = await client.TicketStatuGetAsync(1);

            ApiTicketStatuModelMapper mapper = new ApiTicketStatuModelMapper();

            UpdateResponse <ApiTicketStatuResponseModel> updateResponse = await client.TicketStatuUpdateAsync(model.Id, mapper.MapResponseToRequest(model));

            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
        }
コード例 #8
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <ITicketStatuRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <TicketStatu>(null));
            var service = new TicketStatuService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.TicketStatuModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLTicketStatuMapperMock,
                                                 mock.DALMapperMockFactory.DALTicketStatuMapperMock,
                                                 mock.BOLMapperMockFactory.BOLTicketMapperMock,
                                                 mock.DALMapperMockFactory.DALTicketMapperMock);

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

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

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

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

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

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

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

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

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

                UpdateResponse <ApiTicketStatuResponseModel> result = await this.TicketStatuService.Update(id, model);

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