public void Test(TestJobHost <ConfigStream> host)
            {
                foreach (var funcName in new string[]
                {
                    "StreamRead", "StringRead", "ByteArrayRead", "TextReaderRead"
                })
                {
                    _log = null;
                    host.Call(funcName, new { k = 1 });
                    Assert.Equal("Hello", _log);
                }

                // Test writes. Verify the stream content.
                foreach (var funcName in new string[]
                {
                    "WriteStream",
                    "WriteStream2",
                    "WriteTextWriter1",
                    "WriteTextWriter2",
                    "WriteTextWriter3",
                    "WriteString",
                    "WriteByteArray"
                })
                {
                    _writeStream = null;
                    host.Call(funcName, new { k = funcName });

                    var content = _writeStream.ToArray(); // safe to call even after Dispose()
                    var str     = Encoding.UTF8.GetString(content);

                    // The comparison will also verify there is no BOM written.
                    Assert.Equal(_writeMessage, str);
                }
            }
            public void Test(TestJobHost <ConfigMultipleRules> host)
            {
                host.Call("Func", new { k = 1 });
                Assert.Equal("AlphaBuilder(1)", _log);

                host.Call("Func2", new { k = 1 });
                Assert.Equal("BetaBuilder(1)", _log);
            }
            public void Test(TestJobHost <ConfigWithConverters> host)
            {
                host.Call("Func1", new { k = 1 });
                Assert.Equal("GeneralBuilder_AlphaType(1)", _log);

                host.Call("Func2", new { k = 2 });
                Assert.Equal("A2B(GeneralBuilder_AlphaType(2))", _log);
            }
            public void Test(TestJobHost <ConfigExplicitObjectConverter> host)
            {
                // normal case
                host.Call("Func", new { k = 1 });
                Assert.Equal("GeneralBuilder_AlphaType(1)", _log);

                // use 1st rule with explicit converter
                host.Call("FuncObject", new { k = 1 });
                Assert.Equal("Alpha2Obj(GeneralBuilder_AlphaType(1))", _log);
            }
            public void Test(TestJobHost <ConfigTestDefaultToMethodName> host)
            {
                host.Call("Func", new { k = 1 });
                Assert.NotNull(_log);

                host.Call("Func2", new { k = 1 });
                Assert.Equal("Func2", _log);

                host.Call("FuncRename", new { k = 1 });
                Assert.Equal("newname", _log);
            }
            public void Test(TestJobHost <ConfigCustom> host)
            {
                host.Call("Read");
                Assert.Equal(_log, ReadTag);

                host.Call("Write");

                var content = _writeStream.ToArray(); // safe to call even after Dispose()
                var str     = Encoding.UTF8.GetString(content);

                Assert.Equal("yya", str);
            }
            public void Test(TestJobHost <ConfigObjectInheritence> host)
            {
                // 1st rule
                host.Call("FuncDerived", new { k = 1 });
                Assert.Equal("GeneralBuilder_AlphaDerivedType(1)", _log);

                // 1st rule + implicit converter
                host.Call("Func", new { k = 1 });
                Assert.Equal("GeneralBuilder_AlphaDerivedType(1)", _log);

                // 2nd rule, object isn't matched in an inheritence converter
                host.Call("FuncObject", new { k = 1 });
                Assert.Equal("[obj!]", _log);
            }
            public void Test(TestJobHost <ConfigNotExist> host)
            {
                host.Call("Read1");
                Assert.Null(_log);

                host.Call("Read2");
                Assert.Null(_log);

                host.Call("Read3");
                Assert.Null(_log);

                host.Call("Read4");
                Assert.Null(_log);
            }
            public void Test(TestJobHost <ConfigAutoResolve> host)
            {
                host.Call("Read", new { x = 456 });
                // Convert was never called

                Assert.Equal("456-123", _log);
            }
        public void Test()
        {
            MyProg prog      = new MyProg();
            var    activator = new FakeActivator();

            activator.Add(prog);

            JobHostConfiguration config = TestHelpers.NewConfig <MyProg>(activator);

            var ext = new TestExtension();

            config.AddExtension(ext);

            var host = new TestJobHost <MyProg>(config);
            IJobHostMetadataProvider metadataProvider = host.CreateMetadataProvider();

            Assert.Equal(1, ext._counter);

            // Callable
            host.Call("Test");
            Assert.Equal(1, ext._counter);

            // Fact that we registered a Widget converter is enough to add the assembly
            Assembly asm;
            bool     resolved;

            resolved = metadataProvider.TryResolveAssembly(typeof(Widget).Assembly.GetName().Name, out asm);
            Assert.True(resolved);
            Assert.Same(asm, typeof(Widget).Assembly);

            // check with full name
            resolved = metadataProvider.TryResolveAssembly(typeof(Widget).Assembly.GetName().FullName, out asm);
            Assert.True(resolved);
            Assert.Same(asm, typeof(Widget).Assembly);

            // This requires the target attribute to be unique within the assembly.
            var attrType = metadataProvider.GetAttributeTypeFromName("Test9");

            Assert.Equal(typeof(Test9Attribute), attrType);

            // JObject --> Attribute
            var attr = GetAttr <Test9Attribute>(metadataProvider, new { Flag = "xyz" });

            Assert.Equal("xyz", attr.Flag);

            // Getting default type.
            var defaultType = metadataProvider.GetDefaultType(attr, FileAccess.Read, null);

            Assert.Equal(typeof(JObject), defaultType);

            // If we have no match for output, we'll try IAsyncCollector<string>
            Assert.Equal(typeof(IAsyncCollector <string>), metadataProvider.GetDefaultType(attr, FileAccess.Write, typeof(object)));
        }
