public void ValidatePicturesTest_ShouldReturnCorrectInvalidPictureCounts_And_ValidationResult()
        {
            //Arrange
            var bridgeDeckListDamageSummary = new List <DamageSummary>
            {
                new DamageSummary {
                    PictureNo = "855;858;875"
                }
            };
            var superSpaceListDamageSummary = new List <DamageSummary>
            {
                new DamageSummary {
                    PictureNo = "855;858;875x"
                }
            };
            var subSpaceListDamageSummary = new List <DamageSummary>
            {
                new DamageSummary {
                    PictureNo = "855;858y;875z"
                }
            };

            DamageSummaryServices.InitListDamageSummary(bridgeDeckListDamageSummary);
            DamageSummaryServices.InitListDamageSummary(superSpaceListDamageSummary, 2_000_000, BridgePart.SuperSpace);
            DamageSummaryServices.InitListDamageSummary(subSpaceListDamageSummary, 3_000_000, BridgePart.SubSpace);

            //Act
            int totalInvalidPictureCounts = PictureServices.ValidatePictures(bridgeDeckListDamageSummary, superSpaceListDamageSummary, subSpaceListDamageSummary, out List <string> bridgeDeckValidationResult, out List <string> superSpaceValidationResult, out List <string> subSpaceValidationResult);

            //Assert
            Assert.Equal(3, totalInvalidPictureCounts);
            Assert.Equal("上部结构,照片875x不存在", superSpaceValidationResult[0]);
        }
        public void ReturnNull_WhenValidIdParameterAndAdvertHasNotPictures()
        {
            var mockedRepository = new Mock <IRepository <Picture> >();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();
            var pictureService   = new PictureServices(mockedRepository.Object);

            int testAdvertId = 2;

            mockedRepository.Setup(rep => rep.All()).Returns(() => new List <Picture>()
            {
                new Picture()
                {
                    Id = 1, Name = "1.jpg", AdvertId = 1
                },
                new Picture()
                {
                    Id = 2, Name = "2.jpg"
                },
                new Picture()
                {
                    Id = 3, Name = "3.jpg", AdvertId = 1
                },
                new Picture()
                {
                    Id = 4, Name = "4.jpg"
                }
            }.AsQueryable());

            // Act
            var result = pictureService.GetFirstPicturesNameByAdvertId(testAdvertId);

            Assert.AreEqual(null, result);
        }
        public void ReturnCorrectString_WhenValidIdParameter()
        {
            var mockedRepository = new Mock <IRepository <Picture> >();
            var pictureService   = new PictureServices(mockedRepository.Object);

            int    advertId       = 1;
            string expectedResult = "1.jpg";

            mockedRepository.Setup(rep => rep.All()).Returns(() => new List <Picture>()
            {
                new Picture()
                {
                    Id = 1, Name = expectedResult, AdvertId = 1
                },
                new Picture()
                {
                    Id = 2, Name = "2.jpg"
                },
                new Picture()
                {
                    Id = 3, Name = "3.jpg", AdvertId = 1
                },
                new Picture()
                {
                    Id = 4, Name = "4.jpg"
                }
            }.AsQueryable());

            // Act
            var result = pictureService.GetFirstPicturesNameByAdvertId(advertId);

            Assert.AreEqual(expectedResult, result);
        }
Ejemplo n.º 4
0
        private void ValidatePictures_Click(object sender, RoutedEventArgs e)
        {
            var _bridgeDeckListDamageSummary = BridgeDeckGrid.ItemsSource as ObservableCollection <DamageSummary>;
            var _superSpaceListDamageSummary = SuperSpaceGrid.ItemsSource as ObservableCollection <DamageSummary>;
            var _subSpaceListDamageSummary   = SubSpaceGrid.ItemsSource as ObservableCollection <DamageSummary>;

            List <DamageSummary> l1 = _bridgeDeckListDamageSummary.ToList();
            List <DamageSummary> l2 = _superSpaceListDamageSummary.ToList();
            List <DamageSummary> l3 = _subSpaceListDamageSummary.ToList();

            DamageSummaryServices.InitListDamageSummary1(l1);
            DamageSummaryServices.InitListDamageSummary1(l2, 2_000_000);
            DamageSummaryServices.InitListDamageSummary1(l3, 3_000_000);

            int totalInvalidPictureCounts = PictureServices.ValidatePictures(l1, l2, l3, out List <string> bridgeDeckValidationResult, out List <string> superSpaceValidationResult, out List <string> subSpaceValidationResult);

            try
            {
                WriteInvalidPicturesResultToTxt(totalInvalidPictureCounts, bridgeDeckValidationResult, superSpaceValidationResult, subSpaceValidationResult);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw;
            }

            MessageBoxResult k = MessageBox.Show($"照片验证完成!其中无效照片共计{totalInvalidPictureCounts}张,结果详见根目录文件“无效照片列表.txt”");
        }
