コード例 #1
0
        private DeliveryReportDTO Create(DeliveryReportViewModel viewModel)
        {
            try
            {
                log.Debug(DeliveryReportViewModel.FormatDeliveryReportViewModel(viewModel));

                DeliveryReportDTO deliveryReport = new DeliveryReportDTO();

                // copy values
                viewModel.UpdateDTO(deliveryReport, null); //RequestContext.Principal.Identity.GetUserId());

                // audit
                deliveryReport.CreateBy = null; //RequestContext.Principal.Identity.GetUserId();
                deliveryReport.CreateOn = DateTime.UtcNow;

                // add
                log.Debug("_deliveryReportService.AddDeliveryReport - " + DeliveryReportDTO.FormatDeliveryReportDTO(deliveryReport));

                int id = _deliveryReportService.AddDeliveryReport(deliveryReport);

                deliveryReport.DeliveryReportId = id;

                log.Debug("result: 'success', id: " + id);

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

                throw;
            }
        }
コード例 #2
0
        public static DeliveryReportDTO SampleDeliveryReportDTO(int id = 1)
        {
            DeliveryReportDTO deliveryReport = new DeliveryReportDTO();

            // int
            deliveryReport.DeliveryReportId = id;
            // string
            deliveryReport.Name = "NameTestValue";
            // string
            deliveryReport.Description = "DescriptionTestValue";
            // System.DateTime?
            deliveryReport.ReportDate = new System.DateTime();
            // string
            deliveryReport.WeekDay = "WeekDayTestValue";
            // bool
            deliveryReport.Submitted = false;
            // bool
            deliveryReport.IsDeleted = false;
            // int?
            deliveryReport.CreateBy = 1;
            // System.DateTime?
            deliveryReport.CreateOn = new System.DateTime();
            // int?
            deliveryReport.UpdateBy = 1;
            // System.DateTime?
            deliveryReport.UpdateOn = new System.DateTime();

            return(deliveryReport);
        }
コード例 #3
0
        public void GetDeliveryReportsPaged_Success_Test()
        {
            // Arrange
            string searchTerm = "";
            int    pageIndex  = 0;
            int    pageSize   = 10;

            // list
            IList <R_DeliveryReport> list = new List <R_DeliveryReport>();

            for (int i = 1; i <= pageSize; i++)
            {
                list.Add(SampleDeliveryReport(i));
            }

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

            mock.Setup(s => s.GetDeliveryReports(Moq.It.IsAny <string>(), Moq.It.IsAny <int>(), Moq.It.IsAny <int>())).Returns(list);

            // service
            DeliveryReportService deliveryReportService = new DeliveryReportService();

            DeliveryReportService.Repository = mock.Object;

            // Act
            var resultList           = deliveryReportService.GetDeliveryReports(searchTerm, pageIndex, pageSize);
            DeliveryReportDTO result = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.DeliveryReportId);
            Assert.AreEqual(10, resultList.Count);
        }
コード例 #4
0
        public void GetDeliveryReports_Success_Test()
        {
            // Arrange
            R_DeliveryReport deliveryReport = SampleDeliveryReport(1);

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

            list.Add(deliveryReport);

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

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

            // service
            DeliveryReportService deliveryReportService = new DeliveryReportService();

            DeliveryReportService.Repository = mock.Object;

            // Act
            var resultList           = deliveryReportService.GetDeliveryReports();
            DeliveryReportDTO result = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.DeliveryReportId);
        }
コード例 #5
0
        public DeliveryReportDTO GetDeliveryReport(int deliveryReportId)
        {
            try
            {
                //Requires.NotNegative("deliveryReportId", deliveryReportId);

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

                // get
                R_DeliveryReport t = Repository.GetDeliveryReport(deliveryReportId);

                DeliveryReportDTO dto = new DeliveryReportDTO(t);

                log.Debug(DeliveryReportDTO.FormatDeliveryReportDTO(dto));

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

                throw;
            }
        }
コード例 #6
0
        public int AddDeliveryReport(DeliveryReportDTO dto)
        {
            int id = 0;

            try
            {
                log.Debug(DeliveryReportDTO.FormatDeliveryReportDTO(dto));

                R_DeliveryReport t = DeliveryReportDTO.ConvertDTOtoEntity(dto);

                // add
                id = Repository.AddDeliveryReport(t);
                dto.DeliveryReportId = id;

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

                throw;
            }

            return(id);
        }
コード例 #7
0
        public void GetDeliveryReportListAdvancedSearch_Success_Test()
        {
            // Arrange
            string name        = null;
            string description = null;

            System.DateTime?reportDateFrom = null;
            System.DateTime?reportDateTo   = null;
            string          weekDay        = null;
            bool?           submitted      = null;

            //int pageIndex = 0;
            int pageSize = 10;

            // list
            IList <R_DeliveryReport> list = new List <R_DeliveryReport>();

            for (int i = 1; i <= pageSize; i++)
            {
                list.Add(SampleDeliveryReport(i));
            }

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

            mock.Setup(s => s.GetDeliveryReportListAdvancedSearch(
                           Moq.It.IsAny <string>()             // name
                           , Moq.It.IsAny <string>()           // description
                           , Moq.It.IsAny <System.DateTime?>() // reportDateFrom
                           , Moq.It.IsAny <System.DateTime?>() // reportDateTo
                           , Moq.It.IsAny <string>()           // weekDay
                           , Moq.It.IsAny <bool?>()            // submitted
                           )).Returns(list);

            // service
            DeliveryReportService deliveryReportService = new DeliveryReportService();

            DeliveryReportService.Repository = mock.Object;

            // Act
            var resultList = deliveryReportService.GetDeliveryReportListAdvancedSearch(
                name
                , description
                , reportDateFrom
                , reportDateTo
                , weekDay
                , submitted
                );

            DeliveryReportDTO result = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.DeliveryReportId);
        }
