public string GenerateFilename(ImageSequence sequence) { // "Pleiades-16-01-01-192003_lum" Regex r = new Regex("[^a-zA-Z0-9-]"); var name = r.Replace(Name, "-"); return string.Format("{0}-{1}_{2}", name, DateTime.Now.ToString("yy-MM-dd__HH-mm-ssffff"), sequence.Extension); }
public async Task TestImagingServiceSequence() { var imageIoService = MockImageIoService(); var cameraService = MockCameraService(); var logService = MockLogService(); var systemEnv = new Mock<ISystemEnvironment>(); systemEnv.SetupGet(x => x.UserPicturesDirectory).Returns(Path.GetTempPath()); systemEnv.SetupGet(x => x.UserHomeDirectory).Returns(Path.GetTempPath()); systemEnv.SetupGet(x => x.TemporaryFilesDirectory).Returns(Path.GetTempPath()); cameraService.Setup(x => x.TakeExposure(It.IsAny<double>(), It.IsAny<bool>(), It.IsAny<bool>())) .ReturnsAsync(true) .Raises(x => x.OnExposureCompleted += null, true, new Exposure(800, 600, new int[0], 1, false)); var writerMoq = new Mock<IImageWriter>(); writerMoq.Setup(x => x.Save(It.IsAny<Exposure>(), It.IsAny<string>())); writerMoq.Setup(x => x.Save(It.IsAny<Exposure>(), It.IsAny<string>(), It.IsAny<Dictionary<string, object>>())); imageIoService.Setup(x => x.GetImageWriter(It.IsAny<ImageFileFormat>())).Returns(writerMoq.Object); var imagingService = new ImagingService(cameraService.Object, logService.Object, imageIoService.Object, systemEnv.Object); var session = new ImagingSession() { Name = "Test Session", SaveOutput = true, RepeatTimes = 2, PauseAfterEachRepeat = false, PauseAfterEachSequence = false }; var sequence1 = new ImageSequence() { BinXY = 4, ExposureDuration = 90, Extension = "test", FileFormat = imageIoService.Object.WritableFileFormats.First().Id, Name = "Sequence 1", NumExposures = 2 }; var sequence2 = new ImageSequence() { BinXY = 1, ExposureDuration = 10, Extension = "test", FileFormat = imageIoService.Object.WritableFileFormats.First().Id, Name = "Sequence 2", NumExposures = 2 }; session.ImageSequences.Add(sequence1); session.ImageSequences.Add(sequence2); imagingService.OnImagingSessionStarted += imagingSession => { Console.WriteLine(@"Imaging session started"); }; imagingService.OnImagingComplete += (successful, exposure) => { Console.WriteLine(@"Single exposure imaging complete, success: " + successful); Console.WriteLine(@"Exposure filename: " + session.GenerateFilename(imagingService.CurrentImageSequence)); }; imagingService.OnImagingSessionCompleted += (imagingSession, successfully, userCanceled) => { Console.WriteLine(@"Imaging session completed, success: " + successfully + @", was user canceled: " + userCanceled); }; await imagingService.RunImagingSession(session); // 2 x 2 x 2 images, verify. writerMoq.Verify(x => x.Save(It.IsAny<Exposure>(), It.IsAny<string>()), Times.Exactly(8)); // Asserts? }