public void StaticChainrMethodInstantiator(string testCaseName)
        {
            var spec = GetJson($"chainr/specformat/{testCaseName}");

            FluentActions
            .Invoking(() => Chainr.FromSpec(spec, new DefaultChainrInstantiator()))     // should fail when parsing spec
            .Should().Throw <SpecException>();
        }
        public void StaticChainrMethodTransforms(string testCaseName)
        {
            var spec = GetJson($"chainr/specformat/{testCaseName}");

            FluentActions
            .Invoking(() => Chainr.FromSpec(spec, TestTransforms.Transforms))     // should fail when parsing spec
            .Should().Throw <SpecException>();
        }
Beispiel #3
0
        public void TestBadTransforms(string testCaseName)
        {
            var    spec = GetJson($"chainr/transforms/{testCaseName}");
            var    unit = Chainr.FromSpec(spec, TestTransforms.Transforms);
            Action a    = () => unit.Transform((JToken) new JObject(), null);// should fail here

            a.Should().Throw <TransformException>();
        }
        public void TestFails(int start, int end)
        {
            var    spec   = GetJson("chainr/increments/spec");
            var    chainr = Chainr.FromSpec(spec, TestTransforms.Transforms);
            Action a      = () => chainr.Transform(start, end, (JToken) new JObject());

            a.Should().Throw <TransformException>();
        }
        public void StaticChainrMethod(string testCaseName)
        {
            var spec = GetJson($"chainr/specloading/{testCaseName}");

            // should fail when parsing spec
            FluentActions
            .Invoking(() => Chainr.FromSpec(spec))
            .Should().Throw <SpecException>();
        }
Beispiel #6
0
        public void TestPassing(string testCaseName)
        {
            var    spec   = GetJson($"chainr/transforms/{testCaseName}");
            var    unit   = Chainr.FromSpec(spec, TestTransforms.Transforms);
            JToken input  = new JObject();
            var    result = unit.Transform(input, null);

            result["input"].Should().BeEquivalentTo(input);
            result["spec"].Should().NotBeNull();
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            var spec  = GetJson("spec.json");
            var input = GetJson("input.json");

            Chainr chainr            = Chainr.FromSpec(spec);
            var    transformedOutput = chainr.Transform(input);

            Console.WriteLine(transformedOutput.ToString());
        }
Beispiel #8
0
        public void process_itCallsShiftr()
        {
            var testCase = GetTestCase("shiftr/queryMappingXform");

            var chainrSpec = NewShiftrChainrSpec(testCase.Spec);

            Chainr unit   = Chainr.FromSpec(chainrSpec);
            var    actual = unit.Transform(testCase.Input, null);

            actual.Should().BeEquivalentTo(testCase.Expected);
        }
Beispiel #9
0
        public void process_itCallsRemover()
        {
            var testCase = GetTestCase("removr/firstSample");

            var chainrSpec = NewShiftrRemovrSpec(testCase.Spec);

            var unit   = Chainr.FromSpec(chainrSpec);
            var actual = unit.Transform(testCase.Input, null);

            actual.Should().BeEquivalentTo(testCase.Expected);
        }
Beispiel #10
0
        public void RunTest(string testCaseName, JToken spec, JToken input, JObject context, JToken expected)
        {
            Chainr unit = Chainr.FromSpec(spec, TestTransforms.Transforms);

            unit.HasContextualTransforms().Should().BeTrue();
            unit.GetContextualTransforms().Count.Should().Be(2);

            var actual = unit.Transform(input, context);

            actual.Should().BeEquivalentTo(expected);
        }
        public void TestChainrIncrementsTo(int end)
        {
            var spec = GetJson("chainr/increments/spec");

            var chainr = Chainr.FromSpec(spec, TestTransforms.Transforms);

            var expected = GetJson($"chainr/increments/0-{end}");

            var actual = chainr.Transform(end, (JToken) new JObject());

            actual.Should().BeEquivalentTo(expected);
        }
