Пример #1
0
        public async Task GetAvatarAsync_uses_inner_if_file_expired()
        {
            _fileInfo.Exists.Returns(true);
            _fileInfo.LastWriteTime.Returns(new DateTime(2010, 1, 1));
            _fileSystem.File.OpenWrite(Arg.Any <string>()).Returns(_ => new MemoryStream());
            _fileSystem.File.Delete(Arg.Any <string>());

            await MissAsync(_email1, _name1);

            _fileSystem.File.Received(1).Delete(Path.Combine(AppSettings.AvatarImageCachePath, $"{_email1}.{_size}px.png"));

            _file.OpenRead(Arg.Any <string>()).Returns(c => GetPngStream());
            _fileInfo.LastWriteTime.Returns(DateTime.Now);
            _fileSystem.ClearReceivedCalls();
            _fileInfo.ClearReceivedCalls();
            _file.ClearReceivedCalls();

            var image = await _cache.GetAvatarAsync(_email1, _name1, 16);

            image.Should().NotBeNull();
            _ = _fileInfo.Received(1).LastWriteTime;
            _fileSystem.File.Received(1).OpenRead(Path.Combine(AppSettings.AvatarImageCachePath, $"{_email1}.{_size}px.png"));
        }