コード例 #1
0
        private async Task ProcessResults(DateTime dateNow, Dictionary <FileSystemInfo, Task <InlineResponse200> > fileToTaskMap)
        {
            await Task.WhenAll(fileToTaskMap.Values);

            foreach (var fileTaskPair in fileToTaskMap)
            {
                var resultList = (await fileTaskPair.Value).Results;

                string newFileLocation = null;
                int    camId           = 0;
                var    file            = fileTaskPair.Key;
                if (0 != resultList.Count)
                {
                    newFileLocation = _imageManipulator.MoveFileToPerm(file, dateNow);
                    camId           = _fileNamer.ExtractCameraId(file.Name);
                }

                foreach (var result in resultList)
                {
                    var confidenceResult = result.Confidence ?? 0;
                    var fileApiPath      = _locationToUrl.ConvertPathToUrl(file.Name, dateNow);

                    try
                    {
                        _dlpHelper.InsertNewDetectedPlate(result.Plate, dateNow, camId, fileApiPath, decimal.ToDouble(confidenceResult));
                    }
                    catch
                    {
                        //Skip if error occurs while trying to store image
                        continue;
                    }
                }
            }
        }
コード例 #2
0
        public async Task StartProccess_WhenHappyPath_ShouldCallExpected()
        {
            //Arrange

            var returnedFiles = new List <FileSystemInfo>
            {
                BuildFakeFileSystemInfo("fullName0", "name0"),
                BuildFakeFileSystemInfo("fullName1", "name1")
            };

            A.CallTo(() => _fakeImageSaver.GetTempFiles())
            .Returns(returnedFiles);

            var alprResponses = GetAlprTestData();

            A.CallTo(() => _fakeOpenAlprWrapper.DetectPlateAsync(A <string> ._))
            .ReturnsNextFromSequence(alprResponses);

            var filePathAndCamId = new List <Tuple <string, int> >()
            {
                new Tuple <string, int>("0_location", 0),
                new Tuple <string, int>("1_location", 1)
            };

            A.CallTo(() => _fakeImageSaver.MoveFileToPerm(A <FileSystemInfo> .That.Matches(f => returnedFiles.Contains(f)), A <DateTime> ._))
            .ReturnsNextFromSequence(filePathAndCamId
                                     .Select(pc => pc.Item1)
                                     .ToArray());

            A.CallTo(() => _fakeFileNamer.ExtractCameraId(A <string> .That.Matches(fn => returnedFiles.Select(r => r.Name).Contains(fn))))
            .ReturnsNextFromSequence(filePathAndCamId
                                     .Select(pc => pc.Item2)
                                     .ToArray());

            var expectedApiUrl = "someUrl";

            A.CallTo(() => _fakeLocationUrlConverter.ConvertPathToUrl(A <string> .Ignored, A <DateTime> .Ignored))
            .Returns(expectedApiUrl);

            var dlpProcess = new DlpCollectionProcess(_fakeCameraImageDownloading, _fakeOpenAlprWrapper, _fakeDlpHelper, _fakeFileNamer, _fakeImageSaver, _fakeLocationUrlConverter);

            //Act
            await dlpProcess.StartProccess();

            //Assert
            A.CallTo(() => _fakeCameraImageDownloading.DownloadImagesFromCameraInfoSources(A <bool> ._, A <DateTime> ._))
            .MustHaveHappenedOnceExactly();

            A.CallTo(() => _fakeOpenAlprWrapper.DetectPlateAsync(A <string> ._))
            .MustHaveHappened(returnedFiles.Count, Times.Exactly);

            returnedFiles.ToList().ForEach(f =>
                                           A.CallTo(() => _fakeOpenAlprWrapper.DetectPlateAsync(f.FullName))
                                           .MustHaveHappenedOnceExactly());

            for (int i = 0; i < alprResponses.Count(); i++)
            {
                var plates      = alprResponses[i].Results.Select(r => r.Plate);
                var confidences = alprResponses[i].Results.Select(r => r.Confidence);
                var path        = filePathAndCamId[i].Item1;
                var camId       = filePathAndCamId[i].Item2;

                A.CallTo(() => _fakeDlpHelper.InsertNewDetectedPlate(
                             A <string> .That.Matches(s => plates.Contains(s)),
                             A <DateTime> ._,
                             camId,
                             expectedApiUrl,
                             A <double> .That.Matches(d => confidences.Select(dec => decimal.ToDouble(dec ?? 0m)).Contains(d))
                             )).MustHaveHappened(alprResponses[i].Results.Count(), Times.Exactly);
            }
        }