⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dotnetobjecttypetests.cs

📁 drools 一个开放源码的规则引擎
💻 CS
字号:
using System;
using NUnit.Framework;
using org.drools.rule;
using org.drools.semantics.@base;
using org.drools.semantics.dotnet;
using org.drools.smf;
using org.drools.spi;

namespace org.drools.dotnet.tests.semantics
{
    [TestFixture]
    public class DotNetObjectTypeTests
    {
        [Test]
        [ExpectedException(typeof(FactoryException), "No type name specified.")]
        public void TestWithMissingType()
        {
            RuleBaseContext ruleBaseContext = new RuleBaseContext();
            DefaultConfiguration configuration = new DefaultConfiguration("test1");
            RuleSet ruleSet = new RuleSet("test RuleSet", ruleBaseContext);
            Rule rule = new Rule("Test Rule 1", ruleSet);;

            Importer importer = new DotNetImporter();
            rule.setImporter(importer);

            ObjectTypeFactory factory = new DotNetObjectTypeFactory();
            ObjectType type = factory.newObjectType(rule, ruleBaseContext, configuration);
        }

        [Test]
        public void TestWithoutImports()
        {
            RuleBaseContext ruleBaseContext = new RuleBaseContext();
            DefaultConfiguration configuration = new DefaultConfiguration("test1");
            configuration.setText("System.Collections.Hashtable");

            RuleSet ruleSet = new RuleSet("test RuleSet", ruleBaseContext);
            Rule rule = new Rule("Test Rule 1", ruleSet);

			Importer importer = new DotNetImporter();
            rule.setImporter(importer);

			ObjectTypeFactory factory = new DotNetObjectTypeFactory();
			DotNetObjectType type = (DotNetObjectType) 
				factory.newObjectType(rule, ruleBaseContext, configuration);
            Assert.AreEqual(configuration.getText(), type.Type.FullName);
			Assert.IsTrue(type.matches(Activator.CreateInstance(Type.GetType(configuration.getText()))));
        }

		[Test]
		public void TestWithImports()
		{
			RuleBaseContext ruleBaseContext = new RuleBaseContext();
			DefaultConfiguration configuration = new DefaultConfiguration("test1");
			configuration.setText("Hashtable");

			RuleSet ruleSet = new RuleSet("test RuleSet", ruleBaseContext);
			Rule rule = new Rule("Test Rule 1", ruleSet);

			Importer importer = new DotNetImporter();
			importer.addImport(new BaseImportEntry("System.Collections"));
			rule.setImporter(importer);

			ObjectTypeFactory factory = new DotNetObjectTypeFactory();
			DotNetObjectType type = (DotNetObjectType) 
				factory.newObjectType(rule, ruleBaseContext, configuration);
			Assert.AreEqual("System.Collections.Hashtable", type.Type.FullName);
			Assert.IsTrue(type.matches(Activator.CreateInstance(Type.GetType("System.Collections.Hashtable"))));
		}
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -