public SpoolTestBase() { FilePathUtil.DeleteDirIfExist(Path.Combine(AppContext.BaseDirectory, "default-pool"), true); IServiceCollection services = new ServiceCollection(); services.AddLogging() .Configure <SpoolOptions>(options => { options.FilePools.ConfigureDefault(c => { c.Name = DefaultFilePool.Name; c.Path = Path.Combine(AppContext.BaseDirectory, "default-pool"); c.WriteBufferSize = 1024 * 1024 * 5; c.TrainMaxFileCount = 2; c.EnableFileWatcher = true; c.FileWatcherPath = Path.Combine(AppContext.BaseDirectory, "default-pool-watcher"); c.FileWatcherCopyThread = 2; c.ScanFileWatcherMillSeconds = 500; c.EnableAutoReturn = true; c.AutoReturnSeconds = 1; c.ScanReturnFileMillSeconds = 500; }); }) .AddSpool(); ServiceProvider = services.BuildServiceProvider(); }
public async Task WriteFile_GetFile_Test() { var configuration = _options.FilePools.GetConfiguration <DefaultFilePool>(); FilePathUtil.DeleteDirIfExist(configuration.Path, true); var filePool = _filePoolFactory.GetOrCreate <DefaultFilePool>(); var content = Encoding.UTF8.GetBytes("Hello,Spool Unit Test!"); var spoolFile1 = await filePool.WriteFileAsync(new MemoryStream(content), ".txt"); Assert.Equal(DefaultFilePool.Name, spoolFile1.FilePool); Assert.Equal(1, spoolFile1.TrainIndex); var testPath = PathUtil.MapPath("../../../test-files"); var file2 = Path.Combine(testPath, "t1.txt"); var spoolFile2 = await filePool.WriteFileAsync(file2); var pending1 = filePool.GetPendingCount(); Assert.Equal(2, pending1); var processing1 = filePool.GetProcessingCount(); Assert.Equal(0, processing1); //Write third var spoolFile3 = await filePool.WriteFileAsync(file2); var spoolFiles = filePool.GetFiles(2); Assert.Equal(2, spoolFiles.Count); var pending2 = filePool.GetPendingCount(); Assert.Equal(1, pending2); var processing2 = filePool.GetProcessingCount(); Assert.Equal(2, processing2); var spoolFile_q1 = spoolFiles.FirstOrDefault(x => x.Path == spoolFile1.Path); Assert.NotNull(spoolFile_q1); Assert.Equal("default", spoolFile_q1.FilePool); Assert.Equal(".txt", spoolFile_q1.FileExt); Assert.True(File.Exists(spoolFile_q1.Path)); var spoolFile_q2 = spoolFiles.FirstOrDefault(x => x.Path == spoolFile2.Path); Assert.NotNull(spoolFile_q2); Assert.Equal("default", spoolFile_q2.FilePool); Assert.Equal(".txt", spoolFile_q2.FileExt); Assert.True(File.Exists(spoolFile_q2.Path)); Assert.True(Directory.Exists(configuration.Path)); Directory.Delete(configuration.Path, true); }
public void CreateIfNotExists_Test() { var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "test01\\"); FilePathUtil.CreateIfNotExists(path); Assert.True(Directory.Exists(path)); FilePathUtil.CreateIfNotExists(path); FilePathUtil.DeleteDirIfExist(path, false); Assert.False(Directory.Exists(path)); }