Ejemplo n.º 1
0
        public virtual ApiShiftResponseModel MapBOToModel(
            BOShift boShift)
        {
            var model = new ApiShiftResponseModel();

            model.SetProperties(boShift.ShiftID, boShift.EndTime, boShift.ModifiedDate, boShift.Name, boShift.StartTime);

            return(model);
        }
Ejemplo n.º 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());
            ApiShiftResponseModel response = await client.ShiftGetAsync(1);

            response.Should().NotBeNull();
        }
Ejemplo n.º 3
0
        public async virtual Task <IActionResult> Get(int id)
        {
            ApiShiftResponseModel response = await this.ShiftService.Get(id);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Ejemplo n.º 4
0
        public async virtual Task <IActionResult> ByStartTimeEndTime(TimeSpan startTime, TimeSpan endTime)
        {
            ApiShiftResponseModel response = await this.ShiftService.ByStartTimeEndTime(startTime, endTime);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Ejemplo n.º 5
0
        public async virtual Task <IActionResult> ByName(string name)
        {
            ApiShiftResponseModel response = await this.ShiftService.ByName(name);

            if (response == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                return(this.Ok(response));
            }
        }
Ejemplo n.º 6
0
        public void MapResponseToRequest()
        {
            var mapper = new ApiShiftModelMapper();
            var model  = new ApiShiftResponseModel();

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

            response.EndTime.Should().Be(TimeSpan.Parse("0"));
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
            response.StartTime.Should().Be(TimeSpan.Parse("0"));
        }
Ejemplo n.º 7
0
        public void MapBOToModel()
        {
            var     mapper = new BOLShiftMapper();
            BOShift bo     = new BOShift();

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

            response.EndTime.Should().Be(TimeSpan.Parse("0"));
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Name.Should().Be("A");
            response.ShiftID.Should().Be(1);
            response.StartTime.Should().Be(TimeSpan.Parse("0"));
        }
Ejemplo 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());

            ApiShiftResponseModel model = await client.ShiftGetAsync(1);

            ApiShiftModelMapper mapper = new ApiShiftModelMapper();

            UpdateResponse <ApiShiftResponseModel> updateResponse = await client.ShiftUpdateAsync(model.ShiftID, mapper.MapResponseToRequest(model));

            updateResponse.Record.Should().NotBeNull();
            updateResponse.Success.Should().BeTrue();
        }
Ejemplo n.º 9
0
        public async void Get_null_record()
        {
            var mock = new ServiceMockFacade <IShiftRepository>();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <Shift>(null));
            var service = new ShiftService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.ShiftModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLShiftMapperMock,
                                           mock.DALMapperMockFactory.DALShiftMapperMock,
                                           mock.BOLMapperMockFactory.BOLEmployeeDepartmentHistoryMapperMock,
                                           mock.DALMapperMockFactory.DALEmployeeDepartmentHistoryMapperMock);

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

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Ejemplo n.º 10
0
        public async void ByStartTimeEndTime_Not_Exists()
        {
            var mock = new ServiceMockFacade <IShiftRepository>();

            mock.RepositoryMock.Setup(x => x.ByStartTimeEndTime(It.IsAny <TimeSpan>(), It.IsAny <TimeSpan>())).Returns(Task.FromResult <Shift>(null));
            var service = new ShiftService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.ShiftModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLShiftMapperMock,
                                           mock.DALMapperMockFactory.DALShiftMapperMock,
                                           mock.BOLMapperMockFactory.BOLEmployeeDepartmentHistoryMapperMock,
                                           mock.DALMapperMockFactory.DALEmployeeDepartmentHistoryMapperMock);

            ApiShiftResponseModel response = await service.ByStartTimeEndTime(default(TimeSpan), default(TimeSpan));

            response.Should().BeNull();
            mock.RepositoryMock.Verify(x => x.ByStartTimeEndTime(It.IsAny <TimeSpan>(), It.IsAny <TimeSpan>()));
        }
Ejemplo n.º 11
0
        public async void ByName_Exists()
        {
            var mock   = new ServiceMockFacade <IShiftRepository>();
            var record = new Shift();

            mock.RepositoryMock.Setup(x => x.ByName(It.IsAny <string>())).Returns(Task.FromResult(record));
            var service = new ShiftService(mock.LoggerMock.Object,
                                           mock.RepositoryMock.Object,
                                           mock.ModelValidatorMockFactory.ShiftModelValidatorMock.Object,
                                           mock.BOLMapperMockFactory.BOLShiftMapperMock,
                                           mock.DALMapperMockFactory.DALShiftMapperMock,
                                           mock.BOLMapperMockFactory.BOLEmployeeDepartmentHistoryMapperMock,
                                           mock.DALMapperMockFactory.DALEmployeeDepartmentHistoryMapperMock);

            ApiShiftResponseModel response = await service.ByName(default(string));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.ByName(It.IsAny <string>()));
        }
Ejemplo n.º 12
0
        public async void Create_Errors()
        {
            ShiftControllerMockFacade mock = new ShiftControllerMockFacade();

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

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

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

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiShiftRequestModel>()));
        }
Ejemplo n.º 13
0
        public async void All_Exists()
        {
            ShiftControllerMockFacade mock = new ShiftControllerMockFacade();
            var record  = new ApiShiftResponseModel();
            var records = new List <ApiShiftResponseModel>();

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

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

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

                UpdateResponse <ApiShiftResponseModel> result = await this.ShiftService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
Ejemplo n.º 15
0
        public async void TestGet()
        {
            ApiShiftResponseModel response = await this.Client.ShiftGetAsync(1);

            response.Should().NotBeNull();
        }