Unit testing with Effort and SQL CE in parallel fails

后端 未结 2 2006
孤城傲影
孤城傲影 2021-02-14 08:24

I\'m evaluating unit tests using EF6 in combination with

  • http://effort.codeplex.com/ and
  • SQL CE Server (Local DB file)

http://www.codeproje

相关标签:
2条回答
  • 2021-02-14 08:49

    We were seeing the same errors when running all UnitTests on our build server or when running all UnitTests locally.

    System.InvalidOperationException : The Entity Framework was already using a DbConfiguration instance before an attempt was made to add an 'Loaded' event handler. 'Loaded' event handlers can only be added as part of application start up before the Entity Framework is used.

    Once we moved the Effort Provider registration code from the [TestInitialize] method to the AssemblyInitialize method, everything started working. Based on the message in the reported error, it appears that the registration cannot happen more than once.

        [AssemblyInitialize()]
        public static void AssemblyInit(TestContext context)
        {
            Effort.Provider.EffortProviderConfiguration.RegisterProvider();
        }
    
    0 讨论(0)
  • 2021-02-14 08:49

    I came across this just now and thought I'd share the cause of my issue.

    Everything was working dandy, until I implemented and ActionFilter. It turned out that in my test the Effort code was running after the instantiation of my web site. Instantiating the web site instantiated my filter, my filter requested a DataContext from the container.

    Hence someone had already made use of the datacontext before I tried to configure it with Effort.

    Hope this might help someone in the future, albeit it being a bit of a different cause, and I hope you solved your issue int the end!

    0 讨论(0)
提交回复
热议问题