Beispiel #12
0
        public void process_itBlowsUp_fromTransform(Type transformType)
        {
            var spec       = NewCustomChainrSpec(transformType, null);
            var transforms = new Dictionary <string, Type>(ChainrEntry.STOCK_TRANSFORMS)
            {
                { transformType.Name, transformType }
            };
            Chainr unit = Chainr.FromSpec(spec, transforms);

            FluentActions
            .Invoking(() => unit.Transform(new JObject(), null))
            .Should().Throw <TransformException>();
        }
Beispiel #13
0
        public void process_itCallsSortr()
        {
            var input      = GetJson("sortr/simple/input");
            var expected   = GetJson("sortr/simple/output");
            var chainrSpec = NewShiftrSortrSpec(null);

            var unit   = Chainr.FromSpec(chainrSpec);
            var actual = unit.Transform(input, null);

            actual.Should().BeEquivalentTo(expected);

            String orderErrorMessage = SortrTest.VerifyOrder(actual, expected);

            orderErrorMessage.Should().BeNull(orderErrorMessage);
        }
Beispiel #14
0
        public void process_itCallsCustomTransform()
        {
            var spec          = NewChainrSpec();
            var delegateSpec  = new JObject();
            var transformType = typeof(GoodTestTransform);

            spec.Add(NewCustomActivity(transformType, delegateSpec));

            var transforms = new Dictionary <string, Type>(ChainrEntry.STOCK_TRANSFORMS)
            {
                { transformType.Name, transformType }
            };
            Chainr unit = Chainr.FromSpec(spec, transforms);

            var input  = new JObject();
            var actual = unit.Transform(input, null);

            input.Should().BeEquivalentTo(actual["input"]);
            delegateSpec.Should().BeEquivalentTo(actual["spec"]);
        }
Beispiel #15
0
        public void RunTestCases(string testCaseName, bool sorted)
        {
            var testCase = GetTestCase($"chainr/integration/{testCaseName}");

            var unit = Chainr.FromSpec(testCase.Spec);

            unit.HasContextualTransforms().Should().BeFalse();
            unit.GetContextualTransforms().Count.Should().Be(0);

            var actual = unit.Transform(testCase.Input, null);

            actual.Should().BeEquivalentTo(testCase.Expected);

            if (sorted)
            {
                // Make sure the sort actually worked.
                var orderErrorMessage = SortrTest.VerifyOrder(actual, testCase.Expected);
                orderErrorMessage.Should().BeNull(orderErrorMessage);
            }
        }
Beispiel #16
0
        public void TestReuseChainr()
        {
            // Spec which moves "attributeMap"'s keys to a root "attributes" list.
            var specShift = JObject.Parse(
                "{" +
                "'operation':'shift'," +
                "'spec' : { 'attributeMap' : { '*' : { '$' : 'attributes[#2]' } } }" +
                "}"
                );

            // Create a single Chainr from the spec
            Chainr chainr = Chainr.FromSpec(new JArray(specShift));

            // Test input with three attributes
            var content = JObject.Parse(
                "{ 'attributeMap' : { " +
                "'attribute1' : 1, 'attribute2' : 2, 'attribute3' : 3 }" +
                "}"
                );

            var transformed = chainr.Transform(content);

            // First time everything checks out
            transformed.Should().NotBeNull();
            transformed["attributes"].Should().BeEquivalentTo(new JArray("attribute1", "attribute2", "attribute3"));

            // Create a new identical input
            content = JObject.Parse(
                "{ 'attributeMap' : { " +
                "'attribute1' : 1, 'attribute2' : 2, 'attribute3' : 3 }" +
                "}"
                );

            // Create a new transform from the same Chainr
            transformed = chainr.Transform(content);
            transformed.Should().NotBeNull();

            // The following assert fails because attributes will have three leading null values:
            // transformedMap["attributes"] == [null, null, null, "attribute1", "attribute2", "attribute3"]
            transformed["attributes"].Should().BeEquivalentTo(new JArray("attribute1", "attribute2", "attribute3"));
        }
Beispiel #17
0
        public void process_itBlowsUp_fromSpec(JToken spec)
        {
            Action a = () => Chainr.FromSpec(spec);

            a.Should().Throw <SpecException>();
        }