public void FindManifest_ThrowsIfNoDelegates()
 {
     Assert.Throws <InvalidOperationException>(
         () => ManifestLoader.FindManifest(new MockAssembly()),
         $"{nameof( ManifestLoader.ManifestLoaderDelegates )} was initialized with no pre-registered delegates, or the pre-defined delegates were removed and no alternatives were added."
         );
 }
        public void FindManifest_LoadsJsonManifest_Lowercase()
        {
            ManifestLoader.ManifestLoaderDelegates.Add(ManifestLoader.LoadJsonManifestFrom);
            var mockAssembly = new MockAssembly
            {
                MockManifestResourceInfo = new Dictionary <string, ManifestResourceInfo>
                {
                    {
                        @"manifest.json",
                        typeof(ManifestLoaderTest).Assembly.GetManifestResourceInfo(
                            $@"{VirtualTestManifest.Namespace}.manifest.lowercase.json"
                            )
                    }
                },
                MockManifestResourceStream = new Dictionary <string, Stream>
                {
                    {
                        @"manifest.json",
                        typeof(ManifestLoaderTest).Assembly.GetManifestResourceStream(
                            $@"{VirtualTestManifest.Namespace}.manifest.lowercase.json"
                            )
                    }
                }
            };

            var manifest = ManifestLoader.FindManifest(mockAssembly);

            Assert.IsTrue(manifest is JsonManifest);
            Assert.NotNull(manifest);
            Assert.AreEqual("Test Manifest", manifest.Name);
            Assert.AreEqual("AscensionGameDev.Intersect.Tests", manifest.Key);
            Assert.AreEqual(new SemVersion(1), manifest.Version);
            Assert.AreEqual("https://github.com/AscensionGameDev/Intersect-Engine", manifest.Homepage);
        }
Пример #3
0
        public void TestManifestDetection()
        {
            var manifestType   = typeof(Manifest);
            var pluginAssembly = manifestType.Assembly;
            var manifest       = ManifestLoader.FindManifest(pluginAssembly);

            Assert.NotNull(manifestType);
            Assert.IsInstanceOf(manifestType, manifest);
        }
        public void FindManifest_ReturnsNullWhenNoManifestsFound()
        {
            ManifestLoader.ManifestLoaderDelegates.Add(ManifestLoader.LoadJsonManifestFrom);
            ManifestLoader.ManifestLoaderDelegates.Add(ManifestLoader.LoadVirtualManifestFrom);
            var mockAssembly = new MockAssembly
            {
            };

            var manifest = ManifestLoader.FindManifest(mockAssembly);

            Assert.Null(manifest);
        }
        public void FindManifest_LoadsVirtualManifest()
        {
            ManifestLoader.ManifestLoaderDelegates.Add(ManifestLoader.LoadVirtualManifestFrom);
            var mockAssembly = new MockAssembly
            {
                MockTypes = new[] { typeof(VirtualTestManifest) }
            };

            var manifest = ManifestLoader.FindManifest(mockAssembly);

            Assert.IsTrue(manifest is VirtualTestManifest);
            Assert.NotNull(manifest);
            Assert.AreEqual("Test Manifest", manifest.Name);
            Assert.AreEqual("AscensionGameDev.Intersect.Tests", manifest.Key);
            Assert.AreEqual(new SemVersion(1), manifest.Version);
            Assert.AreEqual("https://github.com/AscensionGameDev/Intersect-Engine", manifest.Homepage);
        }
        public void FindManifest_LogsErrorsIfAnExceptionIsThrownByDelegate()
        {
            var mockLogger = new Mock <Logger>();

            Log.Default = mockLogger.Object;
            var mockException = new Exception("Delegate exception");

            ManifestLoader.ManifestLoaderDelegates.Add(( Assembly assembly ) => throw mockException);
            var mockAssembly = new MockAssembly
            {
            };

            var manifest = ManifestLoader.FindManifest(mockAssembly);

            Assert.Null(manifest);
            mockLogger.Verify(
                l => l.Error(
                    It.Is <Exception>(e => e.Message == mockException.Message),
                    "Exception thrown by manifest loader delegate."
                    )
                );
        }