Ejemplo n.º 5
0
        public void ReturnCorrectPictureCount_WhenValidAdvertIdParameter()
        {
            var mockedRepository = new Mock <IRepository <Picture> >();
            var pictureService   = new PictureServices(mockedRepository.Object);

            int testAdvertId   = 1;
            var expectedResult = 2;

            mockedRepository.Setup(rep => rep.All()).Returns(() => new List <Picture>()
            {
                new Picture()
                {
                    Id = 1, Name = "1.jpg", AdvertId = 1
                },
                new Picture()
                {
                    Id = 2, Name = "2.jpg", AdvertId = 2
                },
                new Picture()
                {
                    Id = 3, Name = "3.jpg", AdvertId = 1
                },
                new Picture()
                {
                    Id = 4, Name = "4.jpg", AdvertId = 3
                }
            }.AsQueryable());

            // Act
            var result = pictureService.GetPicturesByAdvertId(testAdvertId);

            Assert.AreEqual(expectedResult, result.ToList().Count);
        }
Ejemplo n.º 6
0
        private static void GenerateReport(GenerateReportSettings generateReportSettings, bool CommentColumnInsertTable, double ImageWidth, double ImageHeight, string templateFile, string outputFile, int CompressImageFlag, ObservableCollection <DamageSummary> _bridgeDeckListDamageSummary, ObservableCollection <DamageSummary> _superSpaceListDamageSummary, ObservableCollection <DamageSummary> _subSpaceListDamageSummary)
        {
            var w = new ProgressBarWindow();

            w.Top  = 0.4 * (App.ScreenHeight - w.Height);
            w.Left = 0.4 * (App.ScreenWidth - w.Width);

            var progressBarModel = new ProgressBarModel
            {
                ProgressValue = 0
            };

            w.progressBarNumberTextBlock.DataContext = progressBarModel;
            w.progressBar.DataContext = progressBarModel;
            w.progressBarContentTextBlock.DataContext = progressBarModel;

            var progressSleepTime = 500;    //进度条停顿时间

            List <DamageSummary> l1 = _bridgeDeckListDamageSummary.ToList();
            List <DamageSummary> l2 = _superSpaceListDamageSummary.ToList();
            List <DamageSummary> l3 = _subSpaceListDamageSummary.ToList();

            DamageSummaryServices.InitListDamageSummary1(l1);
            DamageSummaryServices.InitListDamageSummary1(l2, 2_000_000);
            DamageSummaryServices.InitListDamageSummary1(l3, 3_000_000);

            var thread = new Thread(new ThreadStart(() =>
            {
                //progressBarModel.ProgressValue = 0;    //测试数据
                //生成报告前先验证照片的有效性
                int totalInvalidPictureCounts = PictureServices.ValidatePictures(l1, l2, l3, out List <string> bridgeDeckValidationResult, out List <string> superSpaceValidationResult, out List <string> subSpaceValidationResult);
                if (totalInvalidPictureCounts > 0)
                {
                    try
                    {
                        WriteInvalidPicturesResultToTxt(totalInvalidPictureCounts, bridgeDeckValidationResult, superSpaceValidationResult, subSpaceValidationResult);
                        MessageBox.Show($"存在无效照片,无法生成报告,共计{totalInvalidPictureCounts}张,详见根目录{App.InvalidPicturesStoreFile}");
                        return;
                    }
                    catch (Exception ex)
                    {
                        //MessageBox.Show(ex.Message);
                        //throw;
                    }
                }

                w.progressBar.Dispatcher.BeginInvoke((ThreadStart) delegate { w.Show(); });
                Document doc      = new Document(templateFile);
                var asposeService = new AsposeWordsServices(ref doc, generateReportSettings, l1, l2, l3);
                asposeService.GenerateReport(ref progressBarModel, CommentColumnInsertTable, ImageWidth, ImageHeight, CompressImageFlag);

                doc.Save(outputFile, SaveFormat.Docx);

                w.progressBar.Dispatcher.BeginInvoke((ThreadStart) delegate { w.Close(); });
                w.progressBar.Dispatcher.BeginInvoke((ThreadStart) delegate { MessageBox.Show("成功生成报告!"); });
            }));

            thread.Start();
        }
 public AccountController(AppDbContext context, IOptions <JwtSetting> options,
                          IWebHostEnvironment env)
 {
     this.context         = context;
     this.services        = new AccountServices(context, options);
     this.PictureServices = new PictureServices(context);
     this.hostingEnv      = env;
 }
Ejemplo n.º 8
0
 public PictureController(AppDbContext context)
 {
     this.context = context;
     services     = new PictureServices(context);
 }
 public PictureController()
 {
     _PictureServices = new PictureServices();
 }