コード例 #8
0
 public DeliveryReportViewModel(DeliveryReportDTO t)
 {
     DeliveryReportId = t.DeliveryReportId;
     Name             = t.Name;
     Description      = t.Description;
     ReportDate       = t.ReportDate;
     WeekDay          = t.WeekDay;
     Submitted        = t.Submitted;
     IsDeleted        = t.IsDeleted;
     CreateBy         = t.CreateBy;
     CreateOn         = t.CreateOn;
     UpdateBy         = t.UpdateBy;
     UpdateOn         = t.UpdateOn;
 }
コード例 #9
0
        public DeliveryReportDTO UpdateDTO(DeliveryReportDTO dto, int?updateBy)
        {
            if (dto != null)
            {
                dto.DeliveryReportId = this.DeliveryReportId;
                dto.Name             = this.Name;
                dto.Description      = this.Description;
                dto.ReportDate       = this.ReportDate;
                dto.WeekDay          = this.WeekDay;
                dto.Submitted        = this.Submitted;
                dto.IsDeleted        = this.IsDeleted;

                dto.UpdateBy = updateBy;
                dto.UpdateOn = System.DateTime.UtcNow;
            }

            return(dto);
        }
コード例 #10
0
        public void UpdateDeliveryReport_Success_Test()
        {
            // Arrange
            DeliveryReportDTO dto = SampleDeliveryReportDTO(1);

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

            mock.Setup(s => s.UpdateDeliveryReport(Moq.It.IsAny <R_DeliveryReport>())).Verifiable();

            // service
            DeliveryReportService deliveryReportService = new DeliveryReportService();

            DeliveryReportService.Repository = mock.Object;

            // Act
            deliveryReportService.UpdateDeliveryReport(dto);

            // Assert
            Assert.IsNotNull(dto);
        }
コード例 #11
0
        private DeliveryReportDTO Update(DeliveryReportViewModel viewModel)
        {
            try
            {
                log.Debug(DeliveryReportViewModel.FormatDeliveryReportViewModel(viewModel));

                // get
                log.Debug("_deliveryReportService.GetDeliveryReport - deliveryReportId: " + viewModel.DeliveryReportId + " ");

                var existingDeliveryReport = _deliveryReportService.GetDeliveryReport(viewModel.DeliveryReportId);

                log.Debug("_deliveryReportService.GetDeliveryReport - " + DeliveryReportDTO.FormatDeliveryReportDTO(existingDeliveryReport));

                if (existingDeliveryReport != null)
                {
                    // copy values
                    viewModel.UpdateDTO(existingDeliveryReport, null); //RequestContext.Principal.Identity.GetUserId());

                    // update
                    log.Debug("_deliveryReportService.UpdateDeliveryReport - " + DeliveryReportDTO.FormatDeliveryReportDTO(existingDeliveryReport));

                    _deliveryReportService.UpdateDeliveryReport(existingDeliveryReport);

                    log.Debug("result: 'success'");
                }
                else
                {
                    log.Error("existingDeliveryReport: null, DeliveryReportId: " + viewModel.DeliveryReportId);
                }

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

                throw;
            }
        }
コード例 #12
0
        public void AddDeliveryReport_Success_Test()
        {
            // Arrange
            DeliveryReportDTO dto = SampleDeliveryReportDTO(1);

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

            mock.Setup(s => s.AddDeliveryReport(Moq.It.IsAny <R_DeliveryReport>())).Returns(1);

            // service
            DeliveryReportService deliveryReportService = new DeliveryReportService();

            DeliveryReportService.Repository = mock.Object;

            // Act
            int id = deliveryReportService.AddDeliveryReport(dto);

            // Assert
            Assert.AreEqual(1, id);
            Assert.AreEqual(1, dto.DeliveryReportId);
        }
コード例 #13
0
        public void DeleteDeliveryReport(DeliveryReportDTO dto)
        {
            try
            {
                log.Debug(DeliveryReportDTO.FormatDeliveryReportDTO(dto));

                R_DeliveryReport t = DeliveryReportDTO.ConvertDTOtoEntity(dto);

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

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

                throw;
            }
        }
コード例 #14
0
        public void GetDeliveryReport_Success_Test()
        {
            // Arrange
            int id = 1;
            R_DeliveryReport deliveryReport = SampleDeliveryReport(id);

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

            mock.Setup(s => s.GetDeliveryReport(Moq.It.IsAny <int>())).Returns(deliveryReport);

            // service
            DeliveryReportService deliveryReportService = new DeliveryReportService();

            DeliveryReportService.Repository = mock.Object;

            // Act
            DeliveryReportDTO result = deliveryReportService.GetDeliveryReport(id);

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

                log.Debug(DeliveryReportDTO.FormatDeliveryReportDTO(dto));

                R_DeliveryReport t = DeliveryReportDTO.ConvertDTOtoEntity(dto);

                // update
                Repository.UpdateDeliveryReport(t);

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

                throw;
            }
        }