Beispiel #1
0
        public virtual ApiDatabaseLogResponseModel MapBOToModel(
            BODatabaseLog boDatabaseLog)
        {
            var model = new ApiDatabaseLogResponseModel();

            model.SetProperties(boDatabaseLog.DatabaseLogID, boDatabaseLog.DatabaseUser, boDatabaseLog.@Event, boDatabaseLog.@Object, boDatabaseLog.PostTime, boDatabaseLog.Schema, boDatabaseLog.Tsql, boDatabaseLog.XmlEvent);

            return(model);
        }
Beispiel #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());
            ApiDatabaseLogResponseModel response = await client.DatabaseLogGetAsync(1);

            response.Should().NotBeNull();
        }
Beispiel #3
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiDatabaseLogResponseModel response = await this.DatabaseLogService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IDatabaseLogRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <DatabaseLog>(null));
            var service = new DatabaseLogService(mock.LoggerMock.Object,
                                                 mock.RepositoryMock.Object,
                                                 mock.ModelValidatorMockFactory.DatabaseLogModelValidatorMock.Object,
                                                 mock.BOLMapperMockFactory.BOLDatabaseLogMapperMock,
                                                 mock.DALMapperMockFactory.DALDatabaseLogMapperMock);

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
        public void MapResponseToRequest()
        {
            var mapper = new ApiDatabaseLogModelMapper();
            var model  = new ApiDatabaseLogResponseModel();

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

            response.DatabaseUser.Should().Be("A");
            [email protected]().Be("A");
            [email protected]().Be("A");
            response.PostTime.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Schema.Should().Be("A");
            response.Tsql.Should().Be("A");
            response.XmlEvent.Should().Be("A");
        }
        public void MapBOToModel()
        {
            var           mapper = new BOLDatabaseLogMapper();
            BODatabaseLog bo     = new BODatabaseLog();

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

            response.DatabaseLogID.Should().Be(1);
            response.DatabaseUser.Should().Be("A");
            [email protected]().Be("A");
            [email protected]().Be("A");
            response.PostTime.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Schema.Should().Be("A");
            response.Tsql.Should().Be("A");
            response.XmlEvent.Should().Be("A");
        }
Beispiel #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());

            ApiDatabaseLogResponseModel model = await client.DatabaseLogGetAsync(1);

            ApiDatabaseLogModelMapper mapper = new ApiDatabaseLogModelMapper();

            UpdateResponse <ApiDatabaseLogResponseModel> updateResponse = await client.DatabaseLogUpdateAsync(model.DatabaseLogID, mapper.MapResponseToRequest(model));

            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
        }
Beispiel #8
0
        public async void Create_Errors()
        {
            DatabaseLogControllerMockFacade mock = new DatabaseLogControllerMockFacade();

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

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

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

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiDatabaseLogRequestModel>()));
        }
Beispiel #9
0
        public async void All_Exists()
        {
            DatabaseLogControllerMockFacade mock = new DatabaseLogControllerMockFacade();
            var record  = new ApiDatabaseLogResponseModel();
            var records = new List <ApiDatabaseLogResponseModel>();

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

            items.Count.Should().Be(1);
            mock.ServiceMock.Verify(x => x.All(It.IsAny <int>(), It.IsAny <int>()));
        }
Beispiel #10
0
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiDatabaseLogRequestModel> patch)
        {
            ApiDatabaseLogResponseModel record = await this.DatabaseLogService.Get(id);

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

                UpdateResponse <ApiDatabaseLogResponseModel> result = await this.DatabaseLogService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public async void TestGet()
        {
            ApiDatabaseLogResponseModel response = await this.Client.DatabaseLogGetAsync(1);

            response.Should().NotBeNull();
        }