예제 #1
0
        public virtual ApiDocumentResponseModel MapBOToModel(
            BODocument boDocument)
        {
            var model = new ApiDocumentResponseModel();

            model.SetProperties(boDocument.Rowguid, boDocument.ChangeNumber, boDocument.Document1, boDocument.DocumentLevel, boDocument.DocumentSummary, boDocument.FileExtension, boDocument.FileName, boDocument.FolderFlag, boDocument.ModifiedDate, boDocument.Owner, boDocument.Revision, boDocument.Status, boDocument.Title);

            return(model);
        }
예제 #2
0
        public async void TestGet()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

            var client = new ApiClient(testServer.CreateClient());
            ApiDocumentResponseModel response = await client.DocumentGetAsync(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));

            response.Should().NotBeNull();
        }
        public async virtual Task <IActionResult> Get(Guid id)
        {
            ApiDocumentResponseModel response = await this.DocumentService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
예제 #4
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IDocumentRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <Guid>())).Returns(Task.FromResult <Document>(null));
            var service = new DocumentService(mock.LoggerMock.Object,
                                              mock.RepositoryMock.Object,
                                              mock.ModelValidatorMockFactory.DocumentModelValidatorMock.Object,
                                              mock.BOLMapperMockFactory.BOLDocumentMapperMock,
                                              mock.DALMapperMockFactory.DALDocumentMapperMock);

            ApiDocumentResponseModel response = await service.Get(default(Guid));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <Guid>()));
        }
예제 #5
0
        public async void TestUpdate()
        {
            var builder = new WebHostBuilder()
                          .UseEnvironment("Production")
                          .UseStartup <TestStartup>();
            TestServer testServer = new TestServer(builder);

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

            ApiDocumentResponseModel model = await client.DocumentGetAsync(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));

            ApiDocumentModelMapper mapper = new ApiDocumentModelMapper();

            UpdateResponse <ApiDocumentResponseModel> updateResponse = await client.DocumentUpdateAsync(model.Rowguid, mapper.MapResponseToRequest(model));

            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
        }
예제 #6
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiDocumentModelMapper();
            var model  = new ApiDocumentResponseModel();

            model.SetProperties(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), 1, BitConverter.GetBytes(1), 1, "A", "A", "A", true, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, "A", 1, "A");
            ApiDocumentRequestModel response = mapper.MapResponseToRequest(model);

            response.ChangeNumber.Should().Be(1);
            response.Document1.Should().BeEquivalentTo(BitConverter.GetBytes(1));
            response.DocumentLevel.Should().Be(1);
            response.DocumentSummary.Should().Be("A");
            response.FileExtension.Should().Be("A");
            response.FileName.Should().Be("A");
            response.FolderFlag.Should().Be(true);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Owner.Should().Be(1);
            response.Revision.Should().Be("A");
            response.Status.Should().Be(1);
            response.Title.Should().Be("A");
        }
예제 #7
0
        public async void Create_Errors()
        {
            DocumentControllerMockFacade mock = new DocumentControllerMockFacade();

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

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

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

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiDocumentRequestModel>()));
        }
예제 #8
0
        public async void All_Exists()
        {
            DocumentControllerMockFacade mock = new DocumentControllerMockFacade();
            var record  = new ApiDocumentResponseModel();
            var records = new List <ApiDocumentResponseModel>();

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

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
        public virtual async Task <IActionResult> Patch(Guid id, [FromBody] JsonPatchDocument <ApiDocumentRequestModel> patch)
        {
            ApiDocumentResponseModel record = await this.DocumentService.Get(id);

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

                UpdateResponse <ApiDocumentResponseModel> result = await this.DocumentService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
예제 #10
0
        public async void TestGet()
        {
            ApiDocumentResponseModel response = await this.Client.DocumentGetAsync(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));

            response.Should().NotBeNull();
        }