Esempio n. 1
0
        public void DoesThrowWhenNoInstallableFiles()
        {
            // Arrange
            var mHttp          = new Mock <IHttpService>();
            var mModuleService = new Mock <IModuleService>();

            mModuleService.Setup(i => i.HasInstallableFiles(It.IsAny <CkanModule>(), It.IsAny <string>()))
            .Returns(false);

            var netkan = new JObject();

            netkan["spec_version"] = 1;
            netkan["identifier"]   = "AwesomeMod";

            var sut  = new CkanValidator(mHttp.Object, mModuleService.Object);
            var json = (JObject)ValidCkan.DeepClone();

            // Act
            TestDelegate act = () => sut.Validate(new Metadata(json));

            // Assert
            Assert.That(act, Throws.Exception,
                        "CkanValidator should throw when there are no files to install."
                        );
        }
Esempio n. 2
0
        public void DoesNotThrowOnValidCkan()
        {
            // Arrange
            var mHttp          = new Mock <IHttpService>();
            var mModuleService = new Mock <IModuleService>();

            mModuleService.Setup(i => i.HasInstallableFiles(It.IsAny <CkanModule>(), It.IsAny <string>()))
            .Returns(true);

            var netkan = new JObject();

            netkan["spec_version"] = 1;
            netkan["identifier"]   = "AwesomeMod";

            var sut  = new CkanValidator(new Metadata(netkan), mHttp.Object, mModuleService.Object);
            var json = (JObject)ValidCkan.DeepClone();

            // Act
            TestDelegate act = () => sut.Validate(new Metadata(json));

            // Assert
            Assert.That(act, Throws.Nothing,
                        "CkanValidator should not throw when passed valid metadata."
                        );
        }
Esempio n. 3
0
        public Inflator(string cacheDir, bool overwriteCache, string githubToken, bool prerelease)
        {
            log.Debug("Initializing inflator");
            cache = FindCache(
                new KSPManager(new ConsoleUser(false)),
                ServiceLocator.Container.Resolve <IConfiguration>(),
                cacheDir
                );

            IModuleService moduleService = new ModuleService();
            IFileService   fileService   = new FileService();

            http          = new CachingHttpService(cache, overwriteCache);
            ckanValidator = new CkanValidator(http, moduleService);
            transformer   = new NetkanTransformer(http, fileService, moduleService, githubToken, prerelease);
        }
Esempio n. 4
0
        public void DoesThrowWhenMissingProperty(string propertyName)
        {
            // Arrange
            var mHttp          = new Mock <IHttpService>();
            var mModuleService = new Mock <IModuleService>();

            mModuleService.Setup(i => i.HasInstallableFiles(It.IsAny <CkanModule>(), It.IsAny <string>()))
            .Returns(true);

            var sut  = new CkanValidator(mHttp.Object, mModuleService.Object);
            var json = (JObject)ValidCkan.DeepClone();

            json.Remove(propertyName);

            // Act
            TestDelegate act = () => sut.Validate(new Metadata(json));

            // Assert
            Assert.That(act, Throws.Exception,
                        string.Format("CkanValidator should throw when {0} is missing.", propertyName)
                        );
        }
Esempio n. 5
0
        public void DoesThrowWhenIdentifiersDoNotMatch()
        {
            // Arrange
            var mHttp          = new Mock <IHttpService>();
            var mModuleService = new Mock <IModuleService>();

            mModuleService.Setup(i => i.HasInstallableFiles(It.IsAny <CkanModule>(), It.IsAny <string>()))
            .Returns(true);

            var sut  = new CkanValidator(mHttp.Object, mModuleService.Object);
            var json = new JObject();

            json["spec_version"] = 1;
            json["identifier"]   = "AmazingMod";

            // Act
            TestDelegate act = () => sut.Validate(new Metadata(json));

            // Assert
            Assert.That(act, Throws.Exception,
                        "CkanValidator should throw when identifiers don't match."
                        );
        }