Пример #11
0
        public void Test()
        {
            MyProg prog      = new MyProg();
            var    activator = new FakeActivator();

            activator.Add(prog);

            JobHostConfiguration config = TestHelpers.NewConfig <MyProg>(activator);

            var ext = new TestExtension();

            config.AddExtension(ext);

            IJobHostMetadataProvider tooling = config.CreateMetadataProvider();

            Assert.Equal(1, ext._counter);

            // Callable
            var host = new TestJobHost <MyProg>(config);

            host.Call("Test");
            Assert.Equal(1, ext._counter);

            // Fact that we registered a Widget converter is enough to add the assembly
            Assembly asm;
            bool     resolved;

            resolved = tooling.TryResolveAssembly(typeof(Widget).Assembly.GetName().Name, out asm);
            Assert.True(resolved);
            Assert.Same(asm, typeof(Widget).Assembly);

            // check with full name
            resolved = tooling.TryResolveAssembly(typeof(Widget).Assembly.GetName().FullName, out asm);
            Assert.True(resolved);
            Assert.Same(asm, typeof(Widget).Assembly);

            var attrType = tooling.GetAttributeTypeFromName("Test");

            Assert.Equal(typeof(TestAttribute), attrType);

            // JObject --> Attribute
            var attr = GetAttr <TestAttribute>(tooling, new { Flag = "xyz" });

            Assert.Equal("xyz", attr.Flag);

            // Getting default type.
            var defaultType = tooling.GetDefaultType(attr, FileAccess.Read, null);

            Assert.Equal(typeof(JObject), defaultType);

            Assert.Throws <InvalidOperationException>(() => tooling.GetDefaultType(attr, FileAccess.Write, typeof(object)));
        }
            public void Test(TestJobHost <ConfigCollector <TParam> > host)
            {
                // tells you we made 2 AddAysnc calls, and invoked the converter on each item.
                _log = "";
                host.Call("Func2", new { k = 1 });

                if (typeof(TParam) == typeof(NonArrayOpenType))
                {
                    // Each object gets converter, so object[] gets converterd to multiple types.
                    Assert.Equal("Collector(Json(123));Collector(Json(\"xyz\"));", _log);
                }
                else
                {
                    // the object[] gets converters to a single element to a single object
                    Assert.Equal("Collector(Json([123,\"xyz\"]));", _log);
                }

                // 2 calls, but no converters
                _log = "";
                host.Call("Func", new { k = 1 });
                Assert.Equal("Collector(v1);Collector(v2);", _log);
            }
Пример #13
0
        public void Table_IfBoundToICollectorJObject__WithAttrKeys_AddInsertsEntity()
        {
            // Arrange
            const string    expectedValue = "abcdef";
            IStorageAccount account       = CreateFakeStorageAccount();
            var             config        = TestHelpers.NewConfig(typeof(BindToICollectorJObjectProgramKeysInAttr), account);

            // Act
            var host = new TestJobHost <BindToICollectorJObjectProgramKeysInAttr>(config);

            host.Call("Run");

            // Assert
            AssertStringProperty(account, "ValueStr", expectedValue);
        }
Пример #14
0
        public void Table_IfBoundToCustomTableBindingExtension_BindsCorrectly()
        {
            // Arrange
            IStorageAccount account = CreateFakeStorageAccount();

            var ext = new TableConverter();

            var config = TestHelpers.NewConfig(typeof(CustomTableBindingExtensionProgram), account, ext);

            var cm = (ConverterManager)config.GetService <IConverterManager>();

            var host = new TestJobHost <CustomTableBindingExtensionProgram>(config);

            host.Call("Run"); // Act

            // Assert
            Assert.Equal(TableName, CustomTableBinding <Poco> .Table.Name);
            Assert.True(CustomTableBinding <Poco> .AddInvoked);
            Assert.True(CustomTableBinding <Poco> .DeleteInvoked);
        }
Пример #15
0
        public void Table_IfBoundToCustomTableBindingExtension_BindsCorrectly()
        {
            // Arrange
            IStorageAccount account = CreateFakeStorageAccount();

            var config = TestHelpers.NewConfig(typeof(CustomTableBindingExtensionProgram), account);

            IConverterManager cm = config.GetService <IConverterManager>();

            // Add a rule for binding CloudTable --> CustomTableBinding<TEntity>
            cm.AddConverter <CloudTable, CustomTableBinding <OpenType>, TableAttribute>(
                typeof(CustomTableBindingConverter <>));

            var host = new TestJobHost <CustomTableBindingExtensionProgram>(config);

            host.Call("Run"); // Act

            // Assert
            Assert.Equal(TableName, CustomTableBinding <Poco> .Table.Name);
            Assert.True(CustomTableBinding <Poco> .AddInvoked);
            Assert.True(CustomTableBinding <Poco> .DeleteInvoked);
        }
 public void Test(TestJobHost <ConfigConcreteTypeNoConverter> host)
 {
     host.Call("Func", new { k = 1 });
     Assert.Equal("AlphaBuilder(1)", _log);
 }
Пример #17
0
 public void Test(TestJobHost <ConfigNullOutParam> host)
 {
     host.Call("WriteString");
     // Convert was never called
 }