Beispiel #1
0
        public void Equals_DifferentDependenciesLength_AreNotEqual()
        {
            // arrange
            PluginsConfigXml configOne = new PluginsConfigXml();
            PluginsConfigXml configTwo = new PluginsConfigXml();
            FileXml file = new FileXml();
            file.Location = System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().Location );
            configOne.PlugIns = new System.Collections.ObjectModel.Collection<FileXml>();
            configOne.PlugIns.Add( file );
            configTwo.PlugIns = new System.Collections.ObjectModel.Collection<FileXml>();
            configTwo.PlugIns.Add( file );
            configTwo.PlugIns.Add( file );
            bool areEqual;

            // act
            areEqual = configOne.Equals( configTwo );

            // assert
            Assert.IsFalse( areEqual );
        }
Beispiel #2
0
        public PluginManager( ILogManager logManager, PluginsConfigXml pluginsConfig )
        {
            if ( logManager == null )
            {
                throw new ArgumentNullException( "logManager", "The given log manager must not be null." );
            }

            this.LogManager = logManager;

            if ( pluginsConfig == null )
            {
                string message = "The given plugins configuration must not be null.";
                ArgumentNullException argEx = new ArgumentNullException( "pluginsConfig", message );
                this.LogManager.Trace( Namespace.LoggerName, LogLevel.Error, message, argEx );
                throw argEx;
            }

            this.PluginsConfig = pluginsConfig;

            this.pluginAssemblies = this.GetPluginAssemblies( pluginsConfig );
            this.pluggables = this.GetPluggables( this.pluginAssemblies );
            this.plugins = this.GetPlugins( this.pluggables, this.pluginAssemblies );
        }
Beispiel #3
0
        internal IList<Assembly> GetPluginAssemblies( PluginsConfigXml pluginsConfig )
        {
            if ( pluginsConfig == null )
            {
                string message = "The given plugins config must not be null.";
                ArgumentNullException argEx = new ArgumentNullException( "pluginsConfig", message );
                this.LogManager.Trace( Namespace.LoggerName, LogLevel.Error, message, argEx );
                throw argEx;
            }

            // check if configuration is valid
            if ( !pluginsConfig.IsInitialized )
            {
                string message = "The given configuration is invalid.";
                InvalidOperationException iopEx = new InvalidOperationException( message );
                this.LogManager.Trace( Namespace.LoggerName, LogLevel.Error, message, iopEx );
                throw iopEx;
            }

            List<Assembly> result = new List<Assembly>();

            foreach ( FileXml pluginDef in pluginsConfig.PlugIns )
            {
                FileInfo pluginFile = new FileInfo( Path.Combine( pluginDef.Location, pluginDef.FileName ) );
                Assembly pluginAssembly = InputOutputManager.LoadAssembly( pluginFile );

                // Idea: should duplicate assemblies be avoided to avoid redundant searching?
                result.Add( pluginAssembly );
            }

            return result;
        }
Beispiel #4
0
        private PluginsConfigXml CreatePluginsConfigMock( params string[] pluginFilePaths )
        {
            PluginsConfigXml result = new PluginsConfigXml();

            result.PlugIns = new System.Collections.ObjectModel.Collection<FileXml>();
            foreach ( string filePath in pluginFilePaths )
            {
                FileXml fileXml = new FileXml();
                fileXml.FileName = Path.GetFileName( filePath );
                fileXml.Location = Path.GetDirectoryName( filePath );
                result.PlugIns.Add( fileXml );
            }

            return result;
        }
Beispiel #5
0
        public void PluginsConfigXml_CreateInstance_Success()
        {
            // arrange
            PluginsConfigXml config;

            // act
            config = new PluginsConfigXml();

            // assert
            Assert.IsNotNull( config );
            Assert.IsInstanceOf<PluginsConfigXml>( config );
        }
Beispiel #6
0
        public void IsInitialized_PlugInsNull_ReturnFalse()
        {
            // arrange
            PluginsConfigXml config = new PluginsConfigXml();
            config.PlugIns = null;

            // act

            // assert
            Assert.IsFalse( config.IsInitialized );
        }
Beispiel #7
0
        public void IsInitialized_PlugInsInitialized_ReturnTrue()
        {
            // arrange
            PluginsConfigXml config = new PluginsConfigXml();
            config.PlugIns = new System.Collections.ObjectModel.Collection<FileXml>();

            // act

            // assert
            Assert.IsTrue( config.IsInitialized );
        }
Beispiel #8
0
        public void GetHashCode_EqualObjects_SameHashCodes()
        {
            // arrange
            PluginsConfigXml configOne = new PluginsConfigXml();
            PluginsConfigXml configTwo = new PluginsConfigXml();
            FileXml file = new FileXml();
            file.Location = System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().Location );
            file.FileName = "abcdef";
            configOne.PlugIns = new System.Collections.ObjectModel.Collection<FileXml>();
            configOne.PlugIns.Add( file );
            configTwo.PlugIns = new System.Collections.ObjectModel.Collection<FileXml>();
            configTwo.PlugIns.Add( file );
            int hashCodeOne, hashCodeTwo;

            // act
            hashCodeOne = configOne.GetHashCode();
            hashCodeTwo = configTwo.GetHashCode();

            // assert
            Assert.AreEqual( hashCodeOne, hashCodeTwo );
        }
Beispiel #9
0
        public void GetHashCode_DifferentDependencies_DifferentHashCodes()
        {
            // arrange
            PluginsConfigXml configOne = new PluginsConfigXml();
            PluginsConfigXml configTwo = new PluginsConfigXml();
            FileXml file = new FileXml();
            FileXml dirOther = new FileXml();
            file.Location = System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().Location );
            file.FileName = "abcd";
            dirOther.Location = System.IO.Path.GetPathRoot( file.Location );
            dirOther.FileName = "xyz";
            configOne.PlugIns = new System.Collections.ObjectModel.Collection<FileXml>();
            configOne.PlugIns.Add( file );
            configTwo.PlugIns = new System.Collections.ObjectModel.Collection<FileXml>();
            configTwo.PlugIns.Add( file );
            configTwo.PlugIns.Add( dirOther );
            int hashCodeOne, hashCodeTwo;

            // act
            hashCodeOne = configOne.GetHashCode();
            hashCodeTwo = configTwo.GetHashCode();

            // assert
            Assert.AreNotEqual( hashCodeOne, hashCodeTwo );
        }
Beispiel #10
0
        public void Equals_OtherType_AreNotEqual()
        {
            // arrange
            PluginsConfigXml config = new PluginsConfigXml();
            string other = "notaconfig";
            bool areEqual;

            // act
            areEqual = config.Equals( other );

            // assert
            Assert.IsFalse( areEqual );
        }