MSTest and NHibernate

时光毁灭记忆、已成空白 提交于 2019-12-07 01:33:56

问题


Does anyone have any experience getting MSTest to copy hibernate.cfg.xml properly to the output directory? All my MSTests fail with a cannot find hibernate.cfg.xml error (I have it set to Copy Always), but my MBUnit tests pass.


回答1:


You can try adding the DeploymentItemAttribute to one of your tests, or edit your .testrunconfig file and add the file to the Deployment list.




回答2:


Edit localtestrun.testrunconfig (in your solution items folder). Select the deployment option and add the hibernate.cfg.xml file to the list of additional files to deploy. The file should then get copied to the output directory where the test gets run.




回答3:


Ran into the same thing a few weeks ago -- this is actually a bug with MSTest -- I believe this was corrected with the recent Service Pack Release (even though it still says "Active"). If not, all I had to do was reference my hibernate.cfg.xml directly (sloppy but works for testing -- this is referencing the hibernate.cfg.xml file in my tests project from the "TestResults" folder):

 try
           {
                sessionFactory = new Configuration()
                    .Configure()
                    .BuildSessionFactory();
            }
            // Assume we are in "MSTest mode"
            catch (Exception)
            {
                sessionFactory = new Configuration()
                    .Configure(@"..\..\..\Program.Tests\" + @"\hibernate.cfg.xml")
                    .BuildSessionFactory();
            }



回答4:


a workaround rather than an answer: NHibernate supports programmatic configuration. so you can write your own native properties/config file and parse it into hibernate configurations on startup.




回答5:


I like to mark my NHibernate config files as Embedded Resources, and use the Configuration.Configure() overload which reads config files from the Assembly Resources.



来源:https://stackoverflow.com/questions/20173/mstest-and-nhibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!