Ejemplo n.º 1
0
        public void EditsCorrectlyWithString()
        {
            // Arrange
            var sut = new VersionEditTransformer();

            var json = new JObject();

            json["spec_version"]          = 1;
            json["version"]               = "v1.2.3";
            json["x_netkan_version_edit"] = "^v?(?<version>.+)$";

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

            // Assert
            Assert.That((string)transformedJson["version"], Is.EqualTo("1.2.3"));
        }
Ejemplo n.º 2
0
        public void DoesNothingWhenNoMatch()
        {
            // Arrange
            var sut = new VersionEditTransformer();

            var json = new JObject();

            json["spec_version"] = 1;
            json["version"]      = "1.2.3";

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

            // Assert
            Assert.That(transformedJson, Is.EqualTo(json),
                        "VersionEditTransformer should not modify metadata if it does not match."
                        );
        }
Ejemplo n.º 3
0
        public void ThrowsWhenNoMatchInStrictMode()
        {
            // Arrange
            var sut = new VersionEditTransformer();

            var edit = new JObject();

            edit["find"] = "^v(?<version>.+)$";

            var json = new JObject();

            json["spec_version"]          = 1;
            json["version"]               = "1.2.3";
            json["x_netkan_version_edit"] = edit;

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

            // Assert
            Assert.That(act, Throws.Exception.TypeOf <Kraken>());
        }
Ejemplo n.º 4
0
        public void DoesNotThrowWhenNoMatchInNonStrictMode()
        {
            // Arrange
            var sut = new VersionEditTransformer();

            var edit = new JObject();

            edit["find"]   = "^v(?<version>.+)$";
            edit["strict"] = false;

            var json = new JObject();

            json["spec_version"]          = 1;
            json["version"]               = "1.2.3";
            json["x_netkan_version_edit"] = edit;

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

            // Assert
            Assert.That(act, Throws.Nothing);
        }
Ejemplo n.º 5
0
        public void EditsCorrectlyWithFindAndReplace()
        {
            // Arrange
            var sut = new VersionEditTransformer();

            var edit = new JObject();

            edit["find"]    = "^v?(?<version>.+)$";
            edit["replace"] = "FOO-${version}-BAR";

            var json = new JObject();

            json["spec_version"]          = 1;
            json["version"]               = "v1.2.3";
            json["x_netkan_version_edit"] = edit;

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

            // Assert
            Assert.That((string)transformedJson["version"], Is.EqualTo("FOO-1.2.3-BAR"));
        }