在 MappingIntegrationTests 中测试多个数据库映射

发布于 2024-09-12 07:34:12 字数 518 浏览 3 评论 0原文

在 as#arparch 项目中测试多个数据库的最佳方法是什么?

MappingIntegrationTests 中的当前 SetUp() 代码尝试针对第一个数据库测试每个程序集。

string[] mappingAssemblies = RepositoryTestsHelper.GetMappingAssemblies();

 configuration = NHibernateSession.Init(new SimpleSessionStorage(), mappingAssemblies,
                                   new AutoPersistenceModelGenerator().Generate(),
                                   "../../../../app/Humanities.IBusiness.Web/NHibernate.config");

有没有人设法根据适当的数据库模式正确测试每个映射?

What's the best approach for testing multiple db's in a s#arparch project?

The current SetUp() code in MappingIntegrationTests tries to test each assembly against the first database.

string[] mappingAssemblies = RepositoryTestsHelper.GetMappingAssemblies();

 configuration = NHibernateSession.Init(new SimpleSessionStorage(), mappingAssemblies,
                                   new AutoPersistenceModelGenerator().Generate(),
                                   "../../../../app/Humanities.IBusiness.Web/NHibernate.config");

Has anyone managed to correctly test each mapping against the appropriate database schema?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岛歌少女 2024-09-19 07:34:12

嘿亚历克,谢谢你的回复。我已经破解了一些解决方案 - 它并不漂亮,但它确实在多个数据库之间进行了冒烟测试,

在设置中我添加了以下内容:

private List<string> sessionKeys;
        [SetUp]
        public virtual void SetUp()
        {
            string[] mappingAssemblies = RepositoryTestsHelper.GetMappingAssemblies();
            configuration = NHibernateSession.Init(new SimpleSessionStorage(), mappingAssemblies,
                                   new AutoPersistenceModelGenerator().Generate(),
                                   "../../../../app/Humanities.IBusiness.Web/NHibernate.config");

            /*NEW CODE */
            var configuration2 = NHibernateSession.AddConfiguration(DataGlobals.ROLES_DB_FACTORY_KEY,
                mappingAssemblies,
                new AutoPersistenceModelGenerator().Generate(),
                "../../../../app/Humanities.IBusiness.Web/NHibernateForRolesDb.config",null,null, null);
            sessionKeys = new List<string>();
            sessionKeys.Add(DataGlobals.DEFAULT_DB_KEY);
            sessionKeys.Add(DataGlobals.ROLES_DB_FACTORY_KEY);

然后在 CanConfirmDatabaseMatchesMappings 中

foreach (var entry in allClassMetadata)
                {
                    bool found = false;
                    foreach (string key in sessionKeys)
                    {
                        ISession session = NHibernateSession.CurrentFor(key);
                        try
                        {
                            session.CreateCriteria(entry.Value.GetMappedClass(EntityMode.Poco))
                                .SetMaxResults(0).List();
                            found = true;
                        }
                        catch (Exception ex) { }

                    }
                    if (found == false)
                        throw new MappingException("Mapping not found for " + entry.Key.ToString());
                }

不确定它是否是完整的答案,但总比没有好:)

任何想法?

Hey Alec, thanks for the reply. I've hacked a bit of a solution - it aint pretty but it does smoke test dodgy mappings across multiple db's

In the set up I add the following:

private List<string> sessionKeys;
        [SetUp]
        public virtual void SetUp()
        {
            string[] mappingAssemblies = RepositoryTestsHelper.GetMappingAssemblies();
            configuration = NHibernateSession.Init(new SimpleSessionStorage(), mappingAssemblies,
                                   new AutoPersistenceModelGenerator().Generate(),
                                   "../../../../app/Humanities.IBusiness.Web/NHibernate.config");

            /*NEW CODE */
            var configuration2 = NHibernateSession.AddConfiguration(DataGlobals.ROLES_DB_FACTORY_KEY,
                mappingAssemblies,
                new AutoPersistenceModelGenerator().Generate(),
                "../../../../app/Humanities.IBusiness.Web/NHibernateForRolesDb.config",null,null, null);
            sessionKeys = new List<string>();
            sessionKeys.Add(DataGlobals.DEFAULT_DB_KEY);
            sessionKeys.Add(DataGlobals.ROLES_DB_FACTORY_KEY);

Then in the CanConfirmDatabaseMatchesMappings

foreach (var entry in allClassMetadata)
                {
                    bool found = false;
                    foreach (string key in sessionKeys)
                    {
                        ISession session = NHibernateSession.CurrentFor(key);
                        try
                        {
                            session.CreateCriteria(entry.Value.GetMappedClass(EntityMode.Poco))
                                .SetMaxResults(0).List();
                            found = true;
                        }
                        catch (Exception ex) { }

                    }
                    if (found == false)
                        throw new MappingException("Mapping not found for " + entry.Key.ToString());
                }

Not sure if it's a full answer but better than nothing :)

Any thoughts?

睡美人的小仙女 2024-09-19 07:34:12

艾尔,
老实说,我不知道用户使用多个数据库的程度。我相信这是一些非常直言不讳的人在项目生命周期开始时游说的事情。这是我要向社区询问的问题,看来是时候提出这个问题了。

您可能需要做的是将设置代码移至单独的方法中。虽然我并不热衷于破坏 DRY 原则,但在这种情况下似乎这是必需的。

亚历克

Al,
to be honest I do not know the extent that the users are using Multiple Databases. This is something I believe a few very vocal people lobbied for in the beginning of the projects lifecycle. This is something I was going to ask the community about, looks like the time has come for the question to be asked.

What you might need to do is move the set-up code into individual methods. While I am not crazy with breaking the DRY principal, it would seem in this case it is required.

Alec

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文