public async void TestImport_RepositoryConsidered(string contents, string[] paths, bool[] results) { _importerAsync = new FakeFileInfoListImporterAsyncWithRepository(contents); ImportedFileInfo[] validFileInfos = paths.Select(x => new ImportedFileInfo { FilePath = x, FileType = "Test" }).ToArray(); await Task.WhenAll(Task.Run(() => _importerAsync.Import(validFileInfos)), Task.Delay(500)); string info = ""; for (int i = 0; i < paths.Length; i++) { ImportedFileInfo fileInfo = validFileInfos.ElementAt(i); Assert.AreEqual(fileInfo.FilePath, paths[i]); Assert.AreEqual(fileInfo.CurrentState, "已读取"); if (results[i]) { Assert.AreEqual(fileInfo.Result, "导入成功"); info += "\n" + fileInfo.FilePath + "完成导入数量:" + contents.Length; } else { Assert.AreEqual(fileInfo.Result, "无需导入"); info += "\n日期:" + fileInfo.FilePath.RetrieveFileNameBody().GetDateExtend().ToShortDateString() + "的统计记录已导入!"; } } Assert.AreEqual(_importerAsync.Result, info); }
public void AddSourceFile(string sourceId, IFileInfo file) { var sourceInfo = Sources.FirstOrDefault(info => info.SourceId == sourceId && info.FilePath == file.Path); if (sourceInfo == null) { sourceInfo = new ImportedFileInfo { FilePath = file.Path, SourceId = sourceId } } ; else { Sources.Remove(sourceInfo); } sourceInfo.LastChange = file.LastChange; Sources.Add(sourceInfo); }
public async void TestImport(string contents, string[] paths, string info) { _importerAsync = new FakeFileInfoListImporterAsync(contents); ImportedFileInfo[] validFileInfos = paths.Select(x => new ImportedFileInfo { FilePath = x, FileType = "Test" }).ToArray(); await Task.WhenAll(Task.Run(() => _importerAsync.Import(validFileInfos)), Task.Delay(300)); Assert.AreEqual(_importerAsync.Result, info); for (int i = 0; i < paths.Length; i++) { ImportedFileInfo fileInfo = validFileInfos.ElementAt(i); Assert.AreEqual(fileInfo.FilePath, paths[i]); Assert.AreEqual(fileInfo.CurrentState, "已读取"); Assert.AreEqual(fileInfo.Result, "导入成功"); } }