public async Task StartProccess() { //Downloads images and saves to temp folder var dateNow = DateTime.Now; try { await _cameraImageDownloading.DownloadImagesFromCameraInfoSources(true, dateNow); //Sends all images to API and puts results in task list var fileToTaskMap = new Dictionary <FileSystemInfo, Task <InlineResponse200> >(); var images = _imageManipulator.GetTempFiles(); foreach (var file in images) { fileToTaskMap.Add(file, _openAlprWrapper.DetectPlateAsync(file.FullName)); } await ProcessResults(dateNow, fileToTaskMap); } finally { _imageManipulator.DeleteTempFiles(); } }
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); } }