Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public static GameObject Load(ReferenceLoader referenceLoader)
        {
            Clear(referenceLoader);

            if (referenceLoader && referenceLoader.prefab)
            {
                return(Instantiate(referenceLoader.prefab, referenceLoader.transform));
            }

            return(null);
        }
Esempio n. 4
0
        public void ReferenceLoader_ShouldWillLoadModules_IfReferencedAssembliesAreNotLoaded()
        {
            // Given
            var loader = new ReferenceLoader <TestReferenceEvents>();

            // When
            var modules = loader.Load(new TestReferenceEvents());

            // Then
            Assert.Single(modules);
        }
Esempio n. 5
0
        public void ReferenceLoader_ShouldLoadModules_IfDefinedInCurrentAssembly()
        {
            // Given
            var loader = new ReferenceLoader <TestReferenceEvents>();

            // When
            var modules = loader.Load(new TestReferenceEvents());

            // Then
            Assert.Single(modules);
        }
Esempio n. 6
0
        public void ReferenceLoader_ShouldNotLoadModules_IfNoneInCurrentAssembly()
        {
            // Given
            var loader = new ReferenceLoader <TestReferenceEventsInvalid>();

            // When
            var modules = loader.Load(new TestReferenceEventsInvalid());

            // Then
            Assert.Empty(modules);
        }
Esempio n. 7
0
        public static void Clear(ReferenceLoader referenceLoader)
        {
            if (!referenceLoader)
            {
                return;
            }

            while (referenceLoader.transform.childCount > 0)
            {
                DestroyImmediate(referenceLoader.transform.GetChild(0).gameObject);
            }
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        /// <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);
        }
Esempio n. 12
0
        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);
            }
        }
Esempio n. 14
0
        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());
        }
Esempio n. 15
0
        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);
                }
            }
        }