public void TestValidationError()
        {
            var nr = new FakeNameResolver().Add("x", "error");
            var host = TestHelpers.NewJobHost<Program>(nr, new FakeExtClient());

            TestHelpers.AssertIndexingError(() => host.Call("Func"), "Program.Func", FakeExtClient.IndexErrorMsg);
        }
        public void TestLocalValidatorSkipped()
        {
            // Local validator only run if we use the given rule.
            var nr = new FakeNameResolver().Add("k1", "v1");
            var host = TestHelpers.NewJobHost<LocalFunction1>(new FakeExtClient2(), nr);

            host.Call("NoValidation", new { k2 = "xxxx" }); // Succeeds since validate doesn't run on this rule
        }
        public void TestValidatorFails()
        {
            var nr = new FakeNameResolver().Add("k1", "v1");
            var host = TestHelpers.NewJobHost<BadFunction>(new FakeExtClient(), nr);

            TestHelpers.AssertIndexingError(
                () => host.Call("Valid"),
                "BadFunction.Bad", TestAttribute.ErrorMessage);
        }
        public void TestLocalValidatorApplied()
        {
            // Local validator only run if we use the given rule.
            var nr = new FakeNameResolver().Add("k1", "v1");
            var host = TestHelpers.NewJobHost<LocalFunction2>(new FakeExtClient2(), nr);

            TestHelpers.AssertIndexingError(
                () => host.Call("WithValidation"),
                "LocalFunction2.WithValidation", TestAttribute.ErrorMessage);
        }
        public void TestSkip()
        {
            var prog = new Program();
            var jobActivator = new FakeActivator();
            jobActivator.Add(prog);

            var nr = new FakeNameResolver().Add("x", "false");
            var host = TestHelpers.NewJobHost<Program>(nr, jobActivator, new FakeExtClient());
            host.Call("Func");

            // Skipped first rule, applied second 
            Assert.Equal(prog._value, "xxx");
        }
        public async Task InvokeString()
        {
            Attr1 a1 = new Attr1 { Path = "%test%" };

            Assert.Null(a1 as IAttributeInvokeDescriptor<Attr1>); // Does not implement the interface

            var nameResolver = new FakeNameResolver();
            nameResolver._dict["test"] = "ABC";

            var cloner = new AttributeCloner<Attr1>(a1, EmptyContract, nameResolver);
            Attr1 attr2 = await cloner.ResolveFromInvokeStringAsync("xy");

            Assert.Equal("xy", attr2.Path);
        }
        public void Setting()
        {
            Attr2 a2 = new Attr2(string.Empty, string.Empty) { ResolvedSetting = "appsetting" };

            var nameResolver = new FakeNameResolver().Add("appsetting", "ABC");
            var cloner = new AttributeCloner<Attr2>(a2, EmptyContract, nameResolver);

            var a2Cloned = cloner.GetNameResolvedAttribute();
            Assert.Equal("ABC", a2Cloned.ResolvedSetting);
        }
        public async Task NameResolver()
        {
            Attr1 a1 = new Attr1 { Path = "x%appsetting%y-{k}" };

            var nameResolver = new FakeNameResolver().Add("appsetting", "ABC");
            var cloner = new AttributeCloner<Attr1>(a1, GetBindingContract("k"), nameResolver);

            // Get the attribute with %% resolved (happens at indexing time), but not {} (not resolved until runtime)
            var attrPre = cloner.GetNameResolvedAttribute();
            Assert.Equal("xABCy-{k}", attrPre.Path);

            Dictionary<string, object> values = new Dictionary<string, object>()
            {
                { "k", "v" }
            };
            var ctx = GetCtx(values);
            var attr2 = await cloner.ResolveFromBindingDataAsync(ctx);

            Assert.Equal("xABCy-v", attr2.Path);
        }
 public void TestValidatorSucceeds()
 {
     var nr = new FakeNameResolver().Add("k1", "v1");
     var host = TestHelpers.NewJobHost<GoodFunction>(new FakeExtClient(), nr);
     host.Call("Good", new { k2 = "xxxx" } );
 }