/// <summary> /// Creates a package with some file data. /// </summary> /// <param name="settings"></param> /// <param name="packageName"></param> /// <returns></returns> public static TestPackage CreatePackage(ITetriSettings settings, string packageName) { // create package, files folder and item location in one byte[] content = Encoding.ASCII.GetBytes("some content"); TestPackage testPackage = new TestPackage { Content = content, Path = $"path/to/{packageName}", Hash = HashServiceHelper.Instance().FromByteArray(content), Name = packageName }; string filePathHash = HashServiceHelper.Instance().FromString(testPackage.Path); // create via workspace writer. Note that workspace has no logic of its own to handle hashing, it relies on whatever // calls it to do that. We could use PackageCreate to do this, but as we want to test PackageCreate with this helper // we keep this as low-level as possible IWorkspace workspace = new Core.Workspace(settings, new TestLogger <IWorkspace>(), HashServiceHelper.Instance()); workspace.Initialize(); workspace.AddIncomingFile(StreamsHelper.StreamFromBytes(testPackage.Content), testPackage.Path); workspace.WriteFile(testPackage.Path, testPackage.Hash, testPackage.Content.Length, testPackage.Name); workspace.WriteManifest(testPackage.Name, HashServiceHelper.Instance().FromString(filePathHash + testPackage.Hash)); return(testPackage); }
public (string, long) GetIncomingFileProperties(string path) { byte[] content = Incoming[path]; string hash = HashServiceHelper.Instance().FromByteArray(content); return(hash, content.Length); }
public void FromFile() { Directory.CreateDirectory(this.Settings.TempPath); string path = Path.Join(this.Settings.TempPath, "hashFromFileTest.txt"); File.WriteAllText(path, _input); Assert.Equal(_expectedHash, HashServiceHelper.Instance().FromFile(path).Item1); }
public void FromString() { Assert.Equal(_expectedHash, HashServiceHelper.Instance().FromString(_input)); }
public void FromByteArray() { byte[] input = Encoding.ASCII.GetBytes(_input); Assert.Equal(_expectedHash, HashServiceHelper.Instance().FromByteArray(input)); }
public FileSystemBase() { string testFolder = Path.Join(AppDomain.CurrentDomain.BaseDirectory, this.GetType().Name); if (Directory.Exists(testFolder)) { Directory.Delete(testFolder, true); } Directory.CreateDirectory(testFolder); Settings = new TetriSettings(new TestLogger <TetriSettings>()) { RepositoryPath = Path.Join(testFolder, "repository"), PackagePath = Path.Join(testFolder, "packages"), TempPath = Path.Join(testFolder, "temp"), ArchivePath = Path.Join(testFolder, "archives"), TagsPath = Path.Join(testFolder, "tags") }; Logger = new TestLogger <IIndexReader>(); TagService = new Core.TagsService( Settings, new TestLogger <ITagsService>(), new PackageListCache(MemoryCacheHelper.GetInstance())); IndexReader = new Core.IndexReader(Settings, new Core.ThreadDefault(), TagService, Logger, new FileSystem(), HashServiceHelper.Instance()); Thread.Sleep(200);// fixes race condition when scaffolding up index between consecutive tests IndexReader.Initialize(); }