Example #1
0
        public void CreateMethodDelegateByNameTest()
        {
            var testClass = new MockClass();

            LazyBinding.CreateMethodDelegate <Action>(testClass, "MockMethod")();
            Assert.AreEqual(1, testClass.TimesCalled);
        }
Example #2
0
        public void GetAssemblyCachedTest()
        {
            // Check that the same Assembly object is returned.
            Assembly thisAssembly = Assembly.GetExecutingAssembly();

            Assert.AreEqual(thisAssembly, LazyBinding.GetAssembly(thisAssembly.GetName().Name));
        }
Example #3
0
        public void CreateILogInstanceTest()
        {
            Assembly log4net = LazyBinding.GetAssembly("log4net");
            object   logger  = Log4NetLogger.CreateILogInstance(log4net, "MyLoggerName");

            Assert.IsNotNull(logger);
            Assert.IsTrue(log4net.GetType("log4net.ILog", true).IsAssignableFrom(logger.GetType()));
        }
Example #4
0
        public void CreatePropertyGetDelegateByNameTest()
        {
            var testClass = new MockClass()
            {
                MockProperty = "FooBar"
            };
            string result = LazyBinding.CreatePropertyGetDelegate <string>(testClass, "MockProperty")();

            Assert.AreEqual("FooBar", result);
        }
Example #5
0
        public void CreatePropertyGetDelegateTest()
        {
            var testClass = new MockClass()
            {
                MockProperty = "FooBar"
            };
            PropertyInfo property = testClass.GetType().GetProperty("MockProperty");
            string       result   = LazyBinding.CreatePropertyGetDelegate <string>(testClass, property)();

            Assert.AreEqual("FooBar", result);
        }
Example #6
0
        private Log4NetLogger(object typeOrName)
        {
            // Create an ILog instance using reflection.
            Assembly log4net = LazyBinding.GetAssembly(log4netAssemblyName);
            object   ILog    = CreateILogInstance(log4net, typeOrName);

            // Get a set of function references.
            logInfo           = LazyBinding.CreateMethodDelegate <Action <string> >(ILog, "Info", typeof(string));
            logDebug          = LazyBinding.CreateMethodDelegate <Action <string> >(ILog, "Debug", typeof(string));
            logWarning        = LazyBinding.CreateMethodDelegate <Action <string> >(ILog, "Warn", typeof(string));
            logError          = LazyBinding.CreateMethodDelegate <Action <string> >(ILog, "Error", typeof(string));
            logErrorException = LazyBinding.CreateMethodDelegate <Action <string, Exception> >(
                ILog, "Error", typeof(string), typeof(Exception));
            logIsDebugEnabled = LazyBinding.CreatePropertyGetDelegate <bool>(ILog, "IsDebugEnabled");
        }
Example #7
0
 public void GetAssemblyUncachedTest()
 {
     // Check that the same Assembly object is returned.
     Assert.IsNotNull(LazyBinding.GetAssembly("log4net"));
 }
Example #8
0
 public void GetAssemblyNonExistentTest()
 {
     // Ensure that an exception is thrown.
     Assert.Throws <FileNotFoundException>(() => LazyBinding.GetAssembly("non_existing_example_dll"));
 }