protected virtual void SetUpFixture()
        {
            string resource = "SqlMap_StatementOnly.config";
            string scriptDirectory = Path.Combine(Path.Combine(Path.Combine(Resources.ApplicationBase, ".."), ".."), "Scripts") + Path.DirectorySeparatorChar;

            try
            {
                IConfigurationEngine engine = new DefaultConfigurationEngine();
                engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));
                engine.RegisterModule(new AccountModule());
                engine.RegisterModule(new DocumentModule());

                IMapperFactory mapperFactory = engine.BuildMapperFactory();

                Console.WriteLine(engine.ConfigurationStore.ToString());

                dataMapper = ((IDataMapperAccessor)mapperFactory).DataMapper;
                ISessionFactory sessionFactory = engine.ModelStore.SessionFactory;
                BaseTest.InitScript(sessionFactory.DataSource, scriptDirectory + "account-init.sql");

            }
            catch (Exception ex)
            {
                Exception e = ex;
                while (e != null)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    e = e.InnerException;

                }
                throw;
            }

        }
        public void ConfigurationStore_should_contain_module_configuration()
        {
            ConfigurationSetting configurationSetting = new ConfigurationSetting();
            configurationSetting.DataSource = new FakeDataSource();

            IConfigurationEngine engine = new DefaultConfigurationEngine(configurationSetting);
            engine.RegisterModule(new MyModule());

            engine.BuildMapperFactory();

            CheckConfigurationStore(engine.ConfigurationStore);
        }
Esempio n. 3
0
        public void SetUpFixture()
        {
            string uri = "file://~/SqlMap.event.config";
            IResource resource = ResourceLoaderRegistry.GetResource(uri);

            ConfigurationSetting setting = new ConfigurationSetting();
            IConfigurationEngine engine = new DefaultConfigurationEngine(setting);
            engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));
            engine.RegisterModule(new EventModule());

            IMapperFactory mapperFactory = engine.BuildMapperFactory();
            sessionFactory = engine.ModelStore.SessionFactory;
            dataMapper = ((IDataMapperAccessor)mapperFactory).DataMapper;
        }
