public void TargetMetadataAddsMissingProperties() { // Arrange var targetJson = new JObject(); targetJson["spec_version"] = 1; targetJson["foo"] = "bar"; var mHttp = new Mock<IHttpService>(); mHttp.Setup(i => i.DownloadText(It.IsAny<Uri>())) .Returns(targetJson.ToString()); var sut = new MetaNetkanTransformer(mHttp.Object); var json = new JObject(); json["spec_version"] = 1; json["$kref"] = "#/ckan/netkan/http://awesomemod.example/AwesomeMod.netkan"; // Act var result = sut.Transform(new Metadata(json)); var transformedJson = result.Json(); // Assert Assert.That((string)transformedJson["foo"], Is.EqualTo("bar"), "MetaNetkanTransformer add properties from target netkan that do not already exist." ); }
public void ThrowsWhenTargetIsAlsoMetaNetkan() { // Arrange var targetJson = new JObject(); targetJson["spec_version"] = 1; targetJson["$kref"] = "#/ckan/netkan/http://awesomemod.example/AwesomeMod.netkan"; var mHttp = new Mock<IHttpService>(); mHttp.Setup(i => i.DownloadText(It.IsAny<Uri>())) .Returns(targetJson.ToString()); var sut = new MetaNetkanTransformer(mHttp.Object); var json = new JObject(); json["spec_version"] = 1; json["$kref"] = "#/ckan/netkan/http://awesomemod.example/AwesomeMod.netkan"; // Act TestDelegate act = () => sut.Transform(new Metadata(json)); // Assert Assert.That(act, Throws.Exception.InstanceOf<Kraken>(), "MetaNetkanTransformer should throw if target is also a metanetkan." ); }
public void DoesNothingWhenNoMatch() { // Arrange var mHttp = new Mock<IHttpService>(); var sut = new MetaNetkanTransformer(mHttp.Object); var json = new JObject(); json["spec_version"] = 1; json["$kref"] = "#/ckan/foo"; // Act var result = sut.Transform(new Metadata(json)); var transformedJson = result.Json(); // Assert Assert.That(transformedJson, Is.EqualTo(json), "MetaNetkanTransformer should not modify metadata if it does not match." ); }
public void SelectsTheHigherSpecVresion(string specVersion, string targetSpecVersion, string expected) { // Arrange var targetJson = new JObject(); targetJson["spec_version"] = targetSpecVersion; var mHttp = new Mock<IHttpService>(); mHttp.Setup(i => i.DownloadText(It.IsAny<Uri>())) .Returns(targetJson.ToString()); var sut = new MetaNetkanTransformer(mHttp.Object); var json = new JObject(); json["spec_version"] = specVersion; json["$kref"] = "#/ckan/netkan/http://awesomemod.example/AwesomeMod.netkan"; // Act var result = sut.Transform(new Metadata(json)); var transformedJson = result.Json(); // Assert Assert.That((string)transformedJson["spec_version"], Is.EqualTo(expected), "MetaNetkanTransformer should select the higher of the two spec_versions." ); }