public void GetImageAsByteArray_WhenCannotReadNewImageFromCacheAndCanReadFromWebCam_ReturnImageFromWebCam(int userId, int cacheUpdaterUserId) { // Arrange const string userUtc = "some_UTC_value"; _dateTimeProvider.DateTimeNow.Returns(new DateTime(2019, 05, 01, 15, 30, 30, 100)); (int waitTimeMilliSec, string reason)valueTuple = (0, ""); _imageFromCacheService.WaitBeforeGettingNextImage(Arg.Any <int>(), Arg.Any <DateTime>()).Returns(valueTuple); _imageFromCacheService.GetNewImageAsByteArray(Arg.Any <int>(), Arg.Any <DateTime>()).Returns((byte[])null); _cacheUpdater.Update(userId: cacheUpdaterUserId, lastUpdate: DateTime.MinValue); var imageFromWebCam = new Bitmap(1, 1); byte[] imageArrayFromWebCam = ImageHelper.ConvertImageToByteArray(imageFromWebCam); _imageFromWebCamService.GetImage(Arg.Any <string>()).Returns(imageFromWebCam); IImageProviderService imageProviderService = CreateValidImageProviderService(); // Act bool canReadImageFromWebCam = imageProviderService.CanReadImageFromWebCam(userId, _dateTimeProvider.DateTimeNow); byte[] imageAsByteArray = imageProviderService.GetImageAsByteArray(userId, userUtc); // Assert Assert.That(canReadImageFromWebCam, Is.True); Assert.That(imageAsByteArray, Is.Not.Null); Assert.That(imageAsByteArray.Length, Is.EqualTo(imageArrayFromWebCam.Length)); Assert.That(_cacheUpdater.LastUpdate, Is.EqualTo(_dateTimeProvider.DateTimeNow)); Assert.That(_cacheUpdater.UserId, Is.EqualTo(userId)); }
private (byte[] imageByteArray, DateTime requestTime) ReadNewImageFromCache(int userId) { _imageFromCacheService.WaitBeforeGettingNextImage(userId: userId, timeRequested: GetLastCacheAccess(userId)); DateTime requestTime = _dateTimeProvider.DateTimeNow; byte[] imageByteArray = _imageFromCacheService.GetNewImageAsByteArray(userId: userId, timeRequested: requestTime); return(imageByteArray, requestTime); }