Пример #1
0
        /// <summary> Inits the plug-in with configured factory data. </summary>
        /// <param name="factoryData"> Retrieved factory settings. This parameter is null if no configuration at all was found. </param>
        public void Init(string factoryData)
        {
            string logTypeName;

            try
            {
                // load the factoryData XML
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(factoryData);

                // obtain the logger element and inspect the 'type' attribute
                XmlElement   logElement       = (XmlElement)xmlDoc.GetElementsByTagName("log")[0];
                XmlAttribute logTypeAttribute = logElement.Attributes[0];
                logTypeName = logTypeAttribute.Value;
            }
            catch (Exception e)
            {
                DiagnosticLog.Error(e, "An exception was thrown while trying to parse the given XML configuration [{0}]",
                                    factoryData);
                return;
            }

            ILog log = ActivatorHelper.Instantiate <ILog>(logTypeName, DiagnosticLog);

            if (log != null)
            {
                this.Log = log;
            }
        }
Пример #2
0
        //
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Instantiate
        ///</summary>
        public void InstantiateTestHelper <T>()
        {
            string typeName = string.Empty; // TODO: Initialize to an appropriate value
            ILog   log      = null;         // TODO: Initialize to an appropriate value
            T      expected = default(T);   // TODO: Initialize to an appropriate value
            T      actual;

            actual = ActivatorHelper.Instantiate <T>(typeName, log);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
        /// <summary> Creates a factory based on a given configuration. If the factory provides invalid information, an error is logged through the internal log, and a <see cref="NullLogFactory" /> returned. </summary>
        /// <param name="factoryConfiguration"> The configuration that provides type information for the <see cref="ILogFactory" /> that is being created. </param>
        /// <returns> Factory instance. </returns>
        private ILogFactory CreateFactoryInstance(FactoryConfigurationElement factoryConfiguration)
        {
            ILogFactory factory = ActivatorHelper.Instantiate <ILogFactory>(factoryConfiguration.Type, DiagnosticLog);

            //if the factory is configurable, invoke its Init method
            IConfigurableLogFactory cf = factory as IConfigurableLogFactory;

            if (cf != null)
            {
                cf.Init(factoryConfiguration.FactoryData);
            }

            if (factory == null)
            {
                factory = NullLogFactory.Instance;
            }

            return(factory);
        }