Exemplo n.º 1
0
        public void DoesNotOverrideExistingProperties()
        {
            // Arrange
            const string filePath = "/DoesNotExist.zip";

            var internalCkan = new JObject();
            internalCkan["spec_version"] = 1;
            internalCkan["foo"] = "bar";

            var mHttp = new Mock<IHttpService>();
            var mModuleService = new Mock<IModuleService>();

            mHttp.Setup(i => i.DownloadPackage(It.IsAny<Uri>(), It.IsAny<string>()))
                .Returns(filePath);

            mModuleService.Setup(i => i.GetInternalCkan(filePath))
                .Returns(internalCkan);

            var sut = new InternalCkanTransformer(mHttp.Object, mModuleService.Object);

            var json = new JObject();
            json["spec_version"] = 1;
            json["foo"] = "baz";
            json["download"] = "https://awesomemod.example/AwesomeMod.zip";

            // Act
            var result = sut.Transform(new Metadata(json));
            var transformedJson = result.Json();

            // Assert
            Assert.That((string)transformedJson["foo"], Is.EqualTo("baz"),
                "InternalCkanTransformer should not override existing properties."
            );
        }
Exemplo n.º 2
0
        public void HigherOfTwoSpecVersionsIsChosen(
            string specVersion, string internalSpecVersion, string expectedSpecVersion
        )
        {
            // Arrange
            const string filePath = "/DoesNotExist.zip";

            var internalCkan = new JObject();
            internalCkan["spec_version"] = internalSpecVersion;

            var mHttp = new Mock<IHttpService>();
            var mModuleService = new Mock<IModuleService>();

            mHttp.Setup(i => i.DownloadPackage(It.IsAny<Uri>(), It.IsAny<string>()))
                .Returns(filePath);

            mModuleService.Setup(i => i.GetInternalCkan(filePath))
                .Returns(internalCkan);

            var sut = new InternalCkanTransformer(mHttp.Object, mModuleService.Object);

            var json = new JObject();
            json["spec_version"] = specVersion;
            json["download"] = "https://awesomemod.example/AwesomeMod.zip";

            // Act
            var result = sut.Transform(new Metadata(json));
            var transformedJson = result.Json();

            // Assert
            Assert.That((string)transformedJson["spec_version"], Is.EqualTo(expectedSpecVersion),
                "InternalCkanTransformer should use the higher of the two spec_versions."
            );
        }