public void CanReloadFile()
        {
            var fileInformation = new FileInformation(this.fileName, this.now);
            var expectedData = new FileInternalData(this.fileName, null);

            this.mockFileInternalDataExtractor
                .Setup(x => x.GetFileInternalData(this.fileName))
                .Returns(expectedData);

            FileInternalData data = this.cache.GetActualData(fileInformation);

            Assert.AreEqual(expectedData, data);

            var newFileInformation = new FileInformation(this.fileName, this.now.AddMinutes(1));
            var newExpectedData = new FileInternalData(this.fileName, null);

            this.mockFileInternalDataExtractor
                .Setup(x => x.GetFileInternalData(this.fileName))
                .Returns(newExpectedData);

            FileInternalData newData = this.cache.GetActualData(newFileInformation);

            Assert.AreEqual(newExpectedData, newData);

            this.mockFileInternalDataExtractor.Verify(x => x.GetFileInternalData(this.fileName), Times.Exactly(2));
        }
        public void CanUnderstandAddedFiles()
        {
            var fileInformation = new FileInformation(this.fileName, this.now);
            IEnumerable<FileState> filesState = this.cache.CheckLastChanged(new[] {fileInformation});

            Assert.IsNotNull(filesState);
            Assert.AreEqual(1, filesState.Count());
            FileState singleState = filesState.FirstOrDefault();
            Assert.AreEqual(fileInformation, singleState.FileInformation);
            Assert.AreEqual(FileChangingState.Added, singleState.FileChangingState);
        }
        public void CanLoadData()
        {
            var fileInformation = new FileInformation(this.fileName, this.now);
            var expectedData = new FileInternalData(this.fileName, null);

            this.mockFileInternalDataExtractor
                .Setup(x => x.GetFileInternalData(this.fileName))
                .Returns(expectedData);

            FileInternalData data = this.cache.GetActualData(fileInformation);
            Assert.AreEqual(expectedData, data);
        }
        /// <summary>
        ///     Вернуть актуальные данные по файлу на заданное время.
        /// </summary>
        /// <param name="fileInformation">Информация о файле.</param>
        /// <returns>Актуальные данные по файлу на заданное время.</returns>
        public FileInternalData GetActualData(FileInformation fileInformation)
        {
            string fileName = fileInformation.FileName;

            bool isNewFile = this.filesByDates.TryAdd(fileName, fileInformation.LastUpdateTime);

            if (isNewFile ||
                this.filesByDates[fileName] < fileInformation.LastUpdateTime ||
                !this.filesByNames.ContainsKey(fileName))
            {
                this.filesByNames[fileName] = this.fileInternalDataExtractor.GetFileInternalData(fileName);
            }

            return this.filesByNames[fileName];
        }
        /// <summary>
        ///     Вернуть актуальные данные по файлу на заданное время.
        /// </summary>
        /// <param name="fileInformation">Информация о файле.</param>
        /// <returns>Актуальные данные по файлу на заданное время.</returns>
        public FileInternalData GetActualData(FileInformation fileInformation)
        {
            if (fileInformation == null)
            {
                // добавить логирование. такого не должно быть никогда.
                throw new ArgumentException("Null file information");
            }

            this.filesByDates.TryAdd(fileInformation.FileName, new object());

            lock (this.filesByDates[fileInformation.FileName])
            {
                return this.cache.GetActualData(fileInformation);
            }
        }
 public void CanUnderstandNothingChanged()
 {
     var fileInformation = new FileInformation(this.fileName, this.now);
     this.cache.CheckLastChanged(new[] {fileInformation});
     IEnumerable<FileState> filesState = this.cache.CheckLastChanged(new[] {fileInformation});
     Assert.IsNotNull(filesState);
     Assert.IsFalse(filesState.Any());
 }
        public void DoesNotLoadSameFile()
        {
            var fileInformation = new FileInformation(this.fileName, this.now);
            var expectedData = new FileInternalData(this.fileName, null);

            this.mockFileInternalDataExtractor
                .Setup(x => x.GetFileInternalData(this.fileName))
                .Returns(expectedData);

            this.cache.GetActualData(fileInformation);
            FileInternalData data = this.cache.GetActualData(new FileInformation(this.fileName, this.now));
            Assert.AreEqual(expectedData, data);

            this.mockFileInternalDataExtractor.Verify(x => x.GetFileInternalData(this.fileName), Times.Once());
        }