public ReferenceLoaderTest() { AssemblyMock = new Mock <IAssemblyWrapper>(); AssemblyMock.Setup(a => a.GetManifestResourceNames()) .Returns(new string[0]); AssemblyMock.Setup(a => a.GetManifestResourceStream(It.IsAny <string>())) .Returns(new MemoryStream()); Loader = new ReferenceLoader(AssemblyMock.Object); }
public void SimpleReferenceUri() { var loader = new ReferenceLoader(); var r = loader.LoadReference(new YamlScalarNode("ref://test/x.dll")); r.Should().NotBeNull(); r.Should().HaveCount(1); r[0].Uri.Should().Be(new Uri("ref://test/x.dll")); r[0].Type.Should().Be(ReferenceType.Build); }
public static GameObject Load(ReferenceLoader referenceLoader) { Clear(referenceLoader); if (referenceLoader && referenceLoader.prefab) { return(Instantiate(referenceLoader.prefab, referenceLoader.transform)); } return(null); }
public void ReferenceLoader_ShouldWillLoadModules_IfReferencedAssembliesAreNotLoaded() { // Given var loader = new ReferenceLoader <TestReferenceEvents>(); // When var modules = loader.Load(new TestReferenceEvents()); // Then Assert.Single(modules); }
public void ReferenceLoader_ShouldLoadModules_IfDefinedInCurrentAssembly() { // Given var loader = new ReferenceLoader <TestReferenceEvents>(); // When var modules = loader.Load(new TestReferenceEvents()); // Then Assert.Single(modules); }
public void ReferenceLoader_ShouldNotLoadModules_IfNoneInCurrentAssembly() { // Given var loader = new ReferenceLoader <TestReferenceEventsInvalid>(); // When var modules = loader.Load(new TestReferenceEventsInvalid()); // Then Assert.Empty(modules); }
public static void Clear(ReferenceLoader referenceLoader) { if (!referenceLoader) { return; } while (referenceLoader.transform.childCount > 0) { DestroyImmediate(referenceLoader.transform.GetChild(0).gameObject); } }
public void ReferenceLoader_ShouldNotBindEvents_IfNoModulesAvailable() { // Given var loader = new ReferenceLoader <TestReferenceEventsInvalid>(); var events = new TestReferenceEventsInvalid(); // When var modules = loader.Load(events); //Then Assert.Null(events.MyEvent); }
public void AliasIsSpecialCase() { var loader = new ReferenceLoader(); var r = loader.LoadReference(new YamlScalarNode("alias://test")); r.Should().NotBeNull(); r.Should().HaveCount(2); r[0].Uri.Should().Be(new Uri("alias://test")); r[0].Type.Should().Be(ReferenceType.Build); r[1].Uri.Should().Be(new Uri("alias://test")); r[1].Type.Should().Be(ReferenceType.Runtime); }
public void ReferenceByUriMappingForm() { var loader = new ReferenceLoader(); var r = loader.LoadReference( new YamlMappingNode( new[] { new KeyValuePair <YamlNode, YamlNode>(new YamlScalarNode("uri"), new YamlScalarNode("ref://test/x.dll")) })); r.Should().NotBeNull(); r.Should().HaveCount(1); r[0].Uri.Should().Be(new Uri("ref://test/x.dll")); r[0].Type.Should().Be(ReferenceType.Build); }
/// <summary> /// 初始化一个<see cref="LoaderContext"/>类型的实例 /// </summary> public LoaderContext() { KeyLoader = new KeyLoader(); ReferenceLoader = new ReferenceLoader(); DbmsLoader = new DbmsLoader(); GroupLoader = new GroupLoader(); PhysicalDiagramLoader = new PhysicalDiagramLoader(); ViewLoader = new ViewLoader(); SchemaLoader = new SchemaLoader(); TargetModelLoader = new TargetModelLoader(); TableLoader = new TableLoader(KeyLoader); PackageLoader = new PackageLoader(TableLoader, ReferenceLoader); PdmLoader = new PdmLoader(this); }
public async Task Should_resolve_external_references() { var sut = new ReferenceLoader("./_yamlSamples/petshop_with_external.yaml", ReferenceLoaderStrategy.CopyRefContent); { var yaml = await sut.GetRefResolvedYamlAsync(); _output.WriteLine(yaml); yaml.Contains(Constants.REF_KEYWORD).ShouldBeFalse(); } { var json = await sut.GetRefResolvedJsonAsync(); _output.WriteLine(json); json.Contains(Constants.REF_KEYWORD).ShouldBeFalse(); } }
public async Task <JToken> LoadSchemaAsync(IEnumerable <string> documentUris, string?authorization) { var docs = documentUris.ToArray(); if (docs.Length == 1) { var loader = new ReferenceLoader(docs[0], ReferenceLoaderStrategy.CopyRefContent, authorization); var jObj = await loader.GetRefResolvedJObjectAsync(); return(jObj); } else { var merger = new OpenApiMerger(documentUris.Select(u => u.GetAbsoluteUri()).ToArray(), authorization: authorization); var jObj = await merger.GetMergedJObjectAsync(); return(jObj); } }
public async Task VeryTrickyTest() { var sut = new ReferenceLoader("./_yamlSamples/simple1.yaml", ReferenceLoaderStrategy.CopyRefContent); var yaml = await sut.GetRefResolvedYamlAsync(); yaml.InvariantNewline().ShouldBe( @"test: this: ""will load multiple files"" finalvalue: value: ""this is the real final value"" value: subvalue: value: ""this is the real final value"" x-fromRef: ""simple3.yaml#/subSubValue/value"" x-refName: ""value"" x-fromRef: ""simple2.json"" x-refName: """" ".InvariantNewline()); }
public async Task ResolveNested(string document, string expectedYaml) { var fileName = Path.GetTempFileName(); try { File.WriteAllText(fileName, document); var sut = new ReferenceLoader(fileName, ReferenceLoaderStrategy.CopyRefContent); var yaml = await sut.GetRefResolvedYamlAsync(); yaml.InvariantNewline().ShouldBe(expectedYaml.InvariantNewline()); } finally { if (File.Exists(fileName)) { File.Delete(fileName); } } }