public async Task Installed() { GivenContext( @"C:\VaM\Custom\Scripts\some-author\my-script\1.0.0\Script 1.cs", "class Script1 {}", new[] { TestFactory.RegFile("Script 1.cs", "64816EFE9CCFED7730C8FCF412178C23E5FE94304B7317ED03FE1D005C490C66") }, out var handler, out var context); var info = await handler.GetInstalledPackageInfoAsync(context); PartyAssertions.AreDeepEqual(new LocalPackageInfo { Corrupted = false, Installable = true, Installed = true, PackageFolder = @"C:\VaM\Custom\Scripts\some-author\my-script\1.0.0", Files = new[] { new InstalledFileInfo { FullPath = @"C:\VaM\Custom\Scripts\some-author\my-script\1.0.0\Script 1.cs", RegistryFile = context.Version.Files.First(), Status = FileStatus.Installed } } }, info); }
public async Task NotInstalled() { GivenContext( @"C:\VaM\Custom\Scripts\elsewhere\Script 1.cs", "class Script1 {}", new[] { new RegistryFile { Filename = "Script 1.cs", Hash = new RegistryHash { Type = Hashing.Type, Value = "64816EFE9CCFED7730C8FCF412178C23E5FE94304B7317ED03FE1D005C490C66" }, Url = "https://example.org/download/Script1%20.cs" } }, out var handler, out var context); var info = await handler.GetInstalledPackageInfoAsync(context); PartyAssertions.AreDeepEqual(new LocalPackageInfo { Corrupted = false, Installable = true, Installed = false, PackageFolder = @"C:\VaM\Custom\Scripts\some-author\my-script\1.0.0", Files = new[] { new InstalledFileInfo { FullPath = @"C:\VaM\Custom\Scripts\some-author\my-script\1.0.0\Script 1.cs", RegistryFile = context.Version.Files.First(), Status = FileStatus.NotInstalled } } }, info); }
public void CanFlagUntrustedDownloads() { var script1 = ResultFactory.RegScript("script1", ResultFactory.RegVer("1.0.0", ResultFactory.RegFile("My Script.cs", "12345", "https://example.com/scripts/MyScript.cs"))); var registry = ResultFactory.Reg(script1); var result = _handler.Search(registry, null, ""); PartyAssertions.AreDeepEqual(new[] { new SearchResult { Package = script1, Trusted = false } }, result); }
public void CanWorkWithoutQueryNorScenes() { var script1 = ResultFactory.RegScript("script1", ResultFactory.RegVer("1.0.0", ResultFactory.RegFile("My Script.cs", "12345", "https://example.org/scripts/MyScript.cs"))); var registry = ResultFactory.Reg(script1); var result = _handler.Search(registry, null, ""); PartyAssertions.AreDeepEqual(new[] { new SearchResult { Package = script1, Trusted = true } }, result); }
public async Task CanOverride() { var serializer = new Mock <IRegistrySerializer>(MockBehavior.Strict); using var httpStream = new MemoryStream(new byte[] { 123 }); serializer .Setup(x => x.Deserialize(It.Is <Stream>(s => s.ReadByte() == 123))) .Returns(TestFactory.Reg(TestFactory.RegScript("my-script", TestFactory.RegVer("1.0.0")))); var handler = new AcquireRegistryHandler( new HttpClient(MockHandler(("https://overridden.example.org/registry/v1/index.json", httpStream))), new[] { "https://example.org/registry/v1/index.json" }, serializer.Object); var registry = await handler.AcquireRegistryAsync(new[] { "https://overridden.example.org/registry/v1/index.json" }); PartyAssertions.AreDeepEqual( TestFactory.Reg(TestFactory.RegScript("my-script", TestFactory.RegVer("1.0.0"))), registry); }
public async Task CanMergeAsync() { var serializer = new Mock <IRegistrySerializer>(MockBehavior.Strict); using var httpStream1 = new MemoryStream(new byte[] { 1 }); using var httpStream2 = new MemoryStream(new byte[] { 2 }); serializer .Setup(x => x.Deserialize(It.Is <Stream>(s => s.ReadByte() == 1 || s.Seek(0, SeekOrigin.Begin) == -1))) .Returns(TestFactory.Reg( TestFactory.RegScript("common-script", TestFactory.RegVer("1.0.0")), TestFactory.RegScript("source1-script", TestFactory.RegVer("1.0.0")) )); serializer .Setup(x => x.Deserialize(It.Is <Stream>(s => s.ReadByte() == 2 || s.Seek(0, SeekOrigin.Begin) == -1))) .Returns(TestFactory.Reg( TestFactory.RegScript("common-script", TestFactory.RegVer("2.0.0")), TestFactory.RegScript("source2-script", TestFactory.RegVer("1.0.0")) )); var client = new HttpClient(MockHandler( ("https://source1.example.org/registry/v1/index.json", httpStream1), ("https://source2.example.org/registry/v1/index.json", httpStream2) )); var handler = new AcquireRegistryHandler( client, new[] { "https://source1.example.org/registry/v1/index.json", "https://source2.example.org/registry/v1/index.json" }, serializer.Object); var registry = await handler.AcquireRegistryAsync(null); Assert.That(registry.Packages.Select(p => p.Name), Is.EqualTo(new[] { "common-script", "source1-script", "source2-script" })); PartyAssertions.AreDeepEqual( TestFactory.Reg( TestFactory.RegScript("common-script", TestFactory.RegVer("1.0.0"), TestFactory.RegVer("2.0.0")), TestFactory.RegScript("source1-script", TestFactory.RegVer("1.0.0")), TestFactory.RegScript("source2-script", TestFactory.RegVer("1.0.0"))), registry); }
public void CanFilterScriptsByKeywords(string query) { var script1 = ResultFactory.RegScript("script1", ResultFactory.RegVer("1.0.0", ResultFactory.RegFile("My Script.cs", "12345", "https://example.org/scripts/MyScript.cs"))); var script2 = ResultFactory.RegScript("script2", ResultFactory.RegVer("1.0.0", ResultFactory.RegFile("Super Stuff.cs", "67890", "https://example.org/scripts/Super Stuff.cs"))); script2.Tags = new[] { "magic" }.ToList(); script2.Author = "John Doe"; script2.Description = "This is a script that makes stuff go boom!"; var registry = ResultFactory.Reg(script1, script2); var result = _handler.Search(registry, null, query); PartyAssertions.AreDeepEqual(new[] { new SearchResult { Package = script2, Trusted = true } }, result); }
public void CanSerializeAndDeserialize() { var registry = new Registry { Authors = new SortedSet <RegistryAuthor>(new[] { new RegistryAuthor { Name = "John Doe" } }), Packages = new SortedSet <RegistryPackage>(new[] { new RegistryPackage { Type = RegistryPackageType.Scripts, Name = "some-package", Tags = new List <string> { "tag1", "tag2" }, Versions = new SortedSet <RegistryPackageVersion>(new[] { new RegistryPackageVersion { Version = "1.0.0" } }) } }) }; var serialized = _serializer.Serialize(registry); using var stream = new MemoryStream(Encoding.UTF8.GetBytes(serialized)); var deserialized = _serializer.Deserialize(stream); PartyAssertions.AreDeepEqual(registry, deserialized); }
public void CanShowScenesUsage() { var regScript = ResultFactory.RegScript("script1", ResultFactory.RegVer("1.0.0", ResultFactory.RegFile("MyScript.cs", "12345", "https://example.org/scripts/MyScript.cs"))); var registry = ResultFactory.Reg(regScript); var saves = ResultFactory.SavesMap() .WithScript(new Script(@"C:\VaM\Saves\MyScript (Copy).cs", "12345"), out var saveScript) .Referencing(new Scene(@"C:\VaM\Saves\My Scene 1.json"), out var saveScene1) .WithScene(new Scene(@"C:\VaM\Saves\My Scene 2.json")) .Build(); var result = _handler.Search(registry, saves, ""); PartyAssertions.AreDeepEqual(new[] { new SearchResult { Package = regScript, Scripts = new[] { saveScript }, Scenes = new[] { saveScene1 }, Trusted = true } }, result); }