Question

After reading the following article Create Test Conditions for the Database Unit Test Designer on MSDN i decided to try create a custom test condition for my database unit tests

  • Ive met the requirements of either Ultimate or Premium as my environment.
  • Created a new class lib project and referenced Microsoft.Data.Schema.UnitTesting and Microsoft.Data.Schema as well as Microsoft.Data.Schema.Sql
  • I created a class inheriting from TestCondition and called it ExpectedSqlException defined as the following

EDIT:

     [DisplayName("Some test condition")] 
     [DatabaseSchemaProviderCompatibility(null)] 
     public class SomeTestCondition : TestCondition
     {
         public override void Assert(System.Data.Common.DbConnection validationConnection, Microsoft.Data.Schema.UnitTesting.ExecutionResult[] results)
         {
         ...
         }
    } 
  • Following the how to I then created the extentions.xml file that i then placed in %ProgramFiles%\Microsoft Visual Studio 10.0\VSTSDB\Extensions and it looks like so (the type key/value is my assembly public info, this should be different for yours)

    <?xml version="1.0" encoding="utf-8"?>    
    <extensions assembly="" version="1" xmlns="urn:Microsoft.Data.Schema.Extensions" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:Microsoft.Data.Schema.Extensions Microsoft.Data.Schema.Extensions.xsd">    
        <extension type="SomeTestCondition.SomeTestCondition" assembly="SomeTestCondition, Version=1.0.0.0, Culture=neutral, PublicKeyToken=01a289ad96d7a8a8" enabled="true" />    
    </extensions>
    
  • And registered the assembly into the GAC after signing the assembly

So now with my new TestCondition i should be able to use it within the database unit testing designer to define expectations, BUT ALAS IT DOES NOT WORK :(

Can someone help me with this? what am i missing?

Was it helpful?

Solution

I can see one thing I did differently when I did this that isn't clearly stated in the how to link you referenced.

It bangs on about putting stuff into "Program Files" but maybe this only works for 32bit machines. Visual Studio is a 32bit app and on the 64bit machine (which I was using) I ignored the instructions and copied the assembly and xml file to %ProgramFiles(x86)% NOT %ProgramFiles% - which seemed to work for me. I never tried %ProgramFiles% at all though - so I can't verify this is an issue.

Is that it?

Addendum:

Looking further at your code, you'll have to add the [DatabaseSchemaProviderCompatibility(null)] attribute on your TestCondition. This will load up the extension when you don't have a database schema provider loaded in the current project, which would be the case for Test Projects. That attribute is not very intuitive methinks.

James.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top