Exemplo n.º 1
0
        public async Task Rehydrate_SettingsExist_ClearsQueueThenEnqueuesImages()
        {
            const string someJson = "Some persisted Json";

            A.CallTo(() => _persistence.LoadSettings(ImageQueuePersistenceKey)).Returns(someJson.Some());
            var imageIds = new[]
            {
                CreateImageId("1"),
                CreateImageId("2"),
                CreateImageId("3")
            };

            A.CallTo(() => _serializer.Deserialize(someJson)).Returns(imageIds);
            var savedImages = new[]
            {
                A.Dummy <ISavedImage>(),
                A.Dummy <ISavedImage>(),
                A.Dummy <ISavedImage>()
            };

            _fetchSavedImages = A.Fake <Func <SourceQualifiedImageId, ISavedImage> >();
            A.CallTo(() => _fetchSavedImages(imageIds[0])).Returns(savedImages[0]);
            A.CallTo(() => _fetchSavedImages(imageIds[1])).Returns(savedImages[1]);
            A.CallTo(() => _fetchSavedImages(imageIds[2])).Returns(savedImages[2]);

            await _sut.Rehydrade(_fetchSavedImages);

            A.CallTo(() => _innerQueue.Clear()).MustHaveHappened()
            .Then(A.CallTo(() => _innerQueue.Enqueue(A <IEnumerable <ISavedImage> > .That.IsSameSequenceAs(savedImages))).MustHaveHappened());
        }
Exemplo n.º 2
0
        public async Task Rehydrade(Func <SourceQualifiedImageId, ISavedImage> fetchSavedImages)
        {
            _logger.Information("Attempting to load queue");
            Option <string> persistedQueue = await _persistence.LoadSettings(SettingsKey);

            await persistedQueue.Match(async s =>
            {
                _logger.Information("Loaded queue json");
                IEnumerable <SourceQualifiedImageId> deserializedQueue = _imageQueueSerializer.Deserialize(s);
                _logger.Information("Queue deserialized");
                await _queue.Clear();
                await _queue.Enqueue(deserializedQueue.Select(fetchSavedImages));
            }, () =>
            {
                _logger.Information("Unable to load queue");
                return(TaskConstants.Completed);
            });
        }