public void CreateMethodDelegateByNameTest() { var testClass = new MockClass(); LazyBinding.CreateMethodDelegate <Action>(testClass, "MockMethod")(); Assert.AreEqual(1, testClass.TimesCalled); }
public void GetAssemblyCachedTest() { // Check that the same Assembly object is returned. Assembly thisAssembly = Assembly.GetExecutingAssembly(); Assert.AreEqual(thisAssembly, LazyBinding.GetAssembly(thisAssembly.GetName().Name)); }
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())); }
public void CreatePropertyGetDelegateByNameTest() { var testClass = new MockClass() { MockProperty = "FooBar" }; string result = LazyBinding.CreatePropertyGetDelegate <string>(testClass, "MockProperty")(); Assert.AreEqual("FooBar", result); }
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); }
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"); }
public void GetAssemblyUncachedTest() { // Check that the same Assembly object is returned. Assert.IsNotNull(LazyBinding.GetAssembly("log4net")); }
public void GetAssemblyNonExistentTest() { // Ensure that an exception is thrown. Assert.Throws <FileNotFoundException>(() => LazyBinding.GetAssembly("non_existing_example_dll")); }