Esempio n. 4
0
        protected virtual void SetUpFixture()
        {
            //DateTime start = DateTime.Now;

            configurationSetting = new ConfigurationSetting();
            configurationSetting.Properties.Add("collection2Namespace", "MyBatis.DataMapper.SqlClient.Test.Domain.LineItemCollection2, MyBatis.DataMapper.SqlClient.Test");
            configurationSetting.Properties.Add("nullableInt", "int?");

            string resource = "sqlmap.config";

            try
            {
                IConfigurationEngine engine = new DefaultConfigurationEngine(configurationSetting);
                engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));
                engine.RegisterModule(new AliasModule());

                IMapperFactory mapperFactory = engine.BuildMapperFactory();
                sessionFactory = engine.ModelStore.SessionFactory;
                dataMapper = ((IDataMapperAccessor)mapperFactory).DataMapper;
                sessionStore = ((IModelStoreAccessor) dataMapper).ModelStore.SessionStore;
            }
            catch (Exception ex)
            {
                Exception e = ex;
                while (e != null)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    e = e.InnerException;
                }
                throw;
            }

            if (sessionFactory.DataSource.DbProvider.Id.IndexOf("PostgreSql") >= 0)
            {
                ConvertKey = new KeyConvert(Lower);
            }
            else if (sessionFactory.DataSource.DbProvider.Id.IndexOf("oracle") >= 0)
            {
                ConvertKey = new KeyConvert(Upper);
            }
            else
            {
                ConvertKey = new KeyConvert(Normal);
            }

            //			string loadTime = DateTime.Now.Subtract(start).ToString();
            //			Console.WriteLine("Loading configuration time :"+loadTime);
        }
        public void Event_FileReourceLoad_should_be_launch()
        {
            string resource = "SqlMap_Test_Configure.config";

            IConfigurationEngine engine = new DefaultConfigurationEngine();
            engine.FileResourceLoad += FileResourceEventHandler;

            engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));
            engine.BuildMapperFactory();

            Assert.That(fileNames.Count, Is.EqualTo(6));
            Assert.Contains(resource, fileNames);
            Assert.Contains("database.config", fileNames);
            Assert.Contains("providers.config", fileNames);
            Assert.Contains("Mapping1.xml", fileNames);
            Assert.Contains("Mapping3.xml", fileNames);
            Assert.Contains("Mapping4.xml", fileNames);
        }
        public void ResultMap_configuration_via_code_should_override_file_configuration()
        {
            string uri = "assembly://MyBatis.DataMapper.SqlClient.Test/bin.Debug/SqlMap_Test_Configure.config";
            IResource resource = ResourceLoaderRegistry.GetResource(uri);

            // Before have 4 properties
            IConfigurationEngine engine = new DefaultConfigurationEngine();
            engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));

            engine.BuildMapperFactory();
            IConfiguration resultMap = engine.ConfigurationStore.GetResultMapConfiguration("Account.Category-result");
            Assert.That(resultMap.Children.Count, Is.EqualTo(3));

            // With code configuration override have only 1 properties
            engine = new DefaultConfigurationEngine();
            engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));
            engine.RegisterModule(new AccountModule());

            engine.BuildMapperFactory();

            resultMap = engine.ConfigurationStore.GetResultMapConfiguration("Account.Category-result");
            Assert.That(resultMap.Children.Count, Is.EqualTo(1));
        }
        public void Should_contains_ResultMap_DocumentBook_with_5_properties()
        {
            string uri = "assembly://MyBatis.DataMapper.SqlClient.Test/bin.Debug/SqlMap_Test_Configure.config";
            IResource resource = ResourceLoaderRegistry.GetResource(uri);

            IConfigurationEngine engine = new DefaultConfigurationEngine();
            engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));

            engine.BuildMapperFactory();

            IConfiguration resultMap = engine.ConfigurationStore.GetResultMapConfiguration("Document.book");
            Assert.That(resultMap.Children.Count, Is.EqualTo(4));

            //Console.WriteLine(engine.ModelStore.ToString());
        }
        public void Can_plug_HybridWebThreadSessionStore()
        {
            string uri = "assembly://MyBatis.DataMapper.SqlClient.Test/bin.Debug/SqlMap_Test_Configure.config";
            IResource resource = ResourceLoaderRegistry.GetResource(uri);

            ConfigurationSetting setting = new ConfigurationSetting();
            setting.SessionStore = new HybridWebThreadSessionStore("test");
            setting.ValidateMapperConfigFile = true;

            IConfigurationEngine engine = new DefaultConfigurationEngine(setting);
            engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));

            IMapperFactory mapperFactory = engine.BuildMapperFactory();
            IDataMapper dataMapper = ((IDataMapperAccessor)mapperFactory).DataMapper;

            Account account = dataMapper.QueryForObject<Account>("GetAccountViaResultClass", 1);

            Assert.AreEqual(1, account.Id, "account.Id");
            Assert.AreEqual("Joe", account.FirstName, "account.FirstName");
            Assert.AreEqual("Dalton", account.LastName, "account.LastName");
            Assert.AreEqual("*****@*****.**", account.EmailAddress, "account.EmailAddress");
        }
        public void Should_contains_statement_GetAllAccountsOrderByName_with_2_child()
        {
            string uri = "assembly://MyBatis.DataMapper.SqlClient.Test/bin.Debug/SqlMap_Test_Configure.config";
            IResource resource = ResourceLoaderRegistry.GetResource(uri);

            IConfigurationEngine engine = new DefaultConfigurationEngine();
            engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));

            engine.BuildMapperFactory();

            IConfiguration statement = engine.ConfigurationStore.GetStatementConfiguration("GetAllAccountsOrderByName");
            Assert.That(statement.Children.Count, Is.EqualTo(2));

            //Console.WriteLine(engine.ConfigurationStore);
        }
        public void Should_contains_ParameterMap_OrderInsertExtend_with_10_properties()
        {
            string uri = "assembly://MyBatis.DataMapper.SqlClient.Test/bin.Debug/SqlMap_Test_Configure.config";
            IResource resource = ResourceLoaderRegistry.GetResource(uri);

            IConfigurationEngine engine = new DefaultConfigurationEngine();
            engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));

            engine.BuildMapperFactory();

            IConfiguration parameterMap = engine.ConfigurationStore.GetParameterMapConfiguration("Order.insert-extend");
            Assert.That(parameterMap.Children.Count, Is.EqualTo(10));

            int index = parameterMap.Children.FindIndex(
                delegate(IConfiguration paramater)
                    { return paramater.Id == "CardNumber"; }
                );
            Assert.That(index, Is.EqualTo(5));

            //Console.WriteLine(engine.ConfigurationStore);
        }
