Ejemplo n.º 1
0
        public void CloneSectionWithData_SectionNull_RaiseArgumentNullException()
        {
            // arrange
            IModuleXml moduleMock = this.CreateModuleMock( "testModule", "NGin.Core.Test.NGinModuleConfigTest.TestModule" );
            NGinModuleConfig config = new NGinModuleConfig( moduleMock );
            ISectionXml sectionNull = null;

            // act
            config.CloneSectionWithData( sectionNull );

            // assert
        }
Ejemplo n.º 2
0
        public NGinConfig( string configFile )
        {
            this.nginConfig = this.DeserializeConfigFile( configFile );

            DependenciesConfigXml dependenciesConfig = this.DeserializeDependenciesConfig( nginConfig );
            this.DependencyResolver = new DependencyResolver( dependenciesConfig );

            foreach ( IModuleXml module in this.nginConfig.Modules )
            {
                INGinModuleConfig moduleConfig = new NGinModuleConfig( module );
                this.modules.Add( moduleConfig.Name, moduleConfig );
            }
        }
Ejemplo n.º 3
0
        public void InsertDataSectionIntoSectionXml_DefaultDataTypeXmlElement_Success()
        {
            // arrange
            ISectionXml testSection = this.CreateSectionMock( "testSection", this.xmlPluginsConfig, typeof(XmlElement).FullName );
            IModuleXml moduleMock = this.CreateModuleMock( "testModule", "NGin.Core.Test.NGinModuleConfigTest.TestModule", testSection );
            NGinModuleConfig config = new NGinModuleConfig( moduleMock );
            Type expectedType = typeof( XmlElement );
            Type actualType = null;

            // act
            actualType = config.InsertDataIntoSectionXml( testSection as SectionXml );

            // assert
            Assert.AreEqual( expectedType, actualType );
            Assert.IsNotNull( testSection.Data );
            Assert.IsInstanceOf( expectedType, testSection.Data );
            Assert.AreEqual( testSection.XmlElement, testSection.Data );
            Assert.AreEqual( testSection.XmlRaw, ( ( XmlElement ) testSection.Data ).OuterXml );
        }
Ejemplo n.º 4
0
        public void InsertDataSectionIntoSectionXml_DataTypePluginsConfig_Success()
        {
            // arrange
            Type expectedType = typeof( PluginsConfigXml );
            Type actualType = null;
            SectionXml testSection = new SectionXml();
            testSection.Name = "testSection";
            testSection.XmlElement = this.xmlPluginsConfig;
            testSection.DataTypeName = expectedType.FullName;
            IModuleXml moduleMock = this.CreateModuleMock( "testModule", "NGin.Core.Test.NGinModuleConfigTest.TestModule", testSection );
            NGinModuleConfig config = new NGinModuleConfig( moduleMock );

            // act
            actualType = config.InsertDataIntoSectionXml( testSection );

            // assert
            Assert.AreEqual( expectedType, actualType );
            Assert.IsNotNull( testSection.Data );
            Assert.IsInstanceOf( expectedType, testSection.Data );
            Assert.IsTrue( ( ( PluginsConfigXml ) testSection.Data ).IsInitialized );
        }
Ejemplo n.º 5
0
        public void InsertDataSectionIntoSectionXml_DataTypeNotDefined_RaisePluginNotFoundException()
        {
            // arrange
            Type expectedType = typeof( DependenciesConfigXml );
            Type actualType = null;
            SectionXml testSection = new SectionXml();
            testSection.Name = "testSection";
            testSection.XmlElement = this.xmlDependenciesConfig;
            // define invalid type name
            testSection.DataTypeName = "Something.Went.Wrong.ConfigType";
            IModuleXml moduleMock = this.CreateModuleMock( "testModule", "NGin.Core.Test.NGinModuleConfigTest.TestModule", testSection );
            NGinModuleConfig config = new NGinModuleConfig( moduleMock );

            // act
            actualType = config.InsertDataIntoSectionXml( testSection );

            // assert
        }
Ejemplo n.º 6
0
        public void GetSectionData_ValidSection_DataValid()
        {
            // arrange
            Type expectedType = typeof( PluginsConfigXml );
            ISectionXml testSection = this.CreateSectionMock( "plugins", this.xmlPluginsConfig, expectedType.FullName );
            IModuleXml moduleMock = this.CreateModuleMock( "testModule", "NGin.Core.Test.NGinModuleConfigTest.TestModule", testSection );
            NGinModuleConfig config = new NGinModuleConfig( moduleMock );
            string sectionName = "plugins";
            ISectionXml expectedSection = config.GetSectionCloned( sectionName );
            object data = null;

            // act
            data = config.GetSectionData( sectionName );

            // assert
            Assert.IsNotNull( data );
            Assert.IsInstanceOf( expectedType, data );
            Assert.AreEqual( expectedSection.Data, data );
            Assert.AreEqual( expectedSection.DataType, data.GetType() );
        }
Ejemplo n.º 7
0
        public void GetSectionData_UnknownSection_RaiseArgumentException()
        {
            // arrange
            IModuleXml moduleMock = this.CreateModuleMock( "testModule", "NGin.Core.Test.NGinModuleConfigTest.TestModule" );
            NGinModuleConfig config = new NGinModuleConfig( moduleMock );
            string sectionName = Guid.NewGuid().ToString();
            object data = null;

            // act
            data = config.GetSectionData( sectionName );

            // assert
        }
Ejemplo n.º 8
0
        public void GetSectionCloned_GetSameSectionTwice_ResultNotSameRef()
        {
            // arrange
            Type expectedType = typeof( DependenciesConfigXml );
            SectionXml testSection = new SectionXml();
            testSection.Name = "testSection";
            // fill in xml that does not match type
            testSection.XmlElement = this.xmlDependenciesConfig;
            testSection.DataTypeName = expectedType.FullName;
            IModuleXml moduleMock = this.CreateModuleMock( "testModule", "NGin.Core.Test.NGinModuleConfigTest.TestModule", testSection );
            NGinModuleConfig config = new NGinModuleConfig( moduleMock );
            ISectionXml first = null;
            ISectionXml second = null;

            // act
            first = config.GetSectionCloned( testSection.Name );
            second = config.GetSectionCloned( testSection.Name );

            // assert
            Assert.IsNotNull( first );
            Assert.IsNotNull( second );
            Assert.AreNotSame( first, second );
            Assert.AreEqual( first, second );
        }
Ejemplo n.º 9
0
        public void GetSectionDataAs_InvalidSectionString_RaiseArgumentException()
        {
            // arrange
            IModuleXml moduleMock = this.CreateModuleMock( "testModule", "NGin.Core.Test.NGinModuleConfigTest.TestModule" );
            NGinModuleConfig config = new NGinModuleConfig( moduleMock );
            string sectionName = Guid.NewGuid().ToString();
            string resultData = null;

            // act
            resultData = config.GetSectionDataAs( typeof( string ), sectionName ) as string;

            // assert
        }
Ejemplo n.º 10
0
        public void GetSectionDataAs_InvalidConfigDataType_RaisePluginNotFoundException()
        {
            // arrange
            ISectionXml testSection = this.CreateSectionMock( "plugins", this.xmlPluginsConfig, typeof( PluginsConfigXml ).FullName );
            IModuleXml moduleMock = this.CreateModuleMock( "testModule", "NGin.Core.Test.NGinModuleConfigTest.TestModule", testSection );
            NGinModuleConfig config = new NGinModuleConfig( moduleMock );
            string sectionName = "plugins";
            Type invalidType = typeof( MemoryStream );

            // act
            config.GetSectionDataAs( invalidType, sectionName );

            // assert
        }
Ejemplo n.º 11
0
        public void GetSectionDataAs_ConfigDataTypeNull_RaiseArgumentNullExcpetion()
        {
            // arrange
            IModuleXml moduleMock = this.CreateModuleMock( "testModule", "NGin.Core.Test.NGinModuleConfigTest.TestModule" );
            NGinModuleConfig config = new NGinModuleConfig( moduleMock );
            string sectionName = "plugins";
            Type typeNull = null;

            // act
            config.GetSectionDataAs( typeNull, sectionName );

            // assert
        }
Ejemplo n.º 12
0
        public void GetSectionDataAsXmlElement_InvalidSection_RaiseArgumentException()
        {
            // arrange
            IModuleXml moduleMock = this.CreateModuleMock( "testModule", "NGin.Core.Test.NGinModuleConfigTest.TestModule" );
            NGinModuleConfig config = new NGinModuleConfig( moduleMock );
            string sectionName = Guid.NewGuid().ToString();
            XmlElement resultXml = null;

            // act
            resultXml = config.GetSectionDataAsXmlElement( sectionName );

            // assert
        }
Ejemplo n.º 13
0
        public void GetSectionDataAsRawXml_ValidSection_Sucess()
        {
            // arrange
            ISectionXml testSection = this.CreateSectionMock( "plugins", this.xmlPluginsConfig, typeof( PluginsConfigXml ).FullName );
            IModuleXml moduleMock = this.CreateModuleMock( "testModule", "NGin.Core.Test.NGinModuleConfigTest.TestModule", testSection );
            NGinModuleConfig config = new NGinModuleConfig( moduleMock );
            string expectedXml = config.GetSectionCloned( "plugins" ).XmlRaw;
            string resultXml = null;

            // act
            resultXml = config.GetSectionDataAsRawXml( "plugins" );

            // assert
            Assert.IsNotNull( resultXml );
            Assert.AreEqual( expectedXml, resultXml );
        }
Ejemplo n.º 14
0
        public void GetSectionCloned_SectionNull_RaiseArgumentNullException()
        {
            // arrange
            IModuleXml moduleMock = this.CreateModuleMock( "testModule", "NGin.Core.Test.NGinModuleConfigTest.TestModule" );
            NGinModuleConfig config = new NGinModuleConfig( moduleMock );
            string sectionNameNull = null;
            ISectionXml section = null;

            // act
            section = config.GetSectionCloned( sectionNameNull );

            // assert
        }
Ejemplo n.º 15
0
        public void GetSectionCloned_SectionNotExist_RaiseArgumentException()
        {
            // arrange
            IModuleXml moduleMock = this.CreateModuleMock( "testModule", "NGin.Core.Test.NGinModuleConfigTest.TestModule" );
            NGinModuleConfig config = new NGinModuleConfig( moduleMock );
            string invalidSectionName = Guid.NewGuid().ToString();
            ISectionXml section = null;

            // act
            section = config.GetSectionCloned( invalidSectionName );

            // assert
        }
Ejemplo n.º 16
0
        public void InsertDataSectionIntoSectionXml_SectionNull_RaiseArgumentNullException()
        {
            // arrange
            Type actualType = null;
            SectionXml testSection = null;
            IModuleXml moduleMock = this.CreateModuleMock( "testModule", "NGin.Core.Test.NGinModuleConfigTest.TestModule", testSection );
            NGinModuleConfig config = new NGinModuleConfig( moduleMock );

            // act
            actualType = config.InsertDataIntoSectionXml( testSection );

            // assert
        }
Ejemplo n.º 17
0
        public void InsertDataSectionIntoSectionXml_XmlDoesNotMatchType_RaiseCoreConfigException()
        {
            // arrange
            Type expectedType = typeof( DependenciesConfigXml );
            Type actualType = null;
            SectionXml testSection = new SectionXml();
            testSection.Name = "testSection";
            // fill in xml that does not match type
            testSection.XmlElement = this.xmlRandom;
            testSection.DataTypeName = expectedType.FullName;
            IModuleXml moduleMock = this.CreateModuleMock( "testModule", "NGin.Core.Test.NGinModuleConfigTest.TestModule", testSection );
            NGinModuleConfig config = new NGinModuleConfig( moduleMock );

            // act
            actualType = config.InsertDataIntoSectionXml( testSection );

            // assert
        }
Ejemplo n.º 18
0
        public void GetSectionDataAs_ValidSectionString_GetDataRawXml()
        {
            // arrange
            string sectionName = "plugins";
            ISectionXml testSection = this.CreateSectionMock( sectionName, this.xmlPluginsConfig, typeof( PluginsConfigXml ).FullName );
            IModuleXml moduleMock = this.CreateModuleMock( "testModule", "NGin.Core.Test.NGinModuleConfigTest.TestModule", testSection );
            NGinModuleConfig config = new NGinModuleConfig( moduleMock );

            string expectedXml = config.GetSectionCloned( sectionName ).XmlRaw;
            string resultData = null;

            // act
            resultData = config.GetSectionDataAs( typeof( string ), sectionName ) as string;

            // assert
            Assert.IsNotNull( resultData );
            Assert.AreEqual( expectedXml, resultData );
        }
Ejemplo n.º 19
0
        public void CloneSectionWithData_ValidSection_DataValid()
        {
            // arrange
            ISectionXml testSection = this.CreateSectionMock( "plugins", this.xmlPluginsConfig, typeof( PluginsConfigXml ).FullName );
            IModuleXml moduleMock = this.CreateModuleMock( "testModule", "NGin.Core.Test.NGinModuleConfigTest.TestModule", testSection );
            NGinModuleConfig config = new NGinModuleConfig( moduleMock );
            ISectionXml section = config.GetSectionCloned( "plugins" );
            ISectionXml clone = null;

            // act
            clone = config.CloneSectionWithData( section );

            // assert
            Assert.IsNotNull( clone );
            Assert.IsInstanceOf<ISectionXml>( clone );
            Assert.AreNotSame( section, clone );
            Assert.AreEqual( section, clone );
        }
Ejemplo n.º 20
0
        public void GetSectionDataAs_XmlElement_Success()
        {
            // arrange
            string sectionName = "dependencies";
            ISectionXml testSection = this.CreateSectionMock( sectionName, this.xmlDependenciesConfig, typeof( DependenciesConfigXml ).FullName );
            IModuleXml moduleMock = this.CreateModuleMock( "testModule", "NGin.Core.Test.NGinModuleConfigTest.TestModule", testSection );
            NGinModuleConfig config = new NGinModuleConfig( moduleMock );
            XmlElement expectedXml = config.GetSectionCloned( sectionName ).XmlElement;
            XmlElement resultXml = null;

            // act
            resultXml = config.GetSectionDataAs( typeof( XmlElement ), sectionName ) as XmlElement;

            // assert
            Assert.IsNotNull( resultXml );
            Assert.AreEqual( expectedXml, resultXml );
        }