public void Wipe() { string testFolder = Path.Join(AppDomain.CurrentDomain.BaseDirectory, this.GetType().Name); if (Directory.Exists(testFolder)) { Directory.Delete(testFolder, true); } Directory.CreateDirectory(testFolder); Core.ITetriSettings settings = new Core.TetriSettings(new TestLogger <Core.TetriSettings>()) { TempPath = Path.Join(testFolder, "Temp") }; Directory.CreateDirectory(settings.TempPath); string testFilePath = Path.Join(settings.TempPath, "test"); File.WriteAllText(testFilePath, string.Empty); Core.ITagsService tagService = new Core.TagsService( settings, new TestLogger <Core.ITagsService>(), new Core.PackageListCache(MemoryCacheHelper.GetInstance())); Core.IIndexReader reader = new Core.IndexReader(settings, new Core.ThreadDefault(), tagService, new TestLogger <Core.IIndexReader>(), new FileSystem(), HashServiceHelper.Instance()); reader.Initialize(); Assert.False(File.Exists(testFilePath)); }
public void PurgeWithException() { IFileSystem fileSystem = Mock.Of <IFileSystem>(); Mock.Get(fileSystem).Setup(f => f.File.Delete(It.IsAny <string>())).Throws <IOException>(); IIndexReader indexReader = new Core.IndexReader(Settings, new ThreadDefault(), TagService, Logger, fileSystem, HashServiceHelper.Instance()); // force an archive and ensure that all archives will be purged Settings.MaxArchives = 0; File.WriteAllText(Path.Join(Settings.ArchivePath, "test"), string.Empty); indexReader.PurgeOldArchives(); // no assert! exception is throttled internally, we just need coverage here }
public void GetAfterWaiting() { // we need a valid package first TestPackage testPackage = PackageHelper.CreatePackage(this.Settings); // create a fake archive temp file so GetPackageAsArchive() goes into wait state string tempArchivePath = this.IndexReader.GetPackageArchiveTempPath(testPackage.Name); File.WriteAllText(tempArchivePath, string.Empty); // seeing as our fake temp archive bypasses archive creation, we should make a fake archive too, it should just be a file string archivePath = this.IndexReader.GetPackageArchivePath(testPackage.Name); File.WriteAllText(archivePath, "some-fake-archive-content"); // lock the temp archive so it doesn't get auto-clobbered using (Stream lockStream = new FileStream(tempArchivePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { // mock IThread.Sleep, in this method, we will release and delete our temp archive lock, so the archive fetch can proceed IThread mockThread = Mock.Of <IThread>(); Mock.Get(mockThread) .Setup(r => r.Sleep(It.IsAny <int>())) .Callback <int>(time => { lockStream.Close(); File.Delete(tempArchivePath); }); // make a custom reader with our mocked Thread IIndexReader indexReader = new Core.IndexReader(this.Settings, mockThread, this.TagService, this.Logger, new FileSystem(), HashServiceHelper.Instance()); using (Stream zipStream = indexReader.GetPackageAsArchive(testPackage.Name)) { // confirm we got our fake archive content back Assert.Equal("some-fake-archive-content", StreamsHelper.StreamToString(zipStream)); } } }