Esempio n. 11
0
        public void Test_DefaultConfigurationEngine_via_File_Resource()
        {
            string uri = "file://~/SqlMap_Test_Configure.config";
            IResource resource = ResourceLoaderRegistry.GetResource(uri);

            IConfigurationEngine engine = new DefaultConfigurationEngine();
            engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));

            engine.BuildMapperFactory();

            CheckResource(engine.ConfigurationStore);
        }
Esempio n. 12
0
        public void Test_DefaultConfigurationEngine_via_Assembly_Resource()
        {
            string uri = "assembly://MyBatis.DataMapper.SqlClient.Test/bin.Debug/SqlMap_Test_Configure.config";
            IResource resource = ResourceLoaderRegistry.GetResource(uri);

            IConfigurationEngine engine = new DefaultConfigurationEngine();
            engine.RegisterInterpreter(new XmlConfigurationInterpreter(resource));

            engine.BuildMapperFactory();

            CheckResource(engine.ConfigurationStore);
        }
        public void CodeConfigurationMatchesSqlMapConfig()
        {
            #region SqlMapConfig.xml
            /*
            <sqlMapConfig xmlns="http://ibatis.apache.org/dataMapper" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
	            <settings>
		            <setting useStatementNamespaces="true"/>
		            <setting cacheModelsEnabled="false"/>
		            <setting validateSqlMap="false"/>
		            <setting useReflectionOptimizer="false"/>
		            <setting preserveWhitespace="false"/>
	            </settings>	
	            <providers uri="file://providers.config"/>
	            <database>
		            <provider name="SQLite3"/>
		            <dataSource name="ibatisnet.sqlmap" connectionString="Data Source=ibatisnet.sqlite;Version=3;"/>
	            </database>  
	            <alias>
		            <typeAlias alias="Account" type="MyBatis.DataMapper.Sqlite.Test.Domain.Account, MyBatis.DataMapper.Sqlite.Test"/>
	            </alias>  
              <sqlMaps>
		            <sqlMap uri="file://../../Maps/Account.xml"/>
              </sqlMaps>
            </sqlMapConfig>
            */
            #endregion

            // slightly awkward to creating ConfigurationSetting, then engine, then interpreter ???

            ConfigurationSetting settings = new ConfigurationSetting();
            settings.UseStatementNamespaces = true;
            settings.IsCacheModelsEnabled = false;
            settings.ValidateMapperConfigFile = false;
            settings.UseReflectionOptimizer = false;
            settings.PreserveWhitespace = false;

            var engine = new DefaultConfigurationEngine(settings);

            CodeConfigurationInterpreter codeConfig = new CodeConfigurationInterpreter(engine.ConfigurationStore);
            codeConfig.AddDatabase(new SqliteDbProvider(), "Data Source=ibatisnet.sqlite;Version=3;");
            codeConfig.AddAlias(typeof(Account), "Account");
            codeConfig.AddSqlMap("file://../../Maps/Account.xml", true);

            engine.RegisterInterpreter(codeConfig);
            IMapperFactory mapperFactory = engine.BuildMapperFactory();
            IDataMapper localDataMapper = ((IDataMapperAccessor)mapperFactory).DataMapper;

            IConfigurationStore store = engine.ConfigurationStore;
            IConfigurationStore baseStore = ConfigurationEngine.ConfigurationStore;

            assertConfiguration(baseStore.Properties, store.Properties);
            // assertConfiguration(baseStore.Settings, store.Settings);
            assertConfiguration(baseStore.Databases, store.Databases);
            assertConfiguration(baseStore.TypeHandlers, store.TypeHandlers);
            assertConfiguration(baseStore.Alias, store.Alias);
            assertConfiguration(baseStore.CacheModels, store.CacheModels);
            assertConfiguration(baseStore.ResultMaps, store.ResultMaps);
            assertConfiguration(baseStore.Statements, store.Statements);
            assertConfiguration(baseStore.ParameterMaps, store.ParameterMaps);

            InitScript(sessionFactory.DataSource, "../../Scripts/account-init.sql");

            ICollection items = localDataMapper.QueryForList("Account.GetAllAccounts1", null);
            Assert.IsTrue(items.Count > 1);

            items = localDataMapper.QueryForList("Account.GetAllAccounts2", null);
            Assert.IsTrue(items.Count > 1);
        }