コード例 #1
0
        public void GetCheckpoints_Success_Test()
        {
            // Arrange
            R_Checkpoint checkpoint = SampleCheckpoint(1);

            IList <R_Checkpoint> list = new List <R_Checkpoint>();

            list.Add(checkpoint);

            // create mock for repository
            var mock = new Mock <ICheckpointRepository>();

            mock.Setup(s => s.GetCheckpoints()).Returns(list);

            // service
            CheckpointService checkpointService = new CheckpointService();

            CheckpointService.Repository = mock.Object;

            // Act
            var           resultList = checkpointService.GetCheckpoints();
            CheckpointDTO result     = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.CheckpointId);
        }
コード例 #2
0
        public CheckpointDTO GetCheckpoint(int checkpointId)
        {
            try
            {
                //Requires.NotNegative("checkpointId", checkpointId);

                log.Debug("checkpointId: " + checkpointId + " ");

                // get
                R_Checkpoint t = Repository.GetCheckpoint(checkpointId);

                CheckpointDTO dto = new CheckpointDTO(t);

                log.Debug(CheckpointDTO.FormatCheckpointDTO(dto));

                return(dto);
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
コード例 #3
0
        public static R_Checkpoint ConvertDTOtoEntity(CheckpointDTO dto)
        {
            R_Checkpoint checkpoint = new R_Checkpoint();

            checkpoint.CheckpointId         = dto.CheckpointId;
            checkpoint.PlannedRouteId       = dto.PlannedRouteId;
            checkpoint.Name                 = dto.Name;
            checkpoint.OrderNumber          = dto.OrderNumber;
            checkpoint.Latitude             = dto.Latitude;
            checkpoint.Longitude            = dto.Longitude;
            checkpoint.AddressId            = dto.AddressId;
            checkpoint.EstimatedTimeArrival = dto.EstimatedTimeArrival;
            checkpoint.MinimumTime          = dto.MinimumTime;
            checkpoint.MaximumTime          = dto.MaximumTime;
            checkpoint.NucleoId             = dto.NucleoId;
            checkpoint.SupplierId           = dto.SupplierId;
            checkpoint.Active               = dto.Active;
            checkpoint.IsDeleted            = dto.IsDeleted;
            checkpoint.CreateBy             = dto.CreateBy;
            checkpoint.CreateOn             = dto.CreateOn;
            checkpoint.UpdateBy             = dto.UpdateBy;
            checkpoint.UpdateOn             = dto.UpdateOn;

            return(checkpoint);
        }
コード例 #4
0
        public void UpdateCheckpoint(R_Checkpoint t)
        {
            //Requires.NotNull(t);
            //Requires.PropertyNotNegative(t, "CheckpointId");

            t.Update();
        }
コード例 #5
0
        public int AddCheckpoint(CheckpointDTO dto)
        {
            int id = 0;

            try
            {
                log.Debug(CheckpointDTO.FormatCheckpointDTO(dto));

                R_Checkpoint t = CheckpointDTO.ConvertDTOtoEntity(dto);

                // add
                id = Repository.AddCheckpoint(t);
                dto.CheckpointId = id;

                log.Debug("result: 'success', id: " + id);
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }

            return(id);
        }
コード例 #6
0
        public R_Checkpoint GetCheckpoint(int checkpointId)
        {
            //Requires.NotNegative("checkpointId", checkpointId);

            R_Checkpoint t = R_Checkpoint.SingleOrDefault(checkpointId);

            return(t);
        }
コード例 #7
0
        public IEnumerable <R_Checkpoint> GetCheckpointListByPlannedRouteId(int itemId)
        {
            IEnumerable <R_Checkpoint> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_Checkpoint")
                      .Where("IsDeleted = 0 and PlannedRouteId = @0", itemId)
            ;

            results = R_Checkpoint.Query(sql);

            return(results);
        }
コード例 #8
0
        public IEnumerable <R_Checkpoint> GetCheckpoints()
        {
            IEnumerable <R_Checkpoint> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_Checkpoint")
                      .Where("IsDeleted = 0")

            ;

            results = R_Checkpoint.Query(sql);

            return(results);
        }
コード例 #9
0
        public IList <R_Checkpoint> GetCheckpoints(string searchTerm, int pageIndex, int pageSize)
        {
            IList <R_Checkpoint> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_Checkpoint")
                      .Where("IsDeleted = 0")
                      .Where(
                "Name like '%" + searchTerm + "%'"
                )
            ;

            results = R_Checkpoint.Fetch(pageIndex, pageSize, sql);

            return(results);
        }
コード例 #10
0
        public IEnumerable <R_Checkpoint> GetCheckpointListAdvancedSearch(
            int?plannedRouteId
            , string name
            , int?orderNumber
            , double?latitude
            , double?longitude
            , int?addressId
            , int?estimatedTimeArrival
            , System.DateTime?minimumTimeFrom
            , System.DateTime?minimumTimeTo
            , System.DateTime?maximumTimeFrom
            , System.DateTime?maximumTimeTo
            , int?nucleoId
            , int?supplierId
            , bool?active
            )
        {
            IEnumerable <R_Checkpoint> results = null;

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("R_Checkpoint")
                      .Where("IsDeleted = 0"
                             + (plannedRouteId != null ? " and PlannedRouteId = " + plannedRouteId : "")
                             + (name != null ? " and Name like '%" + name + "%'" : "")
                             + (orderNumber != null ? " and OrderNumber = " + orderNumber : "")
                             + (latitude != null ? " and Latitude like '%" + latitude + "%'" : "")
                             + (longitude != null ? " and Longitude like '%" + longitude + "%'" : "")
                             + (addressId != null ? " and AddressId like '%" + addressId + "%'" : "")
                             + (estimatedTimeArrival != null ? " and EstimatedTimeArrival = " + estimatedTimeArrival : "")
                             + (minimumTimeFrom != null ? " and MinimumTime >= '" + minimumTimeFrom.Value.ToShortDateString() + "'" : "")
                             + (minimumTimeTo != null ? " and MinimumTime <= '" + minimumTimeTo.Value.ToShortDateString() + "'" : "")
                             + (maximumTimeFrom != null ? " and MaximumTime >= '" + maximumTimeFrom.Value.ToShortDateString() + "'" : "")
                             + (maximumTimeTo != null ? " and MaximumTime <= '" + maximumTimeTo.Value.ToShortDateString() + "'" : "")
                             + (nucleoId != null ? " and NucleoId like '%" + nucleoId + "%'" : "")
                             + (supplierId != null ? " and SupplierId like '%" + supplierId + "%'" : "")
                             + (active != null ? " and Active = " + (active == true ? "1" : "0") : "")
                             )
            ;

            results = R_Checkpoint.Query(sql);

            return(results);
        }
コード例 #11
0
        // example data

        public static R_Checkpoint SampleCheckpoint(int id = 1)
        {
            R_Checkpoint checkpoint = new R_Checkpoint();

            // int
            checkpoint.CheckpointId = id;
            // int
            checkpoint.PlannedRouteId = 1;
            // string
            checkpoint.Name = "NameTestValue";
            // int
            checkpoint.OrderNumber = 1;
            // double?
            checkpoint.Latitude = 1;
            // double?
            checkpoint.Longitude = 1;
            // int?
            checkpoint.AddressId = 1;
            // int
            checkpoint.EstimatedTimeArrival = 1;
            // System.DateTime?
            checkpoint.MinimumTime = new System.DateTime();
            // System.DateTime?
            checkpoint.MaximumTime = new System.DateTime();
            // int?
            checkpoint.NucleoId = 1;
            // int?
            checkpoint.SupplierId = 1;
            // bool
            checkpoint.Active = false;
            // bool
            checkpoint.IsDeleted = false;
            // int?
            checkpoint.CreateBy = 1;
            // System.DateTime?
            checkpoint.CreateOn = new System.DateTime();
            // int?
            checkpoint.UpdateBy = 1;
            // System.DateTime?
            checkpoint.UpdateOn = new System.DateTime();

            return(checkpoint);
        }
コード例 #12
0
 public CheckpointDTO(R_Checkpoint checkpoint)
 {
     CheckpointId         = checkpoint.CheckpointId;
     PlannedRouteId       = checkpoint.PlannedRouteId;
     Name                 = checkpoint.Name;
     OrderNumber          = checkpoint.OrderNumber;
     Latitude             = checkpoint.Latitude;
     Longitude            = checkpoint.Longitude;
     AddressId            = checkpoint.AddressId;
     EstimatedTimeArrival = checkpoint.EstimatedTimeArrival;
     MinimumTime          = checkpoint.MinimumTime;
     MaximumTime          = checkpoint.MaximumTime;
     NucleoId             = checkpoint.NucleoId;
     SupplierId           = checkpoint.SupplierId;
     Active               = checkpoint.Active;
     IsDeleted            = checkpoint.IsDeleted;
     CreateBy             = checkpoint.CreateBy;
     CreateOn             = checkpoint.CreateOn;
     UpdateBy             = checkpoint.UpdateBy;
     UpdateOn             = checkpoint.UpdateOn;
 }
コード例 #13
0
        public void DeleteCheckpoint(CheckpointDTO dto)
        {
            try
            {
                log.Debug(CheckpointDTO.FormatCheckpointDTO(dto));

                R_Checkpoint t = CheckpointDTO.ConvertDTOtoEntity(dto);

                // delete
                Repository.DeleteCheckpoint(t);
                dto.IsDeleted = t.IsDeleted;

                log.Debug("result: 'success'");
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
コード例 #14
0
        public void GetCheckpoint_Success_Test()
        {
            // Arrange
            int          id         = 1;
            R_Checkpoint checkpoint = SampleCheckpoint(id);

            // create mock for repository
            var mock = new Mock <ICheckpointRepository>();

            mock.Setup(s => s.GetCheckpoint(Moq.It.IsAny <int>())).Returns(checkpoint);

            // service
            CheckpointService checkpointService = new CheckpointService();

            CheckpointService.Repository = mock.Object;

            // Act
            CheckpointDTO result = checkpointService.GetCheckpoint(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.CheckpointId);
        }
コード例 #15
0
        public void UpdateCheckpoint(CheckpointDTO dto)
        {
            try
            {
                //Requires.NotNull(t);
                //Requires.PropertyNotNegative(t, "CheckpointId");

                log.Debug(CheckpointDTO.FormatCheckpointDTO(dto));

                R_Checkpoint t = CheckpointDTO.ConvertDTOtoEntity(dto);

                // update
                Repository.UpdateCheckpoint(t);

                log.Debug("result: 'success'");
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
コード例 #16
0
        public int AddCheckpoint(R_Checkpoint t)
        {
            int id = (int)t.Insert();

            return(id);
        }
コード例 #17
0
 public void DeleteCheckpoint(R_Checkpoint t)
 {
     t.IsDeleted = true;
     t.